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;
30 int currentCenterX = 5;
31 int currentCenterY = 5;
33 List<Keys> mLastPressedKeys = new List<Keys>();
39 mCharacters = characters;
44 /// LoadContent will be called once per game and is the place to load
45 /// all of your content.
47 public void LoadContent(ContentManager contentManager)
49 everything = contentManager.Load<Texture2D>("cs");
50 projectile1 = contentManager.Load<Texture2D>("projectile");
51 mMap = contentManager.Load<Map>("Maps/stable");
52 Map.DefaultTile = contentManager.Load<Texture2D>("default");
53 mMap.CenterCell = new Vector2(currentCenterX,currentCenterY);
57 /// UnloadContent will be called once per game and is the place to unload
60 public void UnloadContent()
62 // TODO: Unload any non ContentManager content here
66 /// Allows the game to run logic such as updating the world,
67 /// checking for collisions, gathering input, and playing audio.
69 /// <param name="gameTime">Provides a snapshot of timing values.</param>
70 public void Update(TimeSpan timespan, GameState state)
73 //INPUT - testing input... has to be through network later
75 KeyboardState keyState = Keyboard.GetState();
77 List<Keys> pressedKeys = new List<Keys>();
78 List<Keys> releasedKeys = new List<Keys>();
80 Keys[] pressedKeysArray = keyState.GetPressedKeys();
81 foreach (Keys k in pressedKeysArray)
83 if (!mLastPressedKeys.Contains(k)) pressedKeys.Add(k);
84 else mLastPressedKeys.Remove(k);
87 releasedKeys = mLastPressedKeys;
88 mLastPressedKeys = new List<Keys>(pressedKeysArray);
89 //Just apply input for the first player
90 mCharacters[0].MovePlayer(pressedKeys);
91 if (pressedKeys.Contains(Keys.Enter) && !releasedKeys.Contains(Keys.Enter))
93 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));
95 mMap.CenterCell = new Vector2(mCharacters[0].GridX, mCharacters[0].GridY);
98 //Handle projectiles - update and check for wall collisions
99 for (int i = 0; i < mProjectiles.Count; i++ )
101 bool removed = false;
102 if (!mMap.IsCellOpen(new Point(mProjectiles[i].GridX, mProjectiles[i].GridY)))
105 mProjectiles.RemoveAt(i);
110 mProjectiles[i].Update(timespan);
113 //Check for collisons
114 for (int j = 0; j < mCharacters.Length; j++)
117 if(mCharacters[j] != null)
118 for (int i = 0; i < mProjectiles.Count; i++)
120 if (mProjectiles[i].GridX == mCharacters[j].Coordinates.X && mProjectiles[i].GridY == mCharacters[j].Coordinates.Y)
122 mCharacters[j].causeDamageTo(mProjectiles[i].Damage);
123 Console.WriteLine(mCharacters[j].Health);
124 mProjectiles.RemoveAt(i);
129 //Update input for each player
130 for (int i = 0; i < 4; i++)
132 //If player has not selected a player yet let them select one.
133 if (mCharacters[i] == null)
135 if (state.keysDown[i].Contains(Keys.Enter))
137 mCharacters[i] = new Human(mMap, "", everything, projectile1, this, mMap.GetStartingPositionForPlayer(i+1));
140 //Regular player input updates
144 mCharacters[i].MovePlayer(timespan, state.keysDown[i]);
148 if (mCharacters[0] != null)
150 mMap.CenterCell = mCharacters[0].Position;
152 //Handle wall collisions of projectiles again...
153 for (int i = 0; i < mProjectiles.Count; i++)
155 if (!mMap.IsCellOpen(new Point(mProjectiles[i].GridX, mProjectiles[i].GridY)))
157 mProjectiles.RemoveAt(i);
164 if (Keyboard.GetState().IsKeyDown(Keys.PageUp)) mMap.Zoom = mMap.Zoom + 0.5f;
165 if (Keyboard.GetState().IsKeyDown(Keys.PageDown)) mMap.Zoom = mMap.Zoom - 0.5f;
170 /// This is called when the game should draw itself.
172 /// <param name="spriteBatch">Used to draw with</param>
173 public void Draw(SpriteBatch spriteBatch)
175 mMap.Draw(spriteBatch);
176 foreach(Projectile projectile in mProjectiles)
178 projectile.Draw(spriteBatch);
180 for(int i = 0; i < 4; i++)//IPlayer character in mCharacters)
183 if (mCharacters[i] != null)
185 mCharacters[i].Draw(spriteBatch);
192 /// Add a projectile to the Display.
194 /// <param name="projectile"></param>
195 public void AddProjectiles(Projectile projectile)
197 mProjectiles.Add(projectile);