2 using System.Collections.Generic;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Content;
7 using Microsoft.Xna.Framework.Graphics;
8 using Microsoft.Xna.Framework.Input;
13 /// This class is responsible for controlling what draws to the screen when the game is running.
17 List<Projectile> mProjectiles = new List<Projectile>();
18 List<IPlayer> mCharacters = new List<IPlayer>();
20 int currentCenterX = 5;
21 int currentCenterY = 5;
26 mCharacters = characters;
31 /// LoadContent will be called once per game and is the place to load
32 /// all of your content.
34 public void LoadContent(ContentManager contentManager)
36 Texture2D everything = contentManager.Load<Texture2D>("cs");
37 mMap = contentManager.Load<Map>("Maps/stable");
38 Map.DefaultTile = contentManager.Load<Texture2D>("default");
39 mMap.CenterCell = new Vector2(currentCenterX,currentCenterY);
40 //Debugging... Spawn eight projectiles.
42 mProjectiles.Add(new Projectile(mMap, everything, new Vector2(5,5), 10, 10, 300, 300));
43 mProjectiles.Add(new Projectile(mMap, everything, new Vector2(-5, 5), 10, 10, 300, 300));
44 mProjectiles.Add(new Projectile(mMap, everything, new Vector2(5, -5), 10, 10, 300, 300));
45 mProjectiles.Add(new Projectile(mMap, everything, new Vector2(-5, -5), 10, 10, 300, 300));
46 //Vertical and horizontal
47 mProjectiles.Add(new Projectile(mMap, everything, new Vector2(0, 5), 10, 10, 300, 300));
48 mProjectiles.Add(new Projectile(mMap, everything, new Vector2(-5, 0), 10, 10, 300, 300));
49 mProjectiles.Add(new Projectile(mMap, everything, new Vector2(5, 0), 10, 10, 300, 300));
50 mProjectiles.Add(new Projectile(mMap, everything, new Vector2(0, -5), 10, 10, 300, 300));
53 // TODO: use this.Content to load your game content here
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)
73 for (int i = 0; i < mProjectiles.Count; i++ )
75 mProjectiles[i].Update(timespan);
76 if (!mMap.IsCellOpen(new Point(mProjectiles[i].GridX, mProjectiles[i].GridY)))
79 mProjectiles.RemoveAt(i);
84 for (int j = 0; j < mCharacters.Count; j++)
86 for (int i = 0; i < mProjectiles.Count; i++)
88 if (mProjectiles[i].GridX == mCharacters[j].GridX && mProjectiles[i].GridY == mCharacters[j].GridY)
90 //Debug - not sure if you can remove while doing for each
91 //Alternative - while loop, and decrement projectile counter if projectile is removed.
92 mProjectiles.Remove(mProjectiles[i]);
93 mCharacters[j].causeDamageTo(mProjectiles[i].Damage);
100 /// This is called when the game should draw itself.
102 /// <param name="spriteBatch">Used to draw with</param>
103 public void Draw(SpriteBatch spriteBatch)
105 mMap.Draw(spriteBatch);
106 foreach(Projectile projectile in mProjectiles)
108 //Debug - follow a projectile to make sure following is working.
109 if (mProjectiles.IndexOf(projectile) == 6)
110 mMap.CenterCell = new Vector2(projectile.GridX, projectile.GridY);
111 projectile.Draw(spriteBatch);
114 foreach(IPlayer character in mCharacters)
116 character.Draw(spriteBatch);
120 public void AddCharacters(IPlayer player)
122 mCharacters.Add(player);