]> Dogcows Code - chaz/carfire/blob - CarFire/CarFire/CarFire/Projectile.cs
better player movement (walls are no longer sticky)
[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 int _damage)
48
49 {
50 mGame = theGame;
51 mCharacterIndex = characterNumber;
52 projectileModel = _projectileModel;
53 velocity = _velocity;
54 mPosition = _position;
55 damage = _damage;
56 // Speed is the number of grid cells you can move through per second.
57 mMotion = new MovementManager(mPosition, velocity.Length());
58 }
59 public void Update(TimeSpan timeSpan)
60 {
61 bool moveRight = false;
62 bool moveLeft = false;
63 bool moveUp = false;
64 bool moveDown = false;
65 if (velocity.X > 0)
66 moveRight = true;
67 else if (velocity.X < 0)
68 moveLeft = true;
69 if (velocity.Y > 0)
70 moveDown = true;
71 else if (velocity.Y < 0)
72 moveUp = true;
73 Point destination = MovementManager.GetNeighbor(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown);
74 mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown);
75
76
77 }
78 /// <summary>
79 /// This method will draw a projectile to the screen
80 /// </summary>
81 /// <param name="spriteBatch"></param>
82 /// <param name="topLeftX">The map X pixel position of the topLeft of the display</param>
83 /// <param name="topLeftY">The map Y pixel position of the topLeft of the display</param>
84 public void Draw(SpriteBatch spriteBatch)
85 {
86 Rectangle position = mGame.State.Map.GetRectangleFromCoordinates(mMotion.Position);
87 spriteBatch.Draw(projectileModel, position, Color.White);
88
89 }
90
91 /// <summary>
92 /// Basic getters and setters
93 /// </summary>
94 public int GridX { get { return gridX; } set { gridX = value; } }
95 public int GridY { get { return gridY; } set { gridY = value; } }
96 public int PixelX { get { return pixelX; } set { pixelX = value; } }
97 public int PixelY { get { return pixelY; } set { pixelY = value; } }
98 public int Damage { get { return damage; } set { damage = value; } }
99 public int CharacterIndex { get { return mCharacterIndex; } }
100 public Vector2 Position { get { return mMotion.Position; } }
101 public Point Coordinates { get { return mMotion.Coordinates; } }
102 }
103 }
This page took 0.03437 seconds and 4 git commands to generate.