]> Dogcows Code - chaz/carfire/blob - CarFire/CarFire/CarFire/Projectile.cs
git-svn-id: https://bd85.net/svn/cs3505_group@84 92bb83a3-7c8f-8a45-bc97-515c4e399668
[chaz/carfire] / CarFire / CarFire / CarFire / Projectile.cs
1 <<<<<<< .mine
2 using System;
3 using System.Collections.Generic;
4 using System.Linq;
5 using System.Text;
6 using Microsoft.Xna.Framework;
7 using Microsoft.Xna.Framework.Content;
8 using Microsoft.Xna.Framework.Graphics;
9 using Microsoft.Xna.Framework.Input;
10
11 namespace CarFire
12 {
13 /// <summary>
14 /// This class represents a projectile object that will be spawned whenever a player or a monster fires.
15 /// </summary>
16 public class Projectile
17 {
18 //Member Variables
19 Map theMap;
20 Vector2 velocity;
21 Texture2D projectileModel;
22 int damage;
23 int gridX;
24 int gridY;
25 //The pixel position should be the pixel position on the map. When a projectile is drawn
26 //these will have to be transformed to the coordinate system that the drawable screen is using.
27 int pixelX;
28 int pixelY;
29
30 /// <summary>
31 /// The Constructor for a projectile object.
32 /// </summary>
33 /// <param name="_currentMap">The map that this character will interact with</param>
34 /// <param name="_projectileModel">The model for this projectile</param>
35 /// <param name="_velocity">How fast the projectile moves</param>
36 /// <param name="_gridX">The starting X position in the map grid</param>
37 /// <param name="_gridY">The starting Y position in the map grid</param>
38 /// <param name="_pixelX">The absolute X pixel position on the map</param>
39 /// <param name="_pixelY"> The absolute Y pixel position on the map</param>
40 public Projectile(Map _currentMap,
41 Texture2D _projectileModel,
42 Vector2 _velocity,
43 int _gridX,
44 int _gridY,
45 int _pixelX,
46 int _pixelY)
47 {
48 theMap = _currentMap;
49 projectileModel = _projectileModel;
50 velocity = _velocity;
51 gridX = _gridX;
52 gridY = _gridY;
53 pixelX = _pixelX;
54 pixelY = _pixelY;
55 }
56 public void Update(TimeSpan timespan)
57 {
58 /*
59 //See if something moved onto this projectile.
60 if(theMap.isOpenSquare(gridX, gridY))
61 {
62 theMap.damageSquare(gridX, gridY, damage);
63 }
64 */
65 //If the projectile will be moving to a new grid position we need to check to see if it is occupied.
66 if ((int)((pixelX + velocity.X) / Map.PixelsToUnitSquares) != gridX || (int)((pixelY + velocity.Y) / Map.PixelsToUnitSquares) != gridY)
67 {
68 bool open = theMap.IsCellOpen((int)((pixelX + velocity.X) /Map.PixelsToUnitSquares), (int)((pixelY + velocity.Y) / Map.PixelsToUnitSquares));
69 //If open just move this projectile there
70 //***Map doesn't need to know that this projectile is there because players/monsters are allowed
71 // to move into the path of projectiles.
72 if (open)
73 {
74 Console.WriteLine("pixelX:" + pixelX + " " + " pixelY: "+ pixelY);
75 pixelX += (int)velocity.X;
76 pixelY += (int)velocity.Y;
77 gridX = (int)(pixelX /Map.PixelsToUnitSquares);
78 gridY = (int)(pixelY / Map.PixelsToUnitSquares);
79 }
80 //If the square isn't open then just damage whatever is there
81 //TODO: A projectile must be deleted after this happens
82 //else
83 {
84 //theMap.damageSquare(gridX, gridY, damage);
85 }
86 }
87 //If it is not moving grid positions just increment pixelX and pixelY
88 else
89 {
90 pixelX += (int)velocity.X;
91 pixelY += (int)velocity.Y;
92 }
93
94 }
95 /// <summary>
96 /// This method will draw a projectile to the screen
97 /// </summary>
98 /// <param name="spriteBatch"></param>
99 /// <param name="topLeftX">The map X pixel position of the topLeft of the display</param>
100 /// <param name="topLeftY">The map Y pixel position of the topLeft of the display</param>
101 public void Draw(SpriteBatch spriteBatch)
102 {
103 Console.WriteLine(gridX + " " + gridY);
104 Console.WriteLine(theMap.GetRectangleFromCoordinates(new Vector2(gridX, gridY)));
105 Rectangle position = theMap.GetRectangleFromCoordinates(new Vector2(gridX, gridY));
106 spriteBatch.Draw(projectileModel, position, Color.White);
107 //spriteBatch.Draw(projectileModel, new Vector2(40, 40), Color.White);
108 }
109
110 /// <summary>
111 /// Basic getters and setters
112 /// </summary>
113 public int GridX { get { return gridX; } set { gridX = value; } }
114 public int GridY { get { return gridY; } set { gridY = value; } }
115 public int PixelX { get { return pixelX; } set { pixelX = value; } }
116 public int PixelY { get { return pixelY; } set { pixelY = value; } }
117 public Map TheMap { get { return theMap; } set { theMap = value; } }
118 public int Damage { get { return damage; } set { damage = value; } }
119 }
120 }
121 =======
122 using System;
123 using System.Collections.Generic;
124 using System.Linq;
125 using System.Text;
126 using Microsoft.Xna.Framework;
127 using Microsoft.Xna.Framework.Content;
128 using Microsoft.Xna.Framework.Graphics;
129 using Microsoft.Xna.Framework.Input;
130
131 namespace CarFire
132 {
133 /// <summary>
134 /// This class represents a projectile object that will be spawned whenever a player or a monster fires.
135 /// </summary>
136 public class Projectile
137 {
138 //Member Variables
139 Map theMap;
140 Vector2 velocity;
141 Texture2D projectileModel;
142 int damage;
143 int gridX;
144 int gridY;
145 //The pixel position should be the pixel position on the map. When a projectile is drawn
146 //these will have to be transformed to the coordinate system that the drawable screen is using.
147 int pixelX;
148 int pixelY;
149
150 /// <summary>
151 /// The Constructor for a projectile object.
152 /// </summary>
153 /// <param name="_currentMap">The map that this character will interact with</param>
154 /// <param name="_projectileModel">The model for this projectile</param>
155 /// <param name="_velocity">How fast the projectile moves</param>
156 /// <param name="_gridX">The starting X position in the map grid</param>
157 /// <param name="_gridY">The starting Y position in the map grid</param>
158 /// <param name="_pixelX">The absolute X pixel position on the map</param>
159 /// <param name="_pixelY"> The absolute Y pixel position on the map</param>
160 public Projectile(Map _currentMap,
161 Texture2D _projectileModel,
162 Vector2 _velocity,
163 int _gridX,
164 int _gridY,
165 int _pixelX,
166 int _pixelY)
167 {
168 theMap = _currentMap;
169 projectileModel = _projectileModel;
170 velocity = _velocity;
171 gridX = _gridX;
172 gridY = _gridY;
173 pixelX = _pixelX;
174 pixelY = _pixelY;
175 }
176 public void Update()
177 {
178 //See if something moved onto this projectile.
179 if(theMap.IsCellOpen(gridX, gridY))
180 {
181 //theMap.damageSquare(gridX, gridY, damage);
182 }
183 //If the projectile will be moving to a new grid position we need to check to see if it is occupied.
184 /*
185 if ((int)((pixelX + velocity.X) / theMap.gridToPixelRatio) != gridX || (int)((pixelY + velocity.Y) / Map.gridToPixelRatio) != gridY)
186 {
187 bool open = theMap.IsCellOpen((pixelX + velocity.X) / theMap.gridToPixelRatio, (pixelY + velocity.Y) / Map.gridToPixelRatio);
188 //If open just move this projectile there
189 //***Map doesn't need to know that this projectile is there because players/monsters are allowed
190 // to move into the path of projectiles.
191 if (open)
192 {
193 pixelX += (int)velocity.X;
194 pixelY += (int)velocity.Y;
195 gridX = pixelX / theMap.gridToPixelRatio;
196 gridY = pixelY / theMap.gridToPixelRatio;
197 }
198 //If the square isn't open then just damage whatever is there
199 //TODO: A projectile must be deleted after this happens
200 else
201 {
202 //theMap.damageSquare(gridX, gridY, damage);
203 }
204 }
205 */
206 //If it is not moving grid positions just increment pixelX and pixelY
207 else
208 {
209 pixelX += (int)velocity.X;
210 pixelY += (int)velocity.Y;
211 }
212
213 }
214 /// <summary>
215 /// This method will draw a projectile to the screen
216 /// </summary>
217 /// <param name="spriteBatch"></param>
218 /// <param name="topLeftX">The map X pixel position of the topLeft of the display</param>
219 /// <param name="topLeftY">The map Y pixel position of the topLeft of the display</param>
220 public void Draw(SpriteBatch spriteBatch, int topLeftX, int topLeftY)
221 {
222 spriteBatch.Draw(projectileModel, new Vector2(topLeftX - pixelX, topLeftY - pixelY), null, Color.White, 0, new Vector2(0f, 0f), 1f, SpriteEffects.None, 0);
223 }
224
225 /// <summary>
226 /// Basic getters and setters
227 /// </summary>
228 public int GridX { get { return gridX; } set { gridX = value; } }
229 public int GridY { get { return gridY; } set { gridY = value; } }
230 public int PixelX { get { return pixelX; } set { pixelX = value; } }
231 public int PixelY { get { return pixelY; } set { pixelY = value; } }
232 public Map TheMap { get { return theMap; } set { theMap = value; } }
233 public int Damage { get { return damage; } set { damage = value; } }
234 }
235 }
236 >>>>>>> .r83
This page took 0.04178 seconds and 4 git commands to generate.