1. Michael Gough
  2. HI-2DRTSSGMDDPP1

Source

HI-2DRTSSGMDDPP1 / GameProgram / GameProgram / Game1.cs

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 Innovation;

namespace GameProgram
{
  
  /// <summary>
  /// This is the main type for your game
  /// </summary>
  public class Game1 : Microsoft.Xna.Framework.Game
  {
    GraphicsDeviceManager graphics;
    MouseDevice mouse;
    SpriteBatch spriteBatch;

    public static readonly Random randomNumber = new Random();
    
    private World world;
    private GraphicsScene graphicsScene;

    //// This is a texture we can render.
    //Texture2D myTexture;

    //// Set the coordinates to draw the sprite at.
    //Vector2 spritePosition = Vector2.Zero;

    //// Store some information about the sprite's motion.
    //Vector2 spriteSpeed = new Vector2( 50.0f, 50.0f );

    public Game1()
    {
      graphics = new GraphicsDeviceManager( this );      
      Content.RootDirectory = "Content";

      graphics.PreferredBackBufferWidth = 1024;
      graphics.PreferredBackBufferWidth = 800;
      graphics.ApplyChanges();
      //graphics.IsFullScreen = true;

      this.Window.AllowUserResizing = true;
      this.IsMouseVisible           = true;

      mouse = new MouseDevice( graphics );
    }

    /// <summary>
    /// 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.
    /// </summary>
    protected override void Initialize()
    {
      // TODO: Add your initialization logic here

      WorldFactory worldFactory = new WorldFactory();
      GraphicsSceneFactory graphicsSceneFactory = new GraphicsSceneFactory();
    
      world         = worldFactory.createWorld();
      graphicsScene = graphicsSceneFactory.createGraphicsScene( spriteBatch, world.getVisableGameEntities() );
      
      base.Initialize();
    }

    /// <summary>
    /// LoadContent will be called once per game and is the place to load
    /// all of your content.
    /// </summary>
    protected override void LoadContent()
    {
      // Create a new SpriteBatch, which can be used to draw textures.
      spriteBatch = new SpriteBatch( GraphicsDevice );
      
      // TODO: use this.Content to load your game content here
      graphicsScene.loadContent( this );
      //myTexture = Content.Load<Texture2D>( "WhiteCircle" );
    }

    /// <summary>
    /// UnloadContent will be called once per game and is the place to unload
    /// all content.
    /// </summary>
    protected override void UnloadContent()
    {
      // TODO: Unload any non ContentManager content here
    }

    /// <summary>
    /// Allows the game to run logic such as updating the world,
    /// checking for collisions, gathering input, and playing audio.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Update( GameTime gameTime )
    {
      // Allows the game to exit
      if (GamePad.GetState( PlayerIndex.One ).Buttons.Back == ButtonState.Pressed)
        this.Exit();

      world.update( gameTime );

      mouse.Update();

      graphicsScene.setZoomFactor( ( mouse.ScrollPosition / 10000.0F ) + 0.5F );

      if( mouse.WasButtonHeld( MouseButtons.Left ) )
      {
        graphicsScene.setCameraOffset( mouse.Delta );
      }

      //graphicsScene.setZoomFactor( ( Mouse.GetState().ScrollWheelValue / 10000.0F) + 0.5F );

      //// TODO: Add your update logic here
      //// Move the sprite by speed, scaled by elapsed time.
      //spritePosition +=
      //    spriteSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;

      //int MaxX =
      //    graphics.GraphicsDevice.Viewport.Width - myTexture.Width;
      //int MinX = 0;
      //int MaxY =
      //    graphics.GraphicsDevice.Viewport.Height - myTexture.Height;
      //int MinY = 0;

      //// Check for bounce.
      //if (spritePosition.X > MaxX)
      //{
      //  spriteSpeed.X *= -1;
      //  spritePosition.X = MaxX;
      //}

      //else if (spritePosition.X < MinX)
      //{
      //  spriteSpeed.X *= -1;
      //  spritePosition.X = MinX;
      //}

      //if (spritePosition.Y > MaxY)
      //{
      //  spriteSpeed.Y *= -1;
      //  spritePosition.Y = MaxY;
      //}

      //else if (spritePosition.Y < MinY)
      //{
      //  spriteSpeed.Y *= -1;
      //  spritePosition.Y = MinY;
      //}

      base.Update( gameTime );
    }

    /// <summary>
    /// This is called when the game should draw itself.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Draw( GameTime gameTime )
    {
      GraphicsDevice.Clear( Color.Black );

      // TODO: Add your drawing code here
      spriteBatch.Begin( SpriteSortMode.BackToFront, BlendState.AlphaBlend );
      
      graphicsScene.draw( spriteBatch );
      //spriteBatch.Draw( myTexture, spritePosition, Color.White );
      spriteBatch.End();

      base.Draw( gameTime );
    }

  }
}