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