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