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