]> Dogcows Code - chaz/carfire/blob - CarFire/CarFire/CarFire/Display.cs
Basic Changes to Character, Small Changes to Display as well to make it so a Player...
[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<IPlayer> mCharacters = new List<IPlayer>();
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
53 // TODO: use this.Content to load your game content here
54 }
55
56 /// <summary>
57 /// UnloadContent will be called once per game and is the place to unload
58 /// all content.
59 /// </summary>
60 public void UnloadContent()
61 {
62 // TODO: Unload any non ContentManager content here
63 }
64
65 /// <summary>
66 /// Allows the game to run logic such as updating the world,
67 /// checking for collisions, gathering input, and playing audio.
68 /// </summary>
69 /// <param name="gameTime">Provides a snapshot of timing values.</param>
70 public void Update(TimeSpan timespan)
71 {
72
73 for (int i = 0; i < mProjectiles.Count; i++ )
74 {
75 mProjectiles[i].Update(timespan);
76 if (!mMap.IsCellOpen(new Point(mProjectiles[i].GridX, mProjectiles[i].GridY)))
77 {
78
79 mProjectiles.RemoveAt(i);
80 i--;
81 }
82 }
83 //Check for collisons
84 for (int j = 0; j < mCharacters.Count; j++)
85 {
86 for (int i = 0; i < mProjectiles.Count; i++)
87 {
88 if (mProjectiles[i].GridX == mCharacters[j].GridX && mProjectiles[i].GridY == mCharacters[j].GridY)
89 {
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);
94 }
95 }
96 }
97 }
98
99 /// <summary>
100 /// This is called when the game should draw itself.
101 /// </summary>
102 /// <param name="spriteBatch">Used to draw with</param>
103 public void Draw(SpriteBatch spriteBatch)
104 {
105 mMap.Draw(spriteBatch);
106 foreach(Projectile projectile in mProjectiles)
107 {
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);
112
113 }
114 foreach(IPlayer character in mCharacters)
115 {
116 character.Draw(spriteBatch);
117 }
118 }
119
120 public void AddCharacters(IPlayer player)
121 {
122 mCharacters.Add(player);
123 }
124 }
125 }
126
This page took 0.037966 seconds and 4 git commands to generate.