]> Dogcows Code - chaz/carfire/blob - CarFire/CarFire/CarFire/XnaGame.cs
git-svn-id: https://bd85.net/svn/cs3505_group@168 92bb83a3-7c8f-8a45-bc97-515c4e399668
[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
60 /// <summary>
61 /// LoadContent will be called once per game and is the place to load
62 /// all of your content.
63 /// </summary>
64 protected override void LoadContent()
65 {
66 // Create a new SpriteBatch, which can be used to draw textures.
67 spriteBatch = new SpriteBatch(GraphicsDevice);
68
69 screenManager.LoadContent(Content, graphics);
70 deterministicGame.LoadContent(Content);
71 }
72
73 /// <summary>
74 /// UnloadContent will be called once per game and is the place to unload
75 /// all content.
76 /// </summary>
77 protected override void UnloadContent()
78 {
79 screenManager.UnloadContent();
80 deterministicGame.UnloadContent();
81 }
82
83 /// <summary>
84 /// Allows the game to run logic such as updating the world,
85 /// checking for collisions, gathering input, and playing audio.
86 /// </summary>
87 /// <param name="gameTime">Provides a snapshot of timing values.</param>
88 protected override void Update(GameTime gameTime)
89 {
90 networkGame.Update(gameTime);
91
92 base.Update(gameTime);
93 }
94
95 /// <summary>
96 /// This is called when the game should draw itself.
97 /// </summary>
98 /// <param name="gameTime">Provides a snapshot of timing values.</param>
99 protected override void Draw(GameTime gameTime)
100 {
101 spriteBatch.Begin();
102 networkGame.Draw(gameTime, spriteBatch);
103 spriteBatch.End();
104
105 base.Draw(gameTime);
106 }
107 }
108 }
This page took 0.03815 seconds and 4 git commands to generate.