//--------------------------------------------------------------------------------------------------------------------------------------------------- // // Copyright (C)2007 DarkWynter Studios. All rights reserved. // //--------------------------------------------------------------------------------------------------------------------------------------------------- // {Contact : darkwynter.com for licensing information //--------------------------------------------------------------------------------------------------------------------------------------------------- using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Content; using System.Diagnostics; using DWGame.Player; namespace DW.Stream { // Renderer is a sub-system static structure that drives all graphics-card related functions // This library is specifically split from the engine so it can be swapped out on alt. platforms (eg- DirectX, OpenGL, Mobile) // If designed correctly, a single game then only needs to "re-skin" with a different rendering system to port platforms. // In more advanced systems, this class holds draw-order dependency and shader-related information as well. public static class Renderer { /// /// Global Window Settings /// public struct Dimensions { public static bool RESIZABLE = false; public static Rectangle CLIENTBOUNDS = new Rectangle(0,0,800,600); } /// /// Global Font Struct /// public struct SystemFonts { public static SpriteFont Arial; public static SpriteFont ComicSans; public static SpriteFont ComicSansSmall; } /// /// Variables /// public static Window window; public static SpriteBatch spriteBatch; public static GraphicsDeviceManager graphics; public static ContentManager content; public static Viewport view; public static Human human; public static Background background; public static Collision colDect; public static AI enemies; /// /// Setup /// public static void Initialize() { Renderer.view = graphics.GraphicsDevice.Viewport; Renderer.spriteBatch = new SpriteBatch(graphics.GraphicsDevice); } /// /// Load the new Window /// public static void Load() { Renderer.window = new Window(); window.Load("_xml/GameConfiguration.xml"); SystemFonts.Arial = content.Load("_fonts/Arial"); Renderer.human = new Human(); Renderer.background = new Background(); Renderer.colDect = new Collision(); Renderer.enemies = new AI(); } /// /// Drop all content /// public static void Unload() { } /// /// Mathematical formula for splitting the screen /// /// Number of players /// List of Rectangles holding the viewports for each pane public static List GetRectangles(int frameCount) { List rects = new List(); switch (frameCount) { case 1: rects.Add(new Rectangle(0, 0, view.Width, view.Height)); break; case 2: // 2 players split vertically rects.Add(new Rectangle(0, 0, view.Width / 2, view.Height)); rects.Add(new Rectangle(view.Width / 2, 0, view.Width / 2, view.Height)); break; case 3: // 3 player split rects.Add(new Rectangle(0, 0, view.Width / 2, view.Height / 2)); rects.Add(new Rectangle(view.Width / 2, 0, view.Width / 2, view.Height / 2)); rects.Add(new Rectangle(0, view.Height / 2, view.Width / 2, view.Height / 2)); break; case 4: // 4 players rects.Add(new Rectangle(0, 0, view.Width / 2, view.Height / 2)); rects.Add(new Rectangle(view.Width / 2, 0, view.Width / 2, view.Height / 2)); rects.Add(new Rectangle(0, view.Height / 2, view.Width / 2, view.Height / 2)); rects.Add(new Rectangle(view.Width / 2, view.Height / 2, view.Width / 2, view.Height / 2)); break; default: break; } return rects; } /// /// Resize the windows and down into the panes /// /// Bounding on the game window public static void Resize(Rectangle clientBounds) { window.Resize(clientBounds); } /// /// Game Loop /// /// Passed down from engine, controls the HUD timer /// Provides a snapshot of timing values public static void Update(Stopwatch gameTimer, GameTime gametime) { Human.Update(gameTimer, gametime); Background.Update(); AI.Update(Background.getCounter()); Collision.Update(); window.Update(gameTimer, gametime); } /// /// Main Draw portion of the game, all objects should draw themselves, /// Renderer just controls when it happens /// /// Provides a snapshot of timing values public static void Draw(GameTime gametime) { graphics.GraphicsDevice.Clear(Color.White); Renderer.spriteBatch.Begin(); Background.Draw(); Human.Draw(); AI.Draw(); window.Draw(view); Renderer.spriteBatch.End(); } } }