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