]> Dogcows Code - chaz/carfire/blob - CarFire/CarFire/CarFire/Game.cs
Basic Changes to Character, Small Changes to Display as well to make it so a Player...
[chaz/carfire] / CarFire / CarFire / CarFire / Game.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 //code from Prof Jensen's TestHarness
13 // This class encapsulates inputs from the players.
14 public class NextInputs
15 {
16 public List<Keys>[] keysPressed;
17 public List<Keys>[] keysReleased;
18 public int[] mouseLocationX;
19 public int[] mouseLocationY;
20 public bool[] mouseLocationChanged;
21 public bool[] mousePressed;
22 public bool[] mousePressedChanged;
23
24 public NextInputs()
25 {
26 keysPressed = new List<Keys>[4];
27 keysReleased = new List<Keys>[4];
28 mouseLocationX = new int[4];
29 mouseLocationY = new int[4];
30 mouseLocationChanged = new bool[4];
31 mousePressed = new bool[4];
32 mousePressedChanged = new bool[4];
33 for (int i = 0; i < 4; i++)
34 keysPressed[i] = new List<Keys>();
35 for (int i = 0; i < 4; i++)
36 keysReleased[i] = new List<Keys>();
37 }
38 }
39
40 public class Game : IDeterministicGame
41 {
42 #region IDeterministicGame Members
43 List<IPlayer> mPlayers;
44 NextInputs inputs;
45 Object[] playerIdentifiers;
46 Display mDisplay;
47 Map mMap;
48
49 public Game()
50 {
51 mDisplay = new Display();
52 mPlayers = new List<IPlayer>();
53 }
54 public void LoadContent(ContentManager contentManager)
55 {
56 //Texture2D everything = contentManager.Load<Texture2D>("default");
57 mDisplay.LoadContent(contentManager);
58 int currentCenterX = 5; //Creates a map like the one in Display
59 int currentCenterY = 5;
60 mMap = contentManager.Load<Map>("Maps/stable");
61 Map.DefaultTile = contentManager.Load<Texture2D>("default");
62 mMap.CenterCell = new Vector2(currentCenterX, currentCenterY);
63
64 Human player = new Human(mMap, "");
65 player.LoadContent(contentManager);
66 mPlayers.Add(player);
67 mDisplay.AddCharacters(player);
68 }
69
70 public void UnloadContent()
71 {
72 }
73
74 private int idPlayer(Object playerIdentifier)
75 {
76 for (int i = 0; i < playerIdentifiers.Length; i++)
77 if (playerIdentifiers[i] == playerIdentifier)
78 return i;
79 throw new Exception("Illegal player identifier" + playerIdentifier);
80 }
81
82 public Vector2 PreferredScreenSize
83 {
84 get { return new Vector2(800, 600); }
85 }
86
87 public int MinimumSupportedPlayers
88 {
89 get { return 1; }
90 }
91
92 public int MaximumSupportedPlayers
93 {
94 get { return 4; }
95 }
96
97 public void ResetGame(object[] playerIdentifiers, object thisPlayer)
98 {
99 foreach (IPlayer player in mPlayers)
100 {
101 player.Spawn(mMap.CenterCell);
102 }
103 }
104
105 public long CurrentFrameNumber
106 {
107 get { return 0; }
108 }
109
110 public long CurrentChecksum
111 {
112 get { return 0; }
113 }
114
115 public void ApplyKeyInput(object playerIdentifier, Keys key, bool isKeyPressed)
116 {
117 //code from Prof Jensen's TestHarness
118 int player = idPlayer(playerIdentifier);
119
120 if (isKeyPressed && !inputs.keysPressed[player].Contains(key))
121 inputs.keysPressed[player].Add(key);
122
123 if (!isKeyPressed && !inputs.keysReleased[player].Contains(key))
124 inputs.keysReleased[player].Add(key);
125 }
126
127 public void ApplyMouseLocationInput(object playerIdentifier, int x, int y)
128 {
129 }
130
131 public void ApplyMouseButtonInput(object playerIdentifier, bool isButtonPressed)
132 {
133 }
134
135 public bool IsGameOver(object playerIdentifier)
136 {
137 return false;
138 }
139
140 public bool IsTerminated(object playerIdentifier)
141 {
142 return false;
143 }
144
145 public long Update(TimeSpan timespan)
146 {
147 mDisplay.Update(timespan);
148 return CurrentFrameNumber;
149 }
150
151 public long Draw(SpriteBatch spriteBatch)
152 {
153 mDisplay.Draw(spriteBatch);
154 return CurrentFrameNumber;
155 }
156
157 #endregion
158 }
159 }
This page took 0.046244 seconds and 5 git commands to generate.