]> Dogcows Code - chaz/carfire/blob - CarFire/CarFire/CarFire/Character.cs
git-svn-id: https://bd85.net/svn/cs3505_group@163 92bb83a3-7c8f-8a45-bc97-515c4e399668
[chaz/carfire] / CarFire / CarFire / CarFire / 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
119 // if left edge of map has been reached by screen
120 if (GridX * TheMap.GridToPixelRatio < ScreenWidth / 2)
121 {
122 PixelX = GridX * TheMap.GridToPixelRatio;
123 }
124 // if right edge of TheMap has been reached by screen
125 else if ((TheMap.MaxGridX - GridX) * TheMap.GridToPixelRatio < ScreenWidth / 2)
126 {
127 PixelX = ScreenWidth - (TheMap.MaxGridX - GridX) * TheMap.GridToPixelRatio;
128 }
129 // screen not touching left or right edge of map so center player horazontally on screen
130 else
131 {
132 PixelX = ScreenWidth / 2;
133 }
134
135 // if top edge of map is reached by screen edge
136 if (GridY * TheMap.GridToPixelRatio < ScreenHeight / 2)
137 {
138 PixelY = GridY * TheMap.GridToPixelRatio;
139 }
140 // if bottom edge of map has been reached by screen
141 else if ((TheMap.MaxGridY - GridY) * TheMap.GridToPixelRatio < ScreenHeight / 2)
142 {
143 PixelY = ScreenHeight - (TheMap.MaxGridY - GridY) * TheMap.GridToPixelRatio;
144 }
145 // screen not touching top or bottom edge of map so center player verticaly on screen
146 else
147 {
148 PixelY = ScreenHeight / 2;
149 }
150 }
151 */
152 /// <summary>
153 /// Moves the current player being controlled based on a given set of key presses.
154 /// The player can only move one Grid space per movePlayer call. Thus this method
155 /// is made to be called ever update. The player will only move if the Grid space
156 /// that is being moved to is an open space.
157 /// </summary>
158 /// <param name="keysPressed">A general list of keys that are pressed. Other keys can be included but only direction keys will be used</param>
159 public void movePlayer(List<Keys> keysPressed)
160 {
161 // move upleft
162 keysPressed.Contains<Keys>(Keys.Left);
163 if (keysPressed.Contains<Keys>(Keys.Up) && keysPressed.Contains<Keys>(Keys.Left) && TheMap.IsCellOpen(GridX - 1, GridY - 1))
164 {
165 GridX -= 1;
166 GridY -= 1;
167 }
168 // move upright
169 else if (keysPressed.Contains<Keys>(Keys.Up) && keysPressed.Contains<Keys>(Keys.Right) && TheMap.IsCellOpen(GridX + 1, GridY - 1))
170 {
171 GridX += 1;
172 GridY -= 1;
173 }
174 // move downleft
175 else if (keysPressed.Contains<Keys>(Keys.Down) && keysPressed.Contains<Keys>(Keys.Left) && TheMap.IsCellOpen(GridX - 1, GridY + 1))
176 {
177 GridX -= 1;
178 GridY += 1;
179 }
180 // move downright
181 else if (keysPressed.Contains<Keys>(Keys.Down) && keysPressed.Contains<Keys>(Keys.Right) && TheMap.IsCellOpen(GridX + 1, GridY + 1))
182 {
183 GridX += 1;
184 GridY += 1;
185 }
186 // move up
187 else if (keysPressed.Contains<Keys>(Keys.Up) && TheMap.IsCellOpen(GridX, GridY - 1))
188 {
189 GridY -= 1;
190 }
191 // move down
192 else if (keysPressed.Contains<Keys>(Keys.Down) && TheMap.IsCellOpen(GridX, GridY + 1))
193 {
194 GridY += 1;
195 }
196 // move left
197 else if (keysPressed.Contains<Keys>(Keys.Left) && TheMap.IsCellOpen(GridX - 1, GridY))
198 {
199 GridX -= 1;
200 }
201 // move right
202 else if (keysPressed.Contains<Keys>(Keys.Right) && TheMap.IsCellOpen(GridX + 1, GridY))
203 {
204 GridX += 1;
205 }
206 }
207 }
208
209 /// <summary>
210 ///
211 /// </summary>
212 public class Monster : Character
213 {
214 //Member Variables
215 public Monster( Map _currentMap,
216 Texture2D _charModel,
217 int _baseMovementSpeed,
218 int _baseHealth,
219 int _baseDamage,
220 int _baseRange)
221 : base(_currentMap,_charModel,_baseMovementSpeed, _baseHealth, _baseDamage, _baseRange)
222 {
223
224 }
225
226 public void Update()
227 {
228
229 }
230 }
231 }
This page took 0.039164 seconds and 4 git commands to generate.