2 // DEBUG: for map testing
6 using System.Collections.Generic;
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;
21 /// This is the main type for your game
23 public class XnaGame : Microsoft.Xna.Framework.Game
25 GraphicsDeviceManager graphics;
26 SpriteBatch spriteBatch;
28 NetworkManager networkGame;
29 IScreenManager screenManager;
30 IDeterministicGame deterministicGame;
38 graphics = new GraphicsDeviceManager(this);
39 Content.RootDirectory = "Content";
41 Components.Add(new GamerServicesComponent(this));
43 screenManager = new ScreenManager();
44 deterministicGame = new Game();
45 networkGame = new NetworkManager(screenManager, deterministicGame);
47 Vector2 size = deterministicGame.PreferredScreenSize;
48 graphics.PreferredBackBufferWidth = (int)size.X;
49 graphics.PreferredBackBufferHeight = (int)size.Y;
50 graphics.ApplyChanges();
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.
59 protected override void Initialize()
61 IsFixedTimeStep = true;
62 TargetElapsedTime = networkGame.TargetTimeSpan;
68 /// LoadContent will be called once per game and is the place to load
69 /// all of your content.
71 protected override void LoadContent()
73 // Create a new SpriteBatch, which can be used to draw textures.
74 spriteBatch = new SpriteBatch(GraphicsDevice);
76 screenManager.LoadContent(Content, graphics);
77 deterministicGame.LoadContent(Content);
80 map = Content.Load<Map>("Maps/stable");
81 Map.DefaultTile = Content.Load<Texture2D>("default");
82 map.CenterCell = new Vector2(2, 4);
83 List<object> entities = map.GetAllEntities();
88 /// UnloadContent will be called once per game and is the place to unload
91 protected override void UnloadContent()
93 screenManager.UnloadContent();
94 deterministicGame.UnloadContent();
98 /// Allows the game to run logic such as updating the world,
99 /// checking for collisions, gathering input, and playing audio.
101 /// <param name="gameTime">Provides a snapshot of timing values.</param>
102 protected override void Update(GameTime gameTime)
104 networkGame.Update(gameTime);
106 base.Update(gameTime);
110 /// This is called when the game should draw itself.
112 /// <param name="gameTime">Provides a snapshot of timing values.</param>
113 protected override void Draw(GameTime gameTime)
115 GraphicsDevice.Clear(Color.Red);
118 networkGame.Draw(gameTime, spriteBatch);
120 map.Draw(spriteBatch);