b5312550630b1e64a5c4927ee618e174ca26e34e
[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 = 8.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 mMotion.Coordinates = value;
42 mMotion = new MovementManager(value, basePlayerSpeed);
43 } }
44 public char Identifier { get { return mPlayerIndex.ToString()[0]; } }
45 public int Damage { get { return playerDamage; } set { playerDamage = value; } }
46 public List<IEntity> Inventory { get { return mInventory; } }
47 #endregion
48
49 #region Public Methods
50 public Player(Game theGame, String Name, Point position, int playerIndex, int health, int damage)
51 {
52 game = theGame;
53 CharName = Name;
54 score = 0;
55 playerHealth = health;
56 playerDamage = damage;
57 mPlayerIndex = playerIndex;
58
59 // Speed is the number of grid cells you can move through per second.
60 mMotion = new MovementManager(position, basePlayerSpeed);
61 }
62 public void causeDamageTo(int amount)
63 {
64 playerHealth -= amount;
65 }
66
67 public void Update(TimeSpan timeSpan)
68 {
69
70 }
71 /// <summary>
72 /// Moves the current player being controlled based on a given set of key presses.
73 /// The player can only move one grid space per movePlayer call. Thus this method
74 /// is made to be called ever update. The player will only move if the grid space
75 /// that is being moved to is an open space.
76 /// </summary>
77 /// <param name="keysPressed">A general list of keys that are pressed. Other keys can be included but only direction keys will be used</param>
78 public void UpdateInput(TimeSpan timeSpan, List<Keys> keysPressed)
79 {
80
81 UpdatePosition(timeSpan, keysPressed);
82 Attack(keysPressed);
83
84 }
85 public void UpdatePosition(TimeSpan timeSpan, List<Keys> keysPressed)
86 {
87 bool moveLeft = keysPressed.Contains(Keys.Left);
88 bool moveRight = keysPressed.Contains(Keys.Right);
89 bool moveUp = keysPressed.Contains(Keys.Up);
90 bool moveDown = keysPressed.Contains(Keys.Down);
91
92 List<Point> possibleDestinations = new List<Point>(3);
93 possibleDestinations.Add(MovementManager.GetNeighbor(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown));
94 possibleDestinations.AddRange(MovementManager.GetNeighbors(mMotion.Coordinates, possibleDestinations[0]));
95
96 Direction direction = Direction.None;
97 foreach (Point destination in possibleDestinations)
98 {
99 if (game.IsCellOpen(destination))
100 {
101 direction = MovementManager.GetDirection(mMotion.Coordinates, destination);
102 break;
103 }
104 }
105
106 if (direction != Direction.None && !keysPressed.Contains(Keys.LeftControl))
107 mMotion.Update(timeSpan, direction);
108 else mMotion.LockUpdate(timeSpan, moveLeft, moveRight, moveUp, moveDown);
109 }
110
111 public void powerUp(int amount)
112 {
113 playerHealth += amount;
114 }
115
116 public void Spawn(Vector2 spawn)
117 {
118
119 }
120 public void AddHealth(int healthBoost)
121 {
122 Health += healthBoost;
123 }
124 public void IncreaseDamage(int damageBoost)
125 {
126 Damage += damageBoost;
127 }
128 #endregion
129
130 #region Abstract Methods
131 public abstract void PlayAttackSound();
132 public abstract void PlayDieSound();
133 public abstract void LoadContent(ContentManager contentManager);
134 /// <summary>
135 /// This method will draw a character to the screen.
136 /// </summary>
137 /// <param name="spriteBatch"></param>
138 public abstract void Draw(SpriteBatch spriteBatch);
139 public abstract void Attack(List<Keys> keysPressed);
140 #endregion
141
142
143 }
144
145 }
This page took 0.046109 seconds and 3 git commands to generate.