]> Dogcows Code - chaz/carfire/blob - CarFire/CarFire/CarFire/Human.cs
git-svn-id: https://bd85.net/svn/cs3505_group@114 92bb83a3-7c8f-8a45-bc97-515c4e399668
[chaz/carfire] / CarFire / CarFire / CarFire / Human.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 namespace CarFire
11 {
12 public class Human : IPlayer
13 {
14 public enum State
15 {
16 left,
17 right,
18 up,
19 down
20 };
21 //The number of frames between each square movements
22 const int moveCoolDown = 15;
23 //The number of frames between each projectile is spawned.
24 const int shootCoolDown = 10;
25 State state;
26 String CharName;
27 Map theMap;
28 Texture2D charModel;
29 Texture2D projectileModel;
30 int health;
31 int damage;
32 int range;
33 int score;
34
35 MovementManager mMotion;
36
37 bool visible;
38 Display theDisplay;
39
40 //Used to draw projectiles
41 int projectileSpeed;
42 int projectileCoolDown;
43
44
45 public Human(Map _theMap, String Name, Texture2D model, Texture2D projectile, Display mDisplay, Point position)
46 {
47 theMap = _theMap;
48 CharName = Name;
49 theDisplay = mDisplay;
50 health = 100;
51 score = 0;
52 visible = false;
53 //default state
54 state = State.up;
55 charModel = model;
56 projectileModel = projectile;
57 projectileSpeed = 30;
58
59 // Speed is the number of grid cells you can move through per second.
60 mMotion = new MovementManager(position, 5.0f);
61 }
62
63 public void LoadContent(ContentManager contentManager)
64 {
65 charModel = contentManager.Load<Texture2D>("deselectBox"); //change to charModel when designed
66 projectileModel = contentManager.Load<Texture2D>("emptySelectBox"); //change to a projectile model later
67
68 }
69
70 public void UnloadContent()
71 {
72
73 }
74
75 public long Update(GameTime gameTime, NetworkManager networkGame)
76 {
77 return 0;
78
79 }
80 /// <summary>
81 /// This method will draw a character to the screen.
82 /// </summary>
83 /// <param name="spriteBatch"></param>
84 /// <returns></returns>
85 public long Draw(SpriteBatch spriteBatch)
86 {
87 Rectangle position = theMap.GetRectangleFromCoordinates(mMotion.Position);
88 spriteBatch.Draw(charModel, position, Color.White);
89 return 0;
90 }
91
92 public int Health { get { return health; } }
93 public int Score { get { return score; } }
94 public bool alive { get { return health > 0; } }
95
96 public Vector2 Position { get { return mMotion.Position; } }
97 public Point Coordinates { get { return mMotion.Coordinates; } }
98
99 public void causeDamageTo(int amount)
100 {
101 health -= amount;
102 }
103
104 /// <summary>
105 /// Moves the current player being controlled based on a given set of key presses.
106 /// The player can only move one grid space per movePlayer call. Thus this method
107 /// is made to be called ever update. The player will only move if the grid space
108 /// that is being moved to is an open space.
109 /// </summary>
110 /// <param name="keysPressed">A general list of keys that are pressed. Other keys can be included but only direction keys will be used</param>
111 public void MovePlayer(TimeSpan timeSpan, List<Keys> keysPressed)
112 {
113 bool moveLeft = keysPressed.Contains(Keys.Left);
114 bool moveRight = keysPressed.Contains(Keys.Right);
115 bool moveUp = keysPressed.Contains(Keys.Up);
116 bool moveDown = keysPressed.Contains(Keys.Down);
117 if (moveLeft)
118 state = State.left;
119 else if (moveRight)
120 state = State.right;
121 else if (moveUp)
122 state = State.up;
123 else if (moveDown)
124 state = State.down;
125
126 Point destination = MovementManager.GetNeighborCell(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown);
127 if (theMap.IsCellOpen(destination))
128 {
129 mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown);
130 }
131 else
132 {
133 mMotion.Update(timeSpan);
134 }
135
136
137 if (projectileCoolDown > 0)
138 projectileCoolDown--;
139 else if (projectileCoolDown == 0)
140 {
141 if (keysPressed.Contains<Keys>(Keys.Space))
142 {
143 //TODO spawn projectile... needs to be added to display though
144 if (state == State.up)
145 {
146 projectileCoolDown = shootCoolDown;
147 theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,
148 new Vector2(0, -projectileSpeed), Coordinates.X, Coordinates.Y - 1));
149 }
150 if (state == State.down)
151 {
152 projectileCoolDown = shootCoolDown;
153 theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,
154 new Vector2(0, projectileSpeed), Coordinates.X, Coordinates.Y + 1));
155 }
156 if (state == State.right)
157 {
158 projectileCoolDown = shootCoolDown;
159 theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,
160 new Vector2(projectileSpeed, 0), Coordinates.X + 1, Coordinates.Y));
161 }
162 if (state == State.left)
163 {
164 projectileCoolDown = shootCoolDown;
165 theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,
166 new Vector2(-projectileSpeed, 0), Coordinates.X - 1, Coordinates.Y));
167 }
168 }
169 }
170 }
171
172
173 public void powerUp(int amount)
174 {
175 health += amount;
176 }
177
178 public void Spawn(Vector2 spawn)
179 {
180 //gridX = (int)spawn.X;
181 //gridY = (int)spawn.Y;
182 visible = true;
183 }
184
185
186 }
187 }
This page took 0.044362 seconds and 5 git commands to generate.