//---------------------------------------------------------------------------------------------------------------------------------------------------
//
// Copyright (C)2007 DW Studios. All rights reserved.
//
//---------------------------------------------------------------------------------------------------------------------------------------------------
// {License Information: Creative Commons}
//------------------------------------------------------------a---------------------------------------------------------------------------------------
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.UI;
using DW.Stream;
using System.Diagnostics;
using DW.Globals;
using DW.Data.GameObjects;
using DarkWynter.Engine.Controllers;
using DWControllerDemo;
using DW.Menus;
using DW.Data;
using DW.Data.World;
///
/// Scope of all game code, Entry point of application
///
namespace DW
{
///
/// Main entry point for the scaffolding code
///
public class AISample :Microsoft.Xna.Framework.Game
{
public Stopwatch gameTimer = new Stopwatch();
bool gameTimeStarted = false;
ObjectLibrary objLib;
Renderer renderer;
WorldMap world;
///
/// Main game constructor
///
public AISample()
{
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()
{
// Set to Game_Mode to start the game, Menu_Mode to start with the menu system
Statics.engineState = Enums.EngineState.MENU_MODE;
///
/// 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.ViewMode.SINGLE_SCREEN;
#region Controller Init
// Create a List of Child Controllers
// Pass in Width and Height used by mouse.
List controllerTypes = new List();
controllerTypes.Add(typeof(MenuController));
controllerTypes.Add(typeof(GameController));
Statics.controllerManager = new ControllerManager(800,600, controllerTypes);
#endregion
// Initialize Renderer:
renderer = new Renderer();
// Tidy up..
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();
// Load All Players and GameObjects
objLib = new ObjectLibrary();
world = new WorldMap();
world.LoadMap("_map/king.txt");
world.AddTileset(@"_map\spriteSheet", 48, 48, 0, 0);
objLib.LoadContent();
int numPlayers = 1;
renderer.Load(numPlayers);
}
///
/// 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)
{
// Checks if any controllers have been Added or Removed
Statics.controllerManager.Update();
// Menu Control Update
if (Statics.engineState == Enums.EngineState.MENU_MODE)
{
#region MenuController Update
// Get Controller and Update required controllers
// controller.Update(args) can be any List you want to pass to the controller during key-fire events
List menuController = Statics.controllerManager.GetControllers(typeof(MenuController));
for (int i = 0; i < menuController.Count; i++)
menuController[i].Update(Renderer.menuSystem);
#endregion
}
// Game Control Update
if (Statics.engineState == Enums.EngineState.GAME_MODE)
{
#region GameController Update
// Get Controller (check overloads for alt access params)
// controller.Update(args) can be any List you want to pass to the controller during key-fire events
List gameController = Statics.controllerManager.GetControllers(typeof(GameController));
for (int i = 0; i < gameController.Count; i++)
gameController[i].Update(objLib);
#endregion
}
// First Update Switch
if (Statics.engineState == Enums.EngineState.GAME_MODE)
{
#region First Update() Switch
if (!gameTimeStarted)
{
// Start a game timer
gameTimeStarted = true;
gameTimer.Start();
// Collect Menu Options
List args = Renderer.menuSystem.GetProperties();
// .. Or, get a specific Menu Option
string value = Renderer.menuSystem.GetProperty("Game type");
}
#endregion
}
// Object Update
if (Statics.engineState == Enums.EngineState.GAME_MODE)
{
objLib.Update(gameTime);
}
// Allow Renderer to update math (if any)
renderer.Update(gameTimer, gameTime);
// Play nice with microsoft..
base.Update(gameTime);
}
///
/// This is called when the game should draw itself.
///
/// Provides a snapshot of timing values.
protected override void Draw(GameTime gameTime)
{
// Draw Everything
if (Statics.engineState == Enums.EngineState.MENU_MODE)
{
renderer.DrawMenus(gameTime);
}
if (Statics.engineState == Enums.EngineState.GAME_MODE)
{
renderer.DrawGame(gameTime, objLib);
}
// MuST.. Pl@y nice.. w/m1cr0soft !!!-/
base.Draw(gameTime);
}
// Top level window resizing trace
void Window_ClientSizeChanged(object sender, EventArgs e)
{
// Respond
renderer.Resize(Window.ClientBounds);
}
}
}