From 89e5ee7d83cfb353b6c98dcbf6ed6b87833b9866 Mon Sep 17 00:00:00 2001 From: Kyle Date: Thu, 15 Apr 2010 04:42:09 +0000 Subject: [PATCH] More test projectiles in the display class. git-svn-id: https://bd85.net/svn/cs3505_group@85 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- CarFire/CarFire/CarFire/Display.cs | 23 ++++- CarFire/CarFire/CarFire/Projectile.cs | 124 +------------------------- 2 files changed, 23 insertions(+), 124 deletions(-) diff --git a/CarFire/CarFire/CarFire/Display.cs b/CarFire/CarFire/CarFire/Display.cs index c65075f..98f91ed 100644 --- a/CarFire/CarFire/CarFire/Display.cs +++ b/CarFire/CarFire/CarFire/Display.cs @@ -9,11 +9,16 @@ using Microsoft.Xna.Framework.Input; namespace CarFire { + /// + /// This class is responsible for controlling what draws to the screen when the game is running. + /// public class Display { List mProjectiles = new List(); List mCharacters = new List(); Map mMap; + int currentCenterX = 5; + int currentCenterY = 5; public Display() { /* @@ -31,9 +36,19 @@ namespace CarFire Texture2D everything = contentManager.Load("cs"); mMap = contentManager.Load("Maps/stable"); Map.DefaultTile = contentManager.Load("default"); - mMap.CenterCell = new Vector2(5,5); - //List entities = mMap.GetAllEntities(); + mMap.CenterCell = new Vector2(currentCenterX,currentCenterY); + //Debugging... Spawn eight projectiles. + //Diagonals mProjectiles.Add(new Projectile(mMap, everything, new Vector2(5,5), 10, 10, 300, 300)); + mProjectiles.Add(new Projectile(mMap, everything, new Vector2(-5, 5), 10, 10, 300, 300)); + mProjectiles.Add(new Projectile(mMap, everything, new Vector2(5, -5), 10, 10, 300, 300)); + mProjectiles.Add(new Projectile(mMap, everything, new Vector2(-5, -5), 10, 10, 300, 300)); + //Vertical and horizontal + mProjectiles.Add(new Projectile(mMap, everything, new Vector2(0, 5), 10, 10, 300, 300)); + mProjectiles.Add(new Projectile(mMap, everything, new Vector2(-5, 0), 10, 10, 300, 300)); + mProjectiles.Add(new Projectile(mMap, everything, new Vector2(5, 0), 10, 10, 300, 300)); + mProjectiles.Add(new Projectile(mMap, everything, new Vector2(0, -5), 10, 10, 300, 300)); + // TODO: use this.Content to load your game content here } @@ -53,7 +68,7 @@ namespace CarFire /// Provides a snapshot of timing values. public void Update(TimeSpan timespan) { - + mMap.CenterCell = new Vector2(currentCenterX, currentCenterY); foreach (Projectile projectile in mProjectiles) { projectile.Update(timespan); @@ -77,7 +92,7 @@ namespace CarFire /// /// This is called when the game should draw itself. /// - /// Provides a snapshot of timing values. + /// Used to draw with public void Draw(SpriteBatch spriteBatch) { mMap.Draw(spriteBatch); diff --git a/CarFire/CarFire/CarFire/Projectile.cs b/CarFire/CarFire/CarFire/Projectile.cs index c9cce9b..1dd5e08 100644 --- a/CarFire/CarFire/CarFire/Projectile.cs +++ b/CarFire/CarFire/CarFire/Projectile.cs @@ -1,4 +1,3 @@ -<<<<<<< .mine using System; using System.Collections.Generic; using System.Linq; @@ -100,11 +99,12 @@ namespace CarFire /// The map Y pixel position of the topLeft of the display public void Draw(SpriteBatch spriteBatch) { - Console.WriteLine(gridX + " " + gridY); - Console.WriteLine(theMap.GetRectangleFromCoordinates(new Vector2(gridX, gridY))); + //Console.WriteLine(gridX + " " + gridY); + //Console.WriteLine(theMap.GetRectangleFromCoordinates(new Vector2(gridX, gridY))); Rectangle position = theMap.GetRectangleFromCoordinates(new Vector2(gridX, gridY)); spriteBatch.Draw(projectileModel, position, Color.White); - //spriteBatch.Draw(projectileModel, new Vector2(40, 40), Color.White); + //Rectangle position2 = new Rectangle(pixelX-30, pixelY-30, 60, 60); + //spriteBatch.Draw(projectileModel, position2, Color.White); } /// @@ -118,119 +118,3 @@ namespace CarFire public int Damage { get { return damage; } set { damage = value; } } } } -======= -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 that will be spawned whenever a player or a monster fires. - /// - 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.IsCellOpen(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.IsCellOpen((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 += (int)velocity.X; - pixelY += (int)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 += (int)velocity.X; - pixelY += (int)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 Map TheMap { get { return theMap; } set { theMap = value; } } - public int Damage { get { return damage; } set { damage = value; } } - } -} ->>>>>>> .r83 -- 2.43.0