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<Character> mCharacters = new List<Character>();
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));
52 // TODO: use this.Content to load your game content here
56 /// UnloadContent will be called once per game and is the place to unload
59 public void UnloadContent()
61 // TODO: Unload any non ContentManager content here
65 /// Allows the game to run logic such as updating the world,
66 /// checking for collisions, gathering input, and playing audio.
68 /// <param name="gameTime">Provides a snapshot of timing values.</param>
69 public void Update(TimeSpan timespan)
71 mMap.CenterCell = new Vector2(currentCenterX, currentCenterY);
72 foreach (Projectile projectile in mProjectiles)
74 projectile.Update(timespan);
77 foreach (Character character in mCharacters)
79 foreach (Projectile projectile in mProjectiles)
81 if (projectile.GridX == character.GridX && projectile.GridY == character.GridY)
83 //Debug - not sure if you can remove while doing for each
84 //Alternative - while loop, and decrement projectile counter if projectile is removed.
85 mProjectiles.Remove(projectile);
86 character.Health -= projectile.Damage;
93 /// This is called when the game should draw itself.
95 /// <param name="spriteBatch">Used to draw with</param>
96 public void Draw(SpriteBatch spriteBatch)
98 mMap.Draw(spriteBatch);
99 foreach(Projectile projectile in mProjectiles)
101 projectile.Draw(spriteBatch);
104 foreach(Character character in mCharacters)
106 character.Draw(spriteBatch);