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