]> Dogcows Code - chaz/carfire/blob - CarFire/CarFire/CharacterTestBed/Projectile.cs
git-svn-id: https://bd85.net/svn/cs3505_group@71 92bb83a3-7c8f-8a45-bc97-515c4e399668
[chaz/carfire] / CarFire / CarFire / CharacterTestBed / 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()
56 {
57 //See if something moved onto this projectile.
58 if(theMap.isOpenSquare(gridX, gridY))
59 {
60 theMap.damageSquare(gridX, gridY, damage);
61 }
62 //If the projectile will be moving to a new grid position we need to check to see if it is occupied.
63 if ((int)((pixelX + velocity.X) / theMap.gridToPixelRatio) != gridX || (int)((pixelY + velocity.Y) / Map.gridToPixelRatio) != gridY)
64 {
65 bool open = theMap.isOpenSquare((pixelX + velocity.X) / theMap.gridToPixelRatio, (pixelY + velocity.Y) / Map.gridToPixelRatio);
66 //If open just move this projectile there
67 //***Map doesn't need to know that this projectile is there because players/monsters are allowed
68 // to move into the path of projectiles.
69 if (open)
70 {
71 pixelX += (int)velocity.X;
72 pixelY += (int)velocity.Y;
73 gridX = pixelX / theMap.gridToPixelRatio;
74 gridY = pixelY / theMap.gridToPixelRatio;
75 }
76 //If the square isn't open then just damage whatever is there
77 //TODO: A projectile must be deleted after this happens
78 else
79 {
80 theMap.damageSquare(gridX, gridY, damage);
81 }
82 }
83 //If it is not moving grid positions just increment pixelX and pixelY
84 else
85 {
86 pixelX += (int)velocity.X;
87 pixelY += (int)velocity.Y;
88 }
89
90 }
91 /// <summary>
92 /// This method will draw a projectile to the screen
93 /// </summary>
94 /// <param name="spriteBatch"></param>
95 /// <param name="topLeftX">The map X pixel position of the topLeft of the display</param>
96 /// <param name="topLeftY">The map Y pixel position of the topLeft of the display</param>
97 public void Draw(SpriteBatch spriteBatch, int topLeftX, int topLeftY)
98 {
99 spriteBatch.Draw(projectileModel, new Vector2(topLeftX - pixelX, topLeftY - pixelY), null, Color.White, 0, new Vector2(0f, 0f), 1f, SpriteEffects.None, 0);
100 }
101
102 /// <summary>
103 /// Basic getters and setters
104 /// </summary>
105 public int GridX { get { return gridX; } set { gridX = value; } }
106 public int GridY { get { return gridY; } set { gridY = value; } }
107 public int PixelX { get { return pixelX; } set { pixelX = value; } }
108 public int PixelY { get { return pixelY; } set { pixelY = value; } }
109 public Map TheMap { get { return theMap; } set { theMap = value; } }
110 }
111 }
This page took 0.037354 seconds and 4 git commands to generate.