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