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 bool playerChosen = false;
24 List<Projectile> mProjectiles = new List<Projectile>();
25 //List<IPlayer> mCharacters = new List<IPlayer>();
26 IPlayer[] mCharacters = new IPlayer[4];
28 Texture2D projectile1;
31 List<Keys> mLastPressedKeys = new List<Keys>();
33 public Display(Game game)
38 mCharacters = characters;
43 /// LoadContent will be called once per game and is the place to load
44 /// all of your content.
46 public void LoadContent(ContentManager contentManager)
48 everything = contentManager.Load<Texture2D>("cs");
49 projectile1 = contentManager.Load<Texture2D>("projectile");
53 /// UnloadContent will be called once per game and is the place to unload
56 public void UnloadContent()
58 // TODO: Unload any non ContentManager content here
62 /// Allows the game to run logic such as updating the world,
63 /// checking for collisions, gathering input, and playing audio.
65 /// <param name="gameTime">Provides a snapshot of timing values.</param>
66 public void Update(TimeSpan timespan, GameState state)
69 //INPUT - testing input... has to be through network later
71 KeyboardState keyState = Keyboard.GetState();
73 List<Keys> pressedKeys = new List<Keys>();
74 List<Keys> releasedKeys = new List<Keys>();
76 Keys[] pressedKeysArray = keyState.GetPressedKeys();
77 foreach (Keys k in pressedKeysArray)
79 if (!mLastPressedKeys.Contains(k)) pressedKeys.Add(k);
80 else mLastPressedKeys.Remove(k);
83 releasedKeys = mLastPressedKeys;
84 mLastPressedKeys = new List<Keys>(pressedKeysArray);
85 //Just apply input for the first player
86 mCharacters[0].MovePlayer(pressedKeys);
87 if (pressedKeys.Contains(Keys.Enter) && !releasedKeys.Contains(Keys.Enter))
89 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));
91 mMap.CenterCell = new Vector2(mCharacters[0].GridX, mCharacters[0].GridY);
94 //Handle projectiles - update and check for wall collisions
95 for (int i = 0; i < mProjectiles.Count; i++ )
98 if (!mGame.State.Map.IsCellOpen(new Point(mProjectiles[i].Coordinates.X, mProjectiles[i].Coordinates.Y)))
101 mProjectiles.RemoveAt(i);
106 mProjectiles[i].Update(timespan);
109 //Check for collisons
110 for (int j = 0; j < mCharacters.Length; j++)
113 if(mCharacters[j] != null)
114 for (int i = 0; i < mProjectiles.Count; i++)
116 if (mProjectiles[i].Coordinates.X == mCharacters[j].Coordinates.X && mProjectiles[i].Coordinates.Y == mCharacters[j].Coordinates.Y)
118 mCharacters[j].causeDamageTo(mProjectiles[i].Damage);
119 Console.WriteLine(mCharacters[j].Health);
120 mProjectiles.RemoveAt(i);
125 //Update input for each player
126 for (int i = 0; i < mGame.State.NumberOfPlayers; i++)
128 //If player has not selected a player yet let them select one.
129 if (mCharacters[i] == null)
131 if (mGame.State.GetKeysDown(i).Contains(Keys.Enter))
133 mCharacters[i] = new Human(mGame, "", everything, projectile1, this, mGame.State.Map.GetStartingPositionForPlayer(i + 1));
136 //Regular player input updates
140 mCharacters[i].MovePlayer(timespan, mGame.State.GetKeysDown(i));
144 if (mCharacters[0] != null)
146 mGame.State.Map.CenterCell = mCharacters[0].Position;
148 //Handle wall collisions of projectiles again...
149 for (int i = 0; i < mProjectiles.Count; i++)
151 if (!mGame.State.Map.IsCellOpen(new Point(mProjectiles[i].Coordinates.X, mProjectiles[i].Coordinates.Y)))
153 mProjectiles.RemoveAt(i);
160 if (Keyboard.GetState().IsKeyDown(Keys.PageUp)) mGame.State.Map.Zoom = mGame.State.Map.Zoom + 0.5f;
161 if (Keyboard.GetState().IsKeyDown(Keys.PageDown)) mGame.State.Map.Zoom = mGame.State.Map.Zoom - 0.5f;
166 /// This is called when the game should draw itself.
168 /// <param name="spriteBatch">Used to draw with</param>
169 public void Draw(SpriteBatch spriteBatch)
171 mGame.State.Map.Draw(spriteBatch);
172 mGame.State.Entities.ForEach(delegate(IEntity e) { e.Draw(spriteBatch); });
174 foreach(Projectile projectile in mProjectiles)
176 projectile.Draw(spriteBatch);
178 for(int i = 0; i < mGame.State.NumberOfPlayers; i++)//IPlayer character in mCharacters)
181 if (mCharacters[i] != null)
183 mCharacters[i].Draw(spriteBatch);
190 /// Add a projectile to the Display.
192 /// <param name="projectile"></param>
193 public void AddProjectiles(Projectile projectile)
195 mProjectiles.Add(projectile);