]> Dogcows Code - chaz/carfire/blob - CarFire/CarFire/CarFire/Projectile.cs
Modified Projectiles to work with MovementManager.
[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 MovementManager mMotion;
29 Point mPosition;
30
31 /// <summary>
32 /// The Constructor for a projectile object.
33 /// </summary>
34 /// <param name="_currentMap">The map that this character will interact with</param>
35 /// <param name="_projectileModel">The model for this projectile</param>
36 /// <param name="_velocity">How fast the projectile moves</param>
37 /// <param name="_gridX">The starting X position in the map grid</param>
38 /// <param name="_gridY">The starting Y position in the map grid</param>
39 /// <param name="_pixelX">The absolute X pixel position on the map</param>
40 /// <param name="_pixelY"> The absolute Y pixel position on the map</param>
41 public Projectile(Map _currentMap,
42 Texture2D _projectileModel,
43 Vector2 _velocity,
44 Point _position)
45
46 {
47 theMap = _currentMap;
48 projectileModel = _projectileModel;
49 velocity = _velocity;
50 mPosition = _position;
51 damage = 20;
52 // Speed is the number of grid cells you can move through per second.
53 mMotion = new MovementManager(mPosition, velocity.Length());
54 }
55 public void Update(TimeSpan timeSpan)
56 {
57 bool moveRight = false;
58 bool moveLeft = false;
59 bool moveUp = false;
60 bool moveDown = false;
61 if (velocity.X > 0)
62 moveRight = true;
63 else if (velocity.X < 0)
64 moveLeft = true;
65 if (velocity.Y > 0)
66 moveDown = true;
67 else if (velocity.Y < 0)
68 moveUp = true;
69 Point destination = MovementManager.GetNeighborCell(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown);
70 mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown);
71
72
73 }
74 /// <summary>
75 /// This method will draw a projectile to the screen
76 /// </summary>
77 /// <param name="spriteBatch"></param>
78 /// <param name="topLeftX">The map X pixel position of the topLeft of the display</param>
79 /// <param name="topLeftY">The map Y pixel position of the topLeft of the display</param>
80 public void Draw(SpriteBatch spriteBatch)
81 {
82 Rectangle position = theMap.GetRectangleFromCoordinates(mMotion.Position);
83 spriteBatch.Draw(projectileModel, position, Color.White);
84
85 }
86
87 /// <summary>
88 /// Basic getters and setters
89 /// </summary>
90 public int GridX { get { return gridX; } set { gridX = value; } }
91 public int GridY { get { return gridY; } set { gridY = value; } }
92 public int PixelX { get { return pixelX; } set { pixelX = value; } }
93 public int PixelY { get { return pixelY; } set { pixelY = value; } }
94 public Map TheMap { get { return theMap; } set { theMap = value; } }
95 public int Damage { get { return damage; } set { damage = value; } }
96 public Vector2 Position { get { return mMotion.Position; } }
97 public Point Coordinates { get { return mMotion.Coordinates; } }
98 }
99 }
This page took 0.033195 seconds and 4 git commands to generate.