]> Dogcows Code - chaz/carfire/blob - CarFire/CarFire/CarFire/Display.cs
More test projectiles in the display class.
[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 mMap.CenterCell = new Vector2(currentCenterX, currentCenterY);
72 foreach (Projectile projectile in mProjectiles)
73 {
74 projectile.Update(timespan);
75 }
76 //Check for collisons
77 foreach (Character character in mCharacters)
78 {
79 foreach (Projectile projectile in mProjectiles)
80 {
81 if (projectile.GridX == character.GridX && projectile.GridY == character.GridY)
82 {
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;
87 }
88 }
89 }
90 }
91
92 /// <summary>
93 /// This is called when the game should draw itself.
94 /// </summary>
95 /// <param name="spriteBatch">Used to draw with</param>
96 public void Draw(SpriteBatch spriteBatch)
97 {
98 mMap.Draw(spriteBatch);
99 foreach(Projectile projectile in mProjectiles)
100 {
101 projectile.Draw(spriteBatch);
102
103 }
104 foreach(Character character in mCharacters)
105 {
106 character.Draw(spriteBatch);
107 }
108
109
110 }
111 }
112 }
113
This page took 0.03383 seconds and 4 git commands to generate.