]> Dogcows Code - chaz/carfire/blob - CarFire/CarFire/CarFire/Human.cs
9350d8605e099e92c6c4afecf1e4e7cd27292468
[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 const int moveCoolDown = 12;
22 const int shootCoolDown = 10;
23 //Member Variables
24 State state;
25 String CharName;
26 Map theMap;
27 int movementSpeed;
28 int gridX;
29 int gridY;
30 Texture2D charModel;
31 Texture2D projectileModel;
32 int health;
33 int damage;
34 int range;
35 int score;
36 bool isMoving;
37 int pixelX;
38 int pixelY;
39 bool visible;
40 int movementCoolDown;
41 Display theDisplay;
42 int projectileSpeed;
43 int projectileCoolDown;
44
45 public Human(Map _theMap, String Name, Texture2D model, Texture2D projectile, Display mDisplay)
46 {
47 theMap = _theMap;
48 CharName = Name;
49 theDisplay = mDisplay;
50
51 movementSpeed = 12; // randomly set now
52 health = 100;
53 score = 0;
54 visible = false;
55 //default state
56 state = State.up;
57 charModel = model;
58 projectileModel = projectile;
59 projectileSpeed = 30;
60
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
81 public long Draw(SpriteBatch spriteBatch)
82 {
83 spriteBatch.Draw(charModel, theMap.GetRectangleFromCoordinates(gridX, gridY), Color.White);
84 return 0;
85 }
86
87 public int GridX { get { return gridX; } set { gridX = value; } }
88 public int GridY { get { return gridY; } set { gridY = value; } }
89 public int Health { get { return health; } }
90 public int Score { get { return score; } }
91 public bool alive { get { return health > 0; } }
92
93 public void causeDamageTo(int amount)
94 {
95 health -= amount;
96 }
97
98 /// <summary>
99 /// Moves the current player being controlled based on a given set of key presses.
100 /// The player can only move one grid space per movePlayer call. Thus this method
101 /// is made to be called ever update. The player will only move if the grid space
102 /// that is being moved to is an open space.
103 /// </summary>
104 /// <param name="keysPressed">A general list of keys that are pressed. Other keys can be included but only direction keys will be used</param>
105 public void MovePlayer(List<Keys> keysPressed)
106 {
107 if(movementCoolDown > 0)
108 movementCoolDown--;
109 else if (movementCoolDown == 0)
110 {
111 // move upleft
112 keysPressed.Contains<Keys>(Keys.Left);
113 if (keysPressed.Contains<Keys>(Keys.Up) && keysPressed.Contains<Keys>(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY - 1))
114 {
115 gridX -= 1;
116 gridY -= 1;
117 movementCoolDown = moveCoolDown;
118 }
119 // move upright
120 else if (keysPressed.Contains<Keys>(Keys.Up) && keysPressed.Contains<Keys>(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY - 1))
121 {
122 gridX += 1;
123 gridY -= 1;
124 movementCoolDown = moveCoolDown;
125 }
126 // move downleft
127 else if (keysPressed.Contains<Keys>(Keys.Down) && keysPressed.Contains<Keys>(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY + 1))
128 {
129 gridX -= 1;
130 gridY += 1;
131 movementCoolDown = moveCoolDown;
132 }
133 // move downright
134 else if (keysPressed.Contains<Keys>(Keys.Down) && keysPressed.Contains<Keys>(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY + 1))
135 {
136 gridX += 1;
137 gridY += 1;
138 movementCoolDown = moveCoolDown;
139 }
140 // move up
141 else if (keysPressed.Contains<Keys>(Keys.Up) && theMap.IsCellOpen(gridX, gridY - 1))
142 {
143 state = State.up;
144 gridY -= 1;
145 movementCoolDown = moveCoolDown;
146 }
147 // move down
148 else if (keysPressed.Contains<Keys>(Keys.Down) && theMap.IsCellOpen(gridX, gridY + 1))
149 {
150 state = State.down;
151 gridY += 1;
152 movementCoolDown = moveCoolDown;
153 }
154 // move left
155 else if (keysPressed.Contains<Keys>(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY))
156 {
157 state = State.left;
158 gridX -= 1;
159 movementCoolDown = moveCoolDown;
160 }
161 // move right
162 else if (keysPressed.Contains<Keys>(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY))
163 {
164 state = State.right;
165 gridX += 1;
166 movementCoolDown = moveCoolDown;
167 }
168 }
169 if (projectileCoolDown > 0)
170 projectileCoolDown--;
171 else if (projectileCoolDown == 0)
172 {
173 if (keysPressed.Contains<Keys>(Keys.Space))
174 {
175 //TODO spawn projectile... needs to be added to display though
176 if (state == State.up)
177 {
178 projectileCoolDown = shootCoolDown;
179 theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(0, -projectileSpeed), GridX, GridY - 1));
180 }
181 if (state == State.down)
182 {
183 projectileCoolDown = shootCoolDown;
184 theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(0, projectileSpeed), GridX, GridY + 1));
185 }
186 if (state == State.right)
187 {
188 projectileCoolDown = shootCoolDown;
189 theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(projectileSpeed, 0), GridX + 1, GridY));
190 }
191 if (state == State.left)
192 {
193 projectileCoolDown = shootCoolDown;
194 theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(-projectileSpeed, 0), GridX - 1, GridY));
195 }
196 }
197 }
198 }
199
200
201 public void powerUp(int amount)
202 {
203 health += amount;
204 }
205
206 public void Spawn(Vector2 spawn)
207 {
208 gridX = (int)spawn.X;
209 gridY = (int)spawn.Y;
210 visible = true;
211 }
212
213
214 }
215 }
This page took 0.049252 seconds and 4 git commands to generate.