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