//--------------------------------------------------------------------------------------------------------------------------------------------------- // // Copyright (C)2007 DarkWynter Studios. All rights reserved. // //--------------------------------------------------------------------------------------------------------------------------------------------------- // {License Information: Creative Commons} //--------------------------------------------------------------------------------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; using Microsoft.Xna.Framework.Net; using Microsoft.Xna.Framework.Storage; using DW.UserInterface_2D; using DW.Stream; using DWGame.Globals; using DarkWynter.Engine.Controllers; using DWControllerDemo; using System.Diagnostics; namespace DWGame { /// /// Main entry point for the scaffolding code /// public class PhoenixGame :Microsoft.Xna.Framework.Game { public static Stopwatch gameTimer = new Stopwatch(); bool gameTimeStarted = false; /// /// Main game constructor /// public PhoenixGame() { Statics._self = this; Renderer.graphics = new GraphicsDeviceManager(this); Renderer.content = new ContentManager(Services); Renderer.content.RootDirectory = "Content"; Renderer.graphics.IsFullScreen = false; if (Renderer.Dimensions.RESIZABLE) { // Subscribe to the game window's ClientSizeChanged event. Window.AllowUserResizing = true; Window.ClientSizeChanged += new EventHandler(Window_ClientSizeChanged); } } /// /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// protected override void Initialize() { Renderer.Initialize(); // Set to Game_Mode to start the game, Menu_Mode to start with the menu system Statics.engineState = Enums_Engine.EngineState.GAME_MODE; Statics.playerState = Enums_Engine.PlayerState.ALIVE; /// /// Used to set the type of game you are making, choices are single screen and split screen /// If splitscreen, can have up to 4 splits - huds are also split /// Statics.viewMode = Enums_Engine.ViewMode.SINGLE_SCREEN; // Create a List of Child Controllers List controllerTypes = new List(); controllerTypes.Add(typeof(MenuController)); controllerTypes.Add(typeof(GameController)); // Pass in Width and Height used by mouse. Statics.ControllerSettings.controllerManager = new ControllerManager(800,600, controllerTypes); // Pass “this” as EventArgs to Conroller delegates functions Statics.ControllerSettings.args.Add(this); base.Initialize(); } /// /// LoadContent will be called once per game and is the place to load /// all of your content. /// protected override void LoadContent() { base.LoadContent(); Renderer.Load(); Renderer.window.addPane(); Renderer.window.addPane(); Renderer.window.addPane(); } /// /// UnloadContent will be called once per game and is the place to unload /// all content. /// protected override void UnloadContent() { base.UnloadContent(); Renderer.Unload(); } /// /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// /// Provides a snapshot of timing values. protected override void Update(GameTime gameTime) { if (Statics.engineState == Enums_Engine.EngineState.MENU_MODE) { // Update all MenuControllers Statics.ControllerSettings.menuController = Statics.ControllerSettings.controllerManager.GetControllers(typeof(MenuController)); for (int i = 0; i < Statics.ControllerSettings.menuController.Count; i++) { Statics.ControllerSettings.menuController[i].Update(ref Statics.ControllerSettings.args); } } if (Statics.engineState == Enums_Engine.EngineState.GAME_MODE) { if (!gameTimeStarted) { gameTimer.Start(); gameTimeStarted = true; } Statics.ControllerSettings.gameController = Statics.ControllerSettings.controllerManager.GetControllers(typeof(GameController)); for (int i = 0; i < Statics.ControllerSettings.gameController.Count; i++) { Statics.ControllerSettings.gameController[i].Update(ref Statics.ControllerSettings.args); } } // Checks if any controllers Added or Removed Statics.ControllerSettings.controllerManager.Update(); // Allow Renderer to update math (if any) Renderer.Update(gameTimer, gameTime); base.Update(gameTime); } /// /// This is called when the game should draw itself. /// /// Provides a snapshot of timing values. protected override void Draw(GameTime gameTime) { if (Statics.engineState == Enums_Engine.EngineState.MENU_MODE) { } if (Statics.engineState == Enums_Engine.EngineState.GAME_MODE) { } // Draw Everything Renderer.Draw(gameTime); // Clean up base.Draw(gameTime); } // Top level window resizing trace void Window_ClientSizeChanged(object sender, EventArgs e) { // Respond Renderer.Resize(Window.ClientBounds); } } }