]> Dogcows Code - chaz/carfire/blob - CarFire/CarFire/CarFire/Projectile.cs
git-svn-id: https://bd85.net/svn/cs3505_group@93 92bb83a3-7c8f-8a45-bc97-515c4e399668
[chaz/carfire] / CarFire / CarFire / CarFire / Projectile.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 /// This class represents a projectile object that will be spawned whenever a player or a monster fires.
14 /// </summary>
15 public class Projectile
16 {
17 //Member Variables
18 Map theMap;
19 Vector2 velocity;
20 Texture2D projectileModel;
21 int damage;
22 int gridX;
23 int gridY;
24 //The pixel position should be the pixel position on the map. When a projectile is drawn
25 //these will have to be transformed to the coordinate system that the drawable screen is using.
26 int pixelX;
27 int pixelY;
28
29 /// <summary>
30 /// The Constructor for a projectile object.
31 /// </summary>
32 /// <param name="_currentMap">The map that this character will interact with</param>
33 /// <param name="_projectileModel">The model for this projectile</param>
34 /// <param name="_velocity">How fast the projectile moves</param>
35 /// <param name="_gridX">The starting X position in the map grid</param>
36 /// <param name="_gridY">The starting Y position in the map grid</param>
37 /// <param name="_pixelX">The absolute X pixel position on the map</param>
38 /// <param name="_pixelY"> The absolute Y pixel position on the map</param>
39 public Projectile(Map _currentMap,
40 Texture2D _projectileModel,
41 Vector2 _velocity,
42 int _gridX,
43 int _gridY,
44 int _pixelX,
45 int _pixelY)
46 {
47 theMap = _currentMap;
48 projectileModel = _projectileModel;
49 velocity = _velocity;
50 gridX = _gridX;
51 gridY = _gridY;
52 pixelX = _pixelX;
53 pixelY = _pixelY;
54 damage = 20;
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 //Rectangle position2 = new Rectangle(pixelX-30, pixelY-30, 60, 60);
108 //spriteBatch.Draw(projectileModel, position2, Color.White);
109 }
110
111 /// <summary>
112 /// Basic getters and setters
113 /// </summary>
114 public int GridX { get { return gridX; } set { gridX = value; } }
115 public int GridY { get { return gridY; } set { gridY = value; } }
116 public int PixelX { get { return pixelX; } set { pixelX = value; } }
117 public int PixelY { get { return pixelY; } set { pixelY = value; } }
118 public Map TheMap { get { return theMap; } set { theMap = value; } }
119 public int Damage { get { return damage; } set { damage = value; } }
120 }
121 }
This page took 0.039243 seconds and 5 git commands to generate.