]> Dogcows Code - chaz/carfire/blob - CarFire/CarFire/CarFire/Projectile.cs
More test projectiles in the display class.
[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 }
55 public void Update(TimeSpan timespan)
56 {
57 /*
58 //See if something moved onto this projectile.
59 if(theMap.isOpenSquare(gridX, gridY))
60 {
61 theMap.damageSquare(gridX, gridY, damage);
62 }
63 */
64 //If the projectile will be moving to a new grid position we need to check to see if it is occupied.
65 if ((int)((pixelX + velocity.X) / Map.PixelsToUnitSquares) != gridX || (int)((pixelY + velocity.Y) / Map.PixelsToUnitSquares) != gridY)
66 {
67 bool open = theMap.IsCellOpen((int)((pixelX + velocity.X) /Map.PixelsToUnitSquares), (int)((pixelY + velocity.Y) / Map.PixelsToUnitSquares));
68 //If open just move this projectile there
69 //***Map doesn't need to know that this projectile is there because players/monsters are allowed
70 // to move into the path of projectiles.
71 if (open)
72 {
73 Console.WriteLine("pixelX:" + pixelX + " " + " pixelY: "+ pixelY);
74 pixelX += (int)velocity.X;
75 pixelY += (int)velocity.Y;
76 gridX = (int)(pixelX /Map.PixelsToUnitSquares);
77 gridY = (int)(pixelY / Map.PixelsToUnitSquares);
78 }
79 //If the square isn't open then just damage whatever is there
80 //TODO: A projectile must be deleted after this happens
81 //else
82 {
83 //theMap.damageSquare(gridX, gridY, damage);
84 }
85 }
86 //If it is not moving grid positions just increment pixelX and pixelY
87 else
88 {
89 pixelX += (int)velocity.X;
90 pixelY += (int)velocity.Y;
91 }
92
93 }
94 /// <summary>
95 /// This method will draw a projectile to the screen
96 /// </summary>
97 /// <param name="spriteBatch"></param>
98 /// <param name="topLeftX">The map X pixel position of the topLeft of the display</param>
99 /// <param name="topLeftY">The map Y pixel position of the topLeft of the display</param>
100 public void Draw(SpriteBatch spriteBatch)
101 {
102 //Console.WriteLine(gridX + " " + gridY);
103 //Console.WriteLine(theMap.GetRectangleFromCoordinates(new Vector2(gridX, gridY)));
104 Rectangle position = theMap.GetRectangleFromCoordinates(new Vector2(gridX, gridY));
105 spriteBatch.Draw(projectileModel, position, Color.White);
106 //Rectangle position2 = new Rectangle(pixelX-30, pixelY-30, 60, 60);
107 //spriteBatch.Draw(projectileModel, position2, 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 }
This page took 0.04276 seconds and 4 git commands to generate.