//--------------------------------------------------------------------------------------------------------------------------------------------------- // // Copyright (C)2007 DarkWynter Studios. All rights reserved. // //--------------------------------------------------------------------------------------------------------------------------------------------------- // {Contact : darkwynter.com for licensing information //--------------------------------------------------------------------------------------------------------------------------------------------------- namespace ElementalGame { #region Using Statements using System; using System.Collections.Generic; using System.Diagnostics; using System.Text; using System.Threading; using System.Net; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Storage; using System.Xml; #endregion using DarkWynterEngine; using DarkWynterEngine.Globals; using DarkWynterEngine.Menus; using DarkWynterEngine.Utilities; using RuleBook; // GameRules (move to engine) using Menus; using GameObjects; // User Defined Types //using Networking; //using WindowsGame2; using CSTextEditor; using System.Windows.Forms; using System.Collections; /// /// Base class for creating a game using the DarkWynter Engine. /// DarkWynterEngine extends object modification to the user through XML. /// DakrWynterEngine extends functionality to the user through overridable objects. /// public class ElementalGame : DarkWynterGame { #region Properties /// /// Manage scoring, respawn, and gameover /// private GameRules gameRules; //-- COMPILER Panel drawSurface; MainForm compilerForm; Form gameForm; /// /// Simple Network Client /// //private Client chatClient; #endregion #region Methods // --------------- Constructor ----------------- /// /// Main Engine Class. /// Check for Hardware Capabilities. /// Create GraphicsDeviceManager and ContentManager. /// public ElementalGame():base() { //-- COMPILER drawSurface = new Panel(); gameForm = Form.FromHandle(this.Window.Handle).FindForm(); //gameForm.IsMdiContainer = true; compilerForm = new MainForm(); //compilerForm.MdiParent = gameForm; Statics.SystemSettings.graphics.PreparingDeviceSettings += OnPreparingDeviceSettings; } /// /// Set Form Draw Surface to Window Handle /// /// /// private void OnPreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs args) { args.GraphicsDeviceInformation.PresentationParameters.DeviceWindowHandle = drawSurface.Handle; } // ----------------- Load ---------------------- /// /// Set Up Display Window. /// Create Logging, XML, GameFlow, Renderer, SpriteBatch, /// FontWriter, MenuSystem, Audio, ShaderParameters, ChatClient, /// Frames Per Second Counter, and Screensaver /// protected override void Initialize() { base.Initialize(new UserDefinedTypes()); // Menu System menuSystem = new GameMenuSystem(); // Set up the Game Rules gameRules = new GameRules(); //-- COMPILER drawSurface.Width = Statics.RenderSettings.clientWidth; drawSurface.Height = Statics.RenderSettings.clientHeight; drawSurface.Dock = DockStyle.Top; //compilerForm.StartPosition = FormStartPosition.Manual; //compilerForm.Location= new System.Drawing.Point(0, 650); //compilerForm.Width = Statics.RenderSettings.clientWidth; //compilerForm.Height = Statics.RenderSettings.clientHeight - 650; compilerForm.Dock = DockStyle.Bottom; compilerForm.MinimizeBox = false; compilerForm.MaximizeBox = false; compilerForm.TopLevel = false; compilerForm.FormBorderStyle = FormBorderStyle.None; compilerForm.Show(); //compilerForm.BackColor = System.Drawing.Color.Black; //compilerForm.TransparencyKey = System.Drawing.Color.Black; //this.Window.AllowUserResizing = true; gameForm.Text = "Elemental - DarkWynterEngine Demo from www.darkwynter.com"; gameForm.MinimizeBox = true; gameForm.MaximizeBox = true; gameForm.FormBorderStyle = FormBorderStyle.Fixed3D; gameForm.Controls.Add(drawSurface); gameForm.Controls.Add(compilerForm); this.IsMouseVisible = false; //-- COMPILER //chatClient = new Client(); //chatClient.OpenConnection("amanda", 7777); } // --------------- Update --------------------- /// /// Update MenuSystemGame, Audio, FPS. /// Check For Level Loading Request. /// Check For Exit. /// /// XNA GameTime protected override void Update(GameTime gameTime) { // Update current section of Game Pipeline if (Statics.SystemSettings.gameState == Enums.EngineState.GAME_MODE && Statics.SystemSettings.enableCompilerConsole == false) { // Update GameRules gameRules.Update(ref objectLibrary); } // Compiler if (Statics.SystemSettings.enableCompilerConsole) { drawSurface.Height = Statics.RenderSettings.clientHeight / 2; compilerForm.Height = Statics.RenderSettings.clientHeight / 2; compilerForm.Show(); Statics.SystemSettings.WINDOW_IN_FOCUS = false; } else { drawSurface.Height = Statics.RenderSettings.clientHeight; compilerForm.Hide(); Statics.SystemSettings.WINDOW_IN_FOCUS = true; } // Check for user exit request CheckExit(); //chatClient.Write("Client 1 chat message"); //string s = chatClient.Read(); base.Update(gameTime); } // ----------------- Draw ---------------------- /// /// Draw Game or MenuSystem Screen /// /// XNA GameTime protected override void Draw(GameTime gameTime) { base.Draw(gameTime); renderer.DisableSpriteBatches(); } // ---------------- Exit ----------------------- /// /// Reset the Graphics Device Settings after using SpriteBatch. /// Use this function if you are experiencing weird effects after using SpriteBatch. /// /// /// Check to see if user has requested to exit the application. /// protected override void CheckExit() { base.CheckExit(); } #endregion #region Utilities /// /// Clean up all files before exiting. /// protected override void UnloadContent() { base.UnloadContent(); } /// /// Override XNA function. /// Deactivate Mouse when window looses focus. /// /// /// protected override void OnDeactivated(object sender, EventArgs args) { // Set flag to disable controllers when window looses focus base.OnDeactivated(sender, args); } /// /// Override XNA function /// Activate Mouse when window gains focus. /// /// /// protected override void OnActivated(object sender, EventArgs args) { // Set flag to enable controllers when window gains focus base.OnActivated(sender, args); } #endregion } }