3 // Define INGAME_ZOOM to allow zooming in and out with
4 // the PageUp and PageDown keys.
8 using System.Collections.Generic;
11 using Microsoft.Xna.Framework;
12 using Microsoft.Xna.Framework.Content;
13 using Microsoft.Xna.Framework.Graphics;
14 using Microsoft.Xna.Framework.Input;
19 /// This class is responsible for controlling what draws to the screen when the game is running.
23 List<Projectile> mProjectiles = new List<Projectile>();
24 //List<IPlayer> mCharacters = new List<IPlayer>();
25 //IPlayer[] mCharacters = new IPlayer[4];
27 Texture2D projectile1;
30 List<Keys> mLastPressedKeys = new List<Keys>();
32 public Display(Game game)
37 mCharacters = characters;
42 /// LoadContent will be called once per game and is the place to load
43 /// all of your content.
45 public void LoadContent(ContentManager contentManager)
47 everything = contentManager.Load<Texture2D>("cs");
48 projectile1 = contentManager.Load<Texture2D>("projectile");
52 /// UnloadContent will be called once per game and is the place to unload
55 public void UnloadContent()
57 // TODO: Unload any non ContentManager content here
61 /// Allows the game to run logic such as updating the world,
62 /// checking for collisions, gathering input, and playing audio.
64 /// <param name="gameTime">Provides a snapshot of timing values.</param>
65 public void Update(TimeSpan timespan, GameState state, int thisPlayer)
68 //INPUT - testing input... has to be through network later
70 KeyboardState keyState = Keyboard.GetState();
72 List<Keys> pressedKeys = new List<Keys>();
73 List<Keys> releasedKeys = new List<Keys>();
75 Keys[] pressedKeysArray = keyState.GetPressedKeys();
76 foreach (Keys k in pressedKeysArray)
78 if (!mLastPressedKeys.Contains(k)) pressedKeys.Add(k);
79 else mLastPressedKeys.Remove(k);
82 releasedKeys = mLastPressedKeys;
83 mLastPressedKeys = new List<Keys>(pressedKeysArray);
84 //Just apply input for the first player
85 mCharacters[0].MovePlayer(pressedKeys);
86 if (pressedKeys.Contains(Keys.Enter) && !releasedKeys.Contains(Keys.Enter))
88 mProjectiles.Add(new Projectile(mMap, everything, new Vector2(-5,0), mCharacters[0].GridX +1, mCharacters[0].GridY+1, (int)mCharacters[0].GridX*(int)Map.PixelsToUnitSquares,(int)mCharacters[0].GridY*(int)Map.PixelsToUnitSquares));
90 mMap.CenterCell = new Vector2(mCharacters[0].GridX, mCharacters[0].GridY);
93 //Handle projectiles - update and check for wall collisions
94 for (int i = 0; i < mProjectiles.Count; i++ )
97 if (!mGame.State.Map.IsCellOpen(new Point(mProjectiles[i].Coordinates.X, mProjectiles[i].Coordinates.Y)))
100 mProjectiles.RemoveAt(i);
105 mProjectiles[i].Update(timespan);
108 //Check for collisons
109 for (int j = 0; j < mGame.State.mCharacters.Length; j++)
112 if(mGame.State.mCharacters[j] != null)
113 for (int i = 0; i < mProjectiles.Count; i++)
115 if (mProjectiles[i].Coordinates.X == mGame.State.mCharacters[j].Coordinates.X && mProjectiles[i].Coordinates.Y == mGame.State.mCharacters[j].Coordinates.Y)
117 mGame.State.mCharacters[j].causeDamageTo(mProjectiles[i].Damage);
118 Console.WriteLine(mGame.State.mCharacters[j].Health);
119 mProjectiles.RemoveAt(i);
124 //Update input for each player
125 for (int i = 0; i < mGame.State.NumberOfPlayers; i++)
127 //If player has not selected a player yet let them select one.
128 if (mGame.State.mCharacters[i] == null)
130 if (mGame.State.GetKeysDown(i).Contains(Keys.Enter))
132 //mCharacters[i] = new Human(mGame, "", everything, projectile1, this, mGame.State.Map.GetStartingPositionForPlayer(i + 1));
135 //Regular player input updates
139 mGame.State.mCharacters[i].UpdateInput(timespan, mGame.State.GetKeysDown(i));
143 if (mGame.State.mCharacters[thisPlayer] != null)
145 mGame.State.Map.CenterCell = mGame.State.mCharacters[thisPlayer].Position;
147 //Handle wall collisions of projectiles again...
148 for (int i = 0; i < mProjectiles.Count; i++)
150 if (!mGame.State.Map.IsCellOpen(new Point(mProjectiles[i].Coordinates.X, mProjectiles[i].Coordinates.Y)))
152 mProjectiles.RemoveAt(i);
159 if (Keyboard.GetState().IsKeyDown(Keys.PageUp)) mGame.State.Map.Zoom = mGame.State.Map.Zoom + 0.5f;
160 if (Keyboard.GetState().IsKeyDown(Keys.PageDown)) mGame.State.Map.Zoom = mGame.State.Map.Zoom - 0.5f;
165 /// This is called when the game should draw itself.
167 /// <param name="spriteBatch">Used to draw with</param>
168 public void Draw(SpriteBatch spriteBatch)
170 mGame.State.Map.Draw(spriteBatch);
171 mGame.State.Entities.ForEach(delegate(IEntity e) { e.Draw(spriteBatch); });
173 foreach(Projectile projectile in mProjectiles)
175 projectile.Draw(spriteBatch);
177 for(int i = 0; i < mGame.State.NumberOfPlayers; i++)//IPlayer character in mCharacters)
180 if (mGame.State.mCharacters[i] != null)
182 mGame.State.mCharacters[i].Draw(spriteBatch);
189 /// Add a projectile to the Display.
191 /// <param name="projectile"></param>
192 public void AddProjectiles(Projectile projectile)
194 mProjectiles.Add(projectile);