]> Dogcows Code - chaz/carfire/blob - CarFire/CarFire/CarFire/Player.cs
Cleaned up a bit
[chaz/carfire] / CarFire / CarFire / CarFire / Player.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Content;
7 using Microsoft.Xna.Framework.Graphics;
8 using Microsoft.Xna.Framework.Input;
9
10
11 namespace CarFire
12 {
13 public abstract class Player : ICharacter
14 {
15 #region Member variables
16 //The number of frames between each projectile is spawned.
17 const int shootCoolDown = 18;
18 String CharName;
19 Game game;
20 int playerHealth;
21 int playerDamage;
22 int score;
23 MovementManager mMotion;
24 int mPlayerIndex;
25 #endregion
26
27 #region Public Properties
28 public int Health { get { return playerHealth; } set{playerHealth = value;} }
29 public int Score { get { return score; } }
30 public bool alive { get { return playerHealth > 0; } }
31 public Game Game { get { return game; } }
32 public MovementManager Motion { get { return mMotion; } }
33 public int PlayerIndex { get { return mPlayerIndex; } }
34 public Vector2 Position { get { return mMotion.Position; } }
35 public Point Coordinates { get { return mMotion.Coordinates; } }
36 public int Damage { get { return playerDamage; } set { playerDamage = value; } }
37 #endregion
38
39 #region Public Methods
40 public Player(Game theGame, String Name, Point position, int playerIndex, int health, int damage)
41 {
42 game = theGame;
43 CharName = Name;
44 score = 0;
45 playerHealth = health;
46 playerDamage = damage;
47 mPlayerIndex = playerIndex;
48
49 // Speed is the number of grid cells you can move through per second.
50 mMotion = new MovementManager(position, 4.0f);
51 }
52 public void causeDamageTo(int amount)
53 {
54 playerHealth -= amount;
55 }
56
57 public void Update(TimeSpan timeSpan)
58 {
59
60 }
61 /// <summary>
62 /// Moves the current player being controlled based on a given set of key presses.
63 /// The player can only move one grid space per movePlayer call. Thus this method
64 /// is made to be called ever update. The player will only move if the grid space
65 /// that is being moved to is an open space.
66 /// </summary>
67 /// <param name="keysPressed">A general list of keys that are pressed. Other keys can be included but only direction keys will be used</param>
68 public void UpdateInput(TimeSpan timeSpan, List<Keys> keysPressed)
69 {
70
71 UpdatePosition(timeSpan, keysPressed);
72 Attack(keysPressed);
73
74 }
75 public void UpdatePosition(TimeSpan timeSpan, List<Keys> keysPressed)
76 {
77 bool moveLeft = keysPressed.Contains(Keys.Left);
78 bool moveRight = keysPressed.Contains(Keys.Right);
79 bool moveUp = keysPressed.Contains(Keys.Up);
80 bool moveDown = keysPressed.Contains(Keys.Down);
81 Point destination = MovementManager.GetNeighborCell(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown);
82 if (!keysPressed.Contains(Keys.LeftControl))
83 {
84 if (game.IsCellOpen(destination))
85 {
86 mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown);
87 }
88 else
89 {
90 mMotion.Update(timeSpan);
91 }
92 }
93 else
94 {
95 mMotion.LockUpdate(timeSpan, moveLeft, moveRight, moveUp, moveDown);
96 }
97 }
98
99 public void powerUp(int amount)
100 {
101 playerHealth += amount;
102 }
103
104 public void Spawn(Vector2 spawn)
105 {
106
107 }
108 public void AddHealth(int healthBoost)
109 {
110 Health += healthBoost;
111 }
112 public void IncreaseDamage(int damageBoost)
113 {
114 Damage += damageBoost;
115 }
116 #endregion
117
118 #region Abstract Methods
119 public abstract void PlayAttackSound();
120 public abstract void PlayDieSound();
121 public abstract void LoadContent(ContentManager contentManager);
122 /// <summary>
123 /// This method will draw a character to the screen.
124 /// </summary>
125 /// <param name="spriteBatch"></param>
126 public abstract void Draw(SpriteBatch spriteBatch);
127 public abstract void Attack(List<Keys> keysPressed);
128 #endregion
129
130
131 }
132
133 }
This page took 0.039055 seconds and 5 git commands to generate.