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