From 2eb9216eac3321adc2f897068396e7fb1f126089 Mon Sep 17 00:00:00 2001 From: Kyle Date: Tue, 13 Apr 2010 02:25:17 +0000 Subject: [PATCH] Initial commit. Basic infrastructure done. git-svn-id: https://bd85.net/svn/cs3505_group@66 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- .../CarFire/CharacterTestBed/Projectile.cs | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 CarFire/CarFire/CharacterTestBed/Projectile.cs diff --git a/CarFire/CarFire/CharacterTestBed/Projectile.cs b/CarFire/CarFire/CharacterTestBed/Projectile.cs new file mode 100644 index 0000000..a49476c --- /dev/null +++ b/CarFire/CarFire/CharacterTestBed/Projectile.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; + +namespace CarFire +{ + /// + /// This class represents a projectile object. + /// + public class Projectile + { + //Member Variables + Map theMap; + Vector2 velocity; + Texture2D projectileModel; + int damage; + int gridX; + int gridY; + //The pixel position should be the pixel position on the map. When a projectile is drawn + //these will have to be transformed to the coordinate system that the drawable screen is using. + int pixelX; + int pixelY; + + /// + /// The Constructor for a projectile object. + /// + /// The map that this character will interact with + /// The model for this projectile + /// How fast the projectile moves + /// The starting X position in the map grid + /// The starting Y position in the map grid + /// The absolute X pixel position on the map + /// The absolute Y pixel position on the map + public Projectile(Map _currentMap, + Texture2D _projectileModel, + Vector2 _velocity, + int _gridX, + int _gridY, + int _pixelX, + int _pixelY) + { + theMap = _currentMap; + projectileModel = _projectileModel; + velocity = _velocity; + gridX = _gridX; + gridY = _gridY; + pixelX = _pixelX; + pixelY = _pixelY; + } + public void Update() + { + //See if something moved onto this projectile. + if(theMap.isOpenSquare(gridX, gridY)) + { + theMap.damageSquare(gridX, gridY, damage); + } + //If the projectile will be moving to a new grid position we need to check to see if it is occupied. + if ((int)((pixelX + velocity.X) / theMap.gridToPixelRatio) != gridX || (int)((pixelY + velocity.Y) / Map.gridToPixelRatio) != gridY) + { + bool open = theMap.isOpenSquare((pixelX + velocity.X) / theMap.gridToPixelRatio, (pixelY + velocity.Y) / Map.gridToPixelRatio); + //If open just move this projectile there + //***Map doesn't need to know that this projectile is there because players/monsters are allowed + // to move into the path of projectiles. + if (open) + { + pixelX += velocity.X; + pixelY += velocity.Y; + gridX = pixelX / theMap.gridToPixelRatio; + gridY = pixelY / theMap.gridToPixelRatio; + } + //If the square isn't open then just damage whatever is there + //TODO: A projectile must be deleted after this happens + else + { + theMap.damageSquare(gridX, gridY, damage); + } + } + //If it is not moving grid positions just increment pixelX and pixelY + else + { + pixelX += velocity.X; + pixelY += velocity.Y; + } + + } + /// + /// This method will draw a projectile to the screen + /// + /// + /// The map X pixel position of the topLeft of the display + /// The map Y pixel position of the topLeft of the display + public void Draw(SpriteBatch spriteBatch, int topLeftX, int topLeftY) + { + spriteBatch.Draw(projectileModel, new Vector2(topLeftX - pixelX, topLeftY - pixelY), null, Color.White, 0, new Vector2(0f, 0f), 1f, SpriteEffects.None, 0); + } + + /// + /// Basic getters and setters + /// + public int GridX { get { return gridX; } set { gridX = value; } } + public int GridY { get { return gridY; } set { gridY = value; } } + public int PixelX { get { return pixelX; } set { pixelX = value; } } + public int PixelY { get { return pixelY; } set { pixelY = value; } } + public int Health { get { return health; } set { health = value; } } + public Map TheMap { get { return theMap; } set { theMap = value; } } + } +} -- 2.45.2