]> Dogcows Code - chaz/carfire/blob - CarFire/CarFire/CarFire/XnaGame.cs
6f8a421358d73dae6d66e61f1d102d2a4f59124e
[chaz/carfire] / CarFire / CarFire / CarFire / XnaGame.cs
1
2 // DEBUG: for map testing
3 //#define MAP_TESTING
4
5 using System;
6 using System.Collections.Generic;
7 using System.Linq;
8 using Microsoft.Xna.Framework;
9 using Microsoft.Xna.Framework.Audio;
10 using Microsoft.Xna.Framework.Content;
11 using Microsoft.Xna.Framework.GamerServices;
12 using Microsoft.Xna.Framework.Graphics;
13 using Microsoft.Xna.Framework.Input;
14 using Microsoft.Xna.Framework.Media;
15 using Microsoft.Xna.Framework.Net;
16 using Microsoft.Xna.Framework.Storage;
17
18 namespace CarFire
19 {
20 /// <summary>
21 /// This is the main type for your game
22 /// </summary>
23 public class XnaGame : Microsoft.Xna.Framework.Game
24 {
25 GraphicsDeviceManager graphics;
26 SpriteBatch spriteBatch;
27
28 NetworkManager networkGame;
29 IScreenManager screenManager;
30 IDeterministicGame deterministicGame;
31
32 #if MAP_TESTING
33 Map map;
34 #endif
35
36 public XnaGame()
37 {
38 graphics = new GraphicsDeviceManager(this);
39 Content.RootDirectory = "Content";
40
41 Components.Add(new GamerServicesComponent(this));
42
43 screenManager = new ScreenManager();
44 deterministicGame = new Game();
45 networkGame = new NetworkManager(screenManager, deterministicGame);
46
47 Vector2 size = deterministicGame.PreferredScreenSize;
48 graphics.PreferredBackBufferWidth = (int)size.X;
49 graphics.PreferredBackBufferHeight = (int)size.Y;
50 graphics.ApplyChanges();
51 }
52
53 /// <summary>
54 /// Allows the game to perform any initialization it needs to before starting to run.
55 /// This is where it can query for any required services and load any non-graphic
56 /// related content. Calling base.Initialize will enumerate through any components
57 /// and initialize them as well.
58 /// </summary>
59 protected override void Initialize()
60 {
61 IsFixedTimeStep = true;
62 TargetElapsedTime = networkGame.TargetTimeSpan;
63
64 base.Initialize();
65 }
66
67 /// <summary>
68 /// LoadContent will be called once per game and is the place to load
69 /// all of your content.
70 /// </summary>
71 protected override void LoadContent()
72 {
73 // Create a new SpriteBatch, which can be used to draw textures.
74 spriteBatch = new SpriteBatch(GraphicsDevice);
75
76 screenManager.LoadContent(Content, graphics);
77 deterministicGame.LoadContent(Content);
78
79 #if MAP_TESTING
80 map = Content.Load<Map>("Maps/sandbox");
81 Map.DefaultTile = Content.Load<Texture2D>("default");
82 map.CenterCell = new Vector2(7, 7);
83 #endif
84 }
85
86 /// <summary>
87 /// UnloadContent will be called once per game and is the place to unload
88 /// all content.
89 /// </summary>
90 protected override void UnloadContent()
91 {
92 screenManager.UnloadContent();
93 deterministicGame.UnloadContent();
94 }
95
96 /// <summary>
97 /// Allows the game to run logic such as updating the world,
98 /// checking for collisions, gathering input, and playing audio.
99 /// </summary>
100 /// <param name="gameTime">Provides a snapshot of timing values.</param>
101 protected override void Update(GameTime gameTime)
102 {
103 networkGame.Update(gameTime);
104
105 base.Update(gameTime);
106 }
107
108 /// <summary>
109 /// This is called when the game should draw itself.
110 /// </summary>
111 /// <param name="gameTime">Provides a snapshot of timing values.</param>
112 protected override void Draw(GameTime gameTime)
113 {
114 GraphicsDevice.Clear(Color.Red);
115
116 spriteBatch.Begin();
117 networkGame.Draw(gameTime, spriteBatch);
118 #if MAP_TESTING
119 map.Draw(spriteBatch);
120 #endif
121 spriteBatch.End();
122
123 base.Draw(gameTime);
124 }
125 }
126 }
This page took 0.033695 seconds and 3 git commands to generate.