]> Dogcows Code - chaz/carfire/blob - CarFire/CarFire/CarFire/Display.cs
git-svn-id: https://bd85.net/svn/cs3505_group@90 92bb83a3-7c8f-8a45-bc97-515c4e399668
[chaz/carfire] / CarFire / CarFire / CarFire / Display.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Content;
7 using Microsoft.Xna.Framework.Graphics;
8 using Microsoft.Xna.Framework.Input;
9
10 namespace CarFire
11 {
12 /// <summary>
13 /// This class is responsible for controlling what draws to the screen when the game is running.
14 /// </summary>
15 public class Display
16 {
17 List<Projectile> mProjectiles = new List<Projectile>();
18 List<Character> mCharacters = new List<Character>();
19 Map mMap;
20 int currentCenterX = 5;
21 int currentCenterY = 5;
22 public Display()
23 {
24 /*
25 mMap = aMap;
26 mCharacters = characters;
27 */
28 }
29
30 /// <summary>
31 /// LoadContent will be called once per game and is the place to load
32 /// all of your content.
33 /// </summary>
34 public void LoadContent(ContentManager contentManager)
35 {
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.
41 //Diagonals
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));
51
52 // TODO: use this.Content to load your game content here
53 }
54
55 /// <summary>
56 /// UnloadContent will be called once per game and is the place to unload
57 /// all content.
58 /// </summary>
59 public void UnloadContent()
60 {
61 // TODO: Unload any non ContentManager content here
62 }
63
64 /// <summary>
65 /// Allows the game to run logic such as updating the world,
66 /// checking for collisions, gathering input, and playing audio.
67 /// </summary>
68 /// <param name="gameTime">Provides a snapshot of timing values.</param>
69 public void Update(TimeSpan timespan)
70 {
71
72 for (int i = 0; i < mProjectiles.Count; i++ )
73 {
74 mProjectiles[i].Update(timespan);
75 if (!mMap.IsCellOpen(new Point(mProjectiles[i].GridX, mProjectiles[i].GridY)))
76 {
77
78 mProjectiles.RemoveAt(i);
79 i--;
80 }
81 }
82 //Check for collisons
83 for (int j = 0; j < mCharacters.Count; j++)
84 {
85 for (int i = 0; i < mProjectiles.Count; i++)
86 {
87 if (mProjectiles[i].GridX == mCharacters[j].GridX && mProjectiles[i].GridY == mCharacters[j].GridY)
88 {
89 //Debug - not sure if you can remove while doing for each
90 //Alternative - while loop, and decrement projectile counter if projectile is removed.
91 mProjectiles.Remove(mProjectiles[i]);
92 mCharacters[j].Health -= mProjectiles[i].Damage;
93 }
94 }
95 }
96 }
97
98 /// <summary>
99 /// This is called when the game should draw itself.
100 /// </summary>
101 /// <param name="spriteBatch">Used to draw with</param>
102 public void Draw(SpriteBatch spriteBatch)
103 {
104 mMap.Draw(spriteBatch);
105 foreach(Projectile projectile in mProjectiles)
106 {
107 //Debug - follow a projectile to make sure following is working.
108 if (mProjectiles.IndexOf(projectile) == 6)
109 mMap.CenterCell = new Vector2(projectile.GridX, projectile.GridY);
110 projectile.Draw(spriteBatch);
111
112 }
113 foreach(Character character in mCharacters)
114 {
115 character.Draw(spriteBatch);
116 }
117 }
118 }
119 }
120
This page took 0.039101 seconds and 4 git commands to generate.