]> Dogcows Code - chaz/carfire/blob - CarFire/CarFire/CarFire/XnaGame.cs
Entity loading implemented.
[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(2, 4);
83 List<object> entities = map.GetAllEntities();
84 #endif
85 }
86
87 /// <summary>
88 /// UnloadContent will be called once per game and is the place to unload
89 /// all content.
90 /// </summary>
91 protected override void UnloadContent()
92 {
93 screenManager.UnloadContent();
94 deterministicGame.UnloadContent();
95 }
96
97 /// <summary>
98 /// Allows the game to run logic such as updating the world,
99 /// checking for collisions, gathering input, and playing audio.
100 /// </summary>
101 /// <param name="gameTime">Provides a snapshot of timing values.</param>
102 protected override void Update(GameTime gameTime)
103 {
104 networkGame.Update(gameTime);
105
106 base.Update(gameTime);
107 }
108
109 /// <summary>
110 /// This is called when the game should draw itself.
111 /// </summary>
112 /// <param name="gameTime">Provides a snapshot of timing values.</param>
113 protected override void Draw(GameTime gameTime)
114 {
115 GraphicsDevice.Clear(Color.Red);
116
117 spriteBatch.Begin();
118 networkGame.Draw(gameTime, spriteBatch);
119 #if MAP_TESTING
120 map.Draw(spriteBatch);
121 #endif
122 spriteBatch.End();
123
124 base.Draw(gameTime);
125 }
126 }
127 }
This page took 0.0368 seconds and 5 git commands to generate.