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 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() { /* mMap = aMap; mCharacters = characters; */ } /// /// LoadContent will be called once per game and is the place to load /// all of your content. /// public void LoadContent(ContentManager contentManager) { Texture2D everything = contentManager.Load("cs"); mMap = contentManager.Load("Maps/stable"); Map.DefaultTile = contentManager.Load("default"); 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 } /// /// UnloadContent will be called once per game and is the place to unload /// all content. /// public void UnloadContent() { // TODO: Unload any non ContentManager content here } /// /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// /// Provides a snapshot of timing values. public void Update(TimeSpan timespan) { for (int i = 0; i < mProjectiles.Count; i++ ) { mProjectiles[i].Update(timespan); if (!mMap.IsCellOpen(new Point(mProjectiles[i].GridX, mProjectiles[i].GridY))) { mProjectiles.RemoveAt(i); i--; } } //Check for collisons for (int j = 0; j < mCharacters.Count; j++) { for (int i = 0; i < mProjectiles.Count; i++) { if (mProjectiles[i].GridX == mCharacters[j].GridX && mProjectiles[i].GridY == mCharacters[j].GridY) { //Debug - not sure if you can remove while doing for each //Alternative - while loop, and decrement projectile counter if projectile is removed. mProjectiles.Remove(mProjectiles[i]); mCharacters[j].causeDamageTo(mProjectiles[i].Damage); } } } } /// /// This is called when the game should draw itself. /// /// Used to draw with public void Draw(SpriteBatch spriteBatch) { mMap.Draw(spriteBatch); foreach(Projectile projectile in mProjectiles) { //Debug - follow a projectile to make sure following is working. if (mProjectiles.IndexOf(projectile) == 6) mMap.CenterCell = new Vector2(projectile.GridX, projectile.GridY); projectile.Draw(spriteBatch); } foreach(IPlayer character in mCharacters) { character.Draw(spriteBatch); } } public void AddCharacters(IPlayer player) { mCharacters.Add(player); } } }