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);
54 //Debugging... Spawn eight projectiles.
57 mProjectiles.Add(new Projectile(mMap, everything, new Vector2(5,5), 10, 10, 300, 300));
58 mProjectiles.Add(new Projectile(mMap, everything, new Vector2(-5, 5), 10, 10, 300, 300));
59 mProjectiles.Add(new Projectile(mMap, everything, new Vector2(5, -5), 10, 10, 300, 300));
60 mProjectiles.Add(new Projectile(mMap, everything, new Vector2(-5, -5), 10, 10, 300, 300));
61 //Vertical and horizontal
62 mProjectiles.Add(new Projectile(mMap, everything, new Vector2(0, 5), 10, 10, 300, 300));
63 mProjectiles.Add(new Projectile(mMap, everything, new Vector2(-5, 0), 10, 10, 300, 300));
64 mProjectiles.Add(new Projectile(mMap, everything, new Vector2(5, 0), 10, 10, 300, 300));
65 mProjectiles.Add(new Projectile(mMap, everything, new Vector2(0, -5), 10, 10, 300, 300));
69 // TODO: use this.Content to load your game content here
73 /// UnloadContent will be called once per game and is the place to unload
76 public void UnloadContent()
78 // TODO: Unload any non ContentManager content here
82 /// Allows the game to run logic such as updating the world,
83 /// checking for collisions, gathering input, and playing audio.
85 /// <param name="gameTime">Provides a snapshot of timing values.</param>
86 public void Update(TimeSpan timespan, GameState state)
89 //INPUT - testing input... has to be through network later
91 KeyboardState keyState = Keyboard.GetState();
93 List<Keys> pressedKeys = new List<Keys>();
94 List<Keys> releasedKeys = new List<Keys>();
96 Keys[] pressedKeysArray = keyState.GetPressedKeys();
97 foreach (Keys k in pressedKeysArray)
99 if (!mLastPressedKeys.Contains(k)) pressedKeys.Add(k);
100 else mLastPressedKeys.Remove(k);
103 releasedKeys = mLastPressedKeys;
104 mLastPressedKeys = new List<Keys>(pressedKeysArray);
105 //Just apply input for the first player
106 mCharacters[0].MovePlayer(pressedKeys);
107 if (pressedKeys.Contains(Keys.Enter) && !releasedKeys.Contains(Keys.Enter))
109 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));
111 mMap.CenterCell = new Vector2(mCharacters[0].GridX, mCharacters[0].GridY);
114 //Handle projectiles - update and check for wall collisions
115 for (int i = 0; i < mProjectiles.Count; i++ )
117 bool removed = false;
118 if (!mMap.IsCellOpen(new Point(mProjectiles[i].GridX, mProjectiles[i].GridY)))
121 mProjectiles.RemoveAt(i);
126 mProjectiles[i].Update(timespan);
129 //Check for collisons
130 for (int j = 0; j < mCharacters.Length; j++)
133 if(mCharacters[j] != null)
134 for (int i = 0; i < mProjectiles.Count; i++)
136 if (mProjectiles[i].GridX == mCharacters[j].GridX && mProjectiles[i].GridY == mCharacters[j].GridY)
138 mCharacters[j].causeDamageTo(mProjectiles[i].Damage);
139 Console.WriteLine(mCharacters[j].Health);
140 mProjectiles.RemoveAt(i);
145 //Update input for each player
146 for (int i = 0; i < 4; i++)
148 //If player has not selected a player yet let them select one.
149 if (mCharacters[i] == null)
151 if (state.keysDown[i].Contains(Keys.Enter))
153 mCharacters[i] = (new Human(mMap, "", everything, projectile1, this));
154 mCharacters[i].GridX = mMap.GetStartingPositionForPlayer(i + 1).X;
155 mCharacters[i].GridY = mMap.GetStartingPositionForPlayer(i + 1).Y;
158 //Regular player input updates
162 mCharacters[i].MovePlayer(state.keysDown[i]);
163 mMap.CenterCell = new Vector2(mCharacters[0].GridX, mCharacters[0].GridY);
166 //Handle wall collisions of projectiles again...
167 for (int i = 0; i < mProjectiles.Count; i++)
169 if (!mMap.IsCellOpen(new Point(mProjectiles[i].GridX, mProjectiles[i].GridY)))
171 mProjectiles.RemoveAt(i);
178 if (Keyboard.GetState().IsKeyDown(Keys.PageUp)) mMap.Zoom = mMap.Zoom + 0.5f;
179 if (Keyboard.GetState().IsKeyDown(Keys.PageDown)) mMap.Zoom = mMap.Zoom - 0.5f;
184 /// This is called when the game should draw itself.
186 /// <param name="spriteBatch">Used to draw with</param>
187 public void Draw(SpriteBatch spriteBatch)
189 mMap.Draw(spriteBatch);
190 foreach(Projectile projectile in mProjectiles)
192 projectile.Draw(spriteBatch);
195 for(int i = 0; i < 4; i++)//IPlayer character in mCharacters)
197 if(mCharacters[i] != null)
198 mCharacters[i].Draw(spriteBatch);
202 /// Add a projectile to the Display.
204 /// <param name="projectile"></param>
205 public void AddProjectiles(Projectile projectile)
207 mProjectiles.Add(projectile);