]> Dogcows Code - chaz/carfire/blob - CarFire/CarFire/CharacterTestBed/Character.cs
getting entity lists not more consistent with throwing exceptions
[chaz/carfire] / CarFire / CarFire / CharacterTestBed / Character.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 /// <summary>
13 /// Base class for all Characters,
14 /// includes: basic position information,
15 /// character Texture
16 /// health
17 /// damage
18 /// </summary>
19 public class Character
20 {
21 //Member Variables
22 Map theMap;
23 int movementSpeed;
24 int gridX;
25 int gridY;
26 Texture2D charModel;
27 int health;
28 int damage;
29 int range;
30 bool isMoving;
31 int pixelX;
32 int pixelY;
33
34 /// <summary>
35 /// Call this method to give the game a chance to load its content.
36 /// </summary>
37 /// <param name="_currentMap">The map that this character will interact with</param>
38 /// <param name="_charModel">The model for this character</param>
39 /// <param name="_baseMovementSpeed">How fast the character moves</param>
40 /// <param name="_baseHealth">The starting health of the character</param>
41 /// <param name="_baseDamage">The base damage of the character</param>
42 /// <param name="_baseRange">The range of the character attack</param>
43 public Character( Map _currentMap,
44 Texture2D _charModel,
45 int _baseMovementSpeed,
46 int _baseHealth,
47 int _baseDamage,
48 int _baseRange)
49 {
50 theMap = _currentMap;
51 movementSpeed = _baseMovementSpeed;
52 gridX = 10; //should be included in the map as a designated spawn point to begin map
53 gridY = 10; //
54 charModel = _charModel;
55 health = _baseHealth;
56 damage = _baseDamage;
57 range = _baseRange;
58 isMoving = false;
59 }
60
61 public void Draw(SpriteBatch spriteBatch)
62 {
63 spriteBatch.Draw(charModel, new Vector2(pixelX, pixelY), null, Color.White, 0, new Vector2(0f,0f), 1f, SpriteEffects.None, 0);
64 }
65
66 /// <summary>
67 /// Basic getters and setters
68 /// </summary>
69 public int GridX { get { return gridX; } set { gridX = value; } }
70 public int GridY { get { return gridY; } set { gridY = value; } }
71 public int PixelX { get { return pixelX; } set { pixelX = value; } }
72 public int PixelY { get { return pixelY; } set { pixelY = value; } }
73 public int Health { get { return health; } set { health = value; } }
74 public Map TheMap { get { return theMap; } }
75
76 /// <summary>
77 /// Get if player is Moveing - Getter only
78 /// </summary>
79 public bool IsMoving
80 {
81 get { return isMoving; }
82 }
83 }
84
85 /// <summary>
86 ///
87 /// </summary>
88 public class Player : Character
89 {
90 //Member Variables
91
92 public Player( Map _currentMap,
93 Texture2D _charModel,
94 int _baseMovementSpeed,
95 int _baseHealth,
96 int _baseDamage,
97 int _baseRange)
98 : base(_currentMap,_charModel,_baseMovementSpeed, _baseHealth, _baseDamage, _baseRange)
99 {
100 }
101
102 public void Update()
103 {
104
105
106 }
107
108 /// <summary>
109 /// Updates the players position in the current window, the player is kept centered
110 /// in the window when possible. When the edge of the map is reached by one or more
111 /// of the edges of the window the player will then move towards the edges of the
112 /// window.
113 /// </summary>
114 /// <param name="ScreenWidth">Used to know how wide the current window is</param>
115 /// <param name="ScreenHeight">Used to know how tall the current window is</param>
116 public void updatePlayerScreenPosition(int ScreenWidth, int ScreenHeight)
117 {
118 // if left edge of map has been reached by screen
119 if (GridX * TheMap.GridToPixelRatio < ScreenWidth / 2)
120 {
121 PixelX = GridX * TheMap.GridToPixelRatio;
122 }
123 // if right edge of TheMap has been reached by screen
124 else if ((TheMap.MaxGridX - GridX) * TheMap.GridToPixelRatio < ScreenWidth / 2)
125 {
126 PixelX = ScreenWidth - (TheMap.MaxGridX - GridX) * TheMap.GridToPixelRatio;
127 }
128 // screen not touching left or right edge of map so center player horazontally on screen
129 else
130 {
131 PixelX = ScreenWidth / 2;
132 }
133
134 // if top edge of map is reached by screen edge
135 if (GridY * TheMap.GridToPixelRatio < ScreenHeight / 2)
136 {
137 PixelY = GridY * TheMap.GridToPixelRatio;
138 }
139 // if bottom edge of map has been reached by screen
140 else if ((TheMap.MaxGridY - GridY) * TheMap.GridToPixelRatio < ScreenHeight / 2)
141 {
142 PixelY = ScreenHeight - (TheMap.MaxGridY - GridY) * TheMap.GridToPixelRatio;
143 }
144 // screen not touching top or bottom edge of map so center player verticaly on screen
145 else
146 {
147 PixelY = ScreenHeight / 2;
148 }
149 }
150
151 /// <summary>
152 /// Moves the current player being controlled based on a given set of key presses.
153 /// The player can only move one Grid space per movePlayer call. Thus this method
154 /// is made to be called ever update. The player will only move if the Grid space
155 /// that is being moved to is an open space.
156 /// </summary>
157 /// <param name="keysPressed">A general list of keys that are pressed. Other keys can be included but only direction keys will be used</param>
158 public void movePlayer(List<Keys> keysPressed)
159 {
160 // move upleft
161 keysPressed.Contains<Keys>(Keys.Left);
162 if (keysPressed.Contains<Keys>(Keys.Up) && keysPressed.Contains<Keys>(Keys.Left) && TheMap.isOpenSquare(GridX - 1, GridY - 1))
163 {
164 GridX -= 1;
165 GridY -= 1;
166 }
167 // move upright
168 else if (keysPressed.Contains<Keys>(Keys.Up) && keysPressed.Contains<Keys>(Keys.Right) && TheMap.isOpenSquare(GridX + 1, GridY - 1))
169 {
170 GridX += 1;
171 GridY -= 1;
172 }
173 // move downleft
174 else if (keysPressed.Contains<Keys>(Keys.Down) && keysPressed.Contains<Keys>(Keys.Left) && TheMap.isOpenSquare(GridX - 1, GridY + 1))
175 {
176 GridX -= 1;
177 GridY += 1;
178 }
179 // move downright
180 else if (keysPressed.Contains<Keys>(Keys.Down) && keysPressed.Contains<Keys>(Keys.Right) && TheMap.isOpenSquare(GridX + 1, GridY + 1))
181 {
182 GridX += 1;
183 GridY += 1;
184 }
185 // move up
186 else if (keysPressed.Contains<Keys>(Keys.Up) && TheMap.isOpenSquare(GridX, GridY - 1))
187 {
188 GridY -= 1;
189 }
190 // move down
191 else if (keysPressed.Contains<Keys>(Keys.Down) && TheMap.isOpenSquare(GridX, GridY + 1))
192 {
193 GridY += 1;
194 }
195 // move left
196 else if (keysPressed.Contains<Keys>(Keys.Left) && TheMap.isOpenSquare(GridX - 1, GridY))
197 {
198 GridX -= 1;
199 }
200 // move right
201 else if (keysPressed.Contains<Keys>(Keys.Right) && TheMap.isOpenSquare(GridX + 1, GridY))
202 {
203 GridX += 1;
204 }
205 }
206 }
207
208 /// <summary>
209 ///
210 /// </summary>
211 public class Monster : Character
212 {
213 //Member Variables
214 public Monster( Map _currentMap,
215 Texture2D _charModel,
216 int _baseMovementSpeed,
217 int _baseHealth,
218 int _baseDamage,
219 int _baseRange)
220 : base(_currentMap,_charModel,_baseMovementSpeed, _baseHealth, _baseDamage, _baseRange)
221 {
222
223 }
224
225 public void Update()
226 {
227
228 }
229 }
230 /*
231 //this is for testing purposes only!
232 public class Map
233 {
234 int gridToPixelRatio;
235
236 public Map()
237 {
238 gridToPixelRatio = 10;
239 }
240
241 public int MaxGridX
242 {
243 get { return 100; }
244 }
245 public int MaxGridY
246 {
247 get { return 100; }
248 }
249
250 public int GridToPixelRatio
251 {
252 get { return gridToPixelRatio; }
253 }
254
255 public bool isOpenSquare(int GridX, int GridY)
256 {
257 return true;
258 }
259
260
261 }
262 */
263 }
This page took 0.041545 seconds and 4 git commands to generate.