using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using RecrownedAthenaeum.Camera;
using RecrownedAthenaeum.Render;
using System;
namespace CameraTest
{
///
/// This is the main type for your game.
///
public class CameraTest : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
PrimitiveBatch pb;
Camera2D camera;
RectangleRenderer rr;
BasicEffect be;
public CameraTest()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
///
/// 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()
{
// TODO: Add your initialization logic here
base.Initialize();
}
///
/// LoadContent will be called once per game and is the place to load
/// all of your content.
///
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
camera = new Camera2D(graphics.GraphicsDevice);
spriteBatch = new SpriteBatch(GraphicsDevice);
rr = new RectangleRenderer(camera, GraphicsDevice);
pb = new PrimitiveBatch(camera, GraphicsDevice);
be = new BasicEffect(GraphicsDevice);
be.World = camera.worldMatrix;
be.View = camera.ViewMatrix;
be.Projection = camera.projectionMatrix;
// TODO: use this.Content to load your game content here
}
///
/// UnloadContent will be called once per game and is the place to unload
/// game-specific content.
///
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
rr.Dispose();
}
///
/// 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 (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
if (Keyboard.GetState().IsKeyDown(Keys.Left))
{
Console.WriteLine("moving..");
camera.MoveCamera(new Vector2(-5, 0));
}
if (Keyboard.GetState().IsKeyDown(Keys.Right))
{
Console.WriteLine("moving..");
camera.MoveCamera(new Vector2(5, 0));
}
if (Keyboard.GetState().IsKeyDown(Keys.Up))
{
Console.WriteLine("moving..");
camera.MoveCamera(new Vector2(0, 5));
}
if (Keyboard.GetState().IsKeyDown(Keys.Down))
{
Console.WriteLine("moving..");
camera.MoveCamera(new Vector2(0, -5));
}
camera.Apply();
base.Update(gameTime);
}
float angleDeg = 0;
///
/// This is called when the game should draw itself.
///
/// Provides a snapshot of timing values.
protected override void Draw(GameTime gameTime)
{
angleDeg++;
if (angleDeg > 360) angleDeg = 0;
GraphicsDevice.Clear(Color.Black);
rr.Begin(true);
rr.Draw(25, 25, 70, 70, Color.Purple);
rr.End();
rr.Begin(false);
rr.Draw(75, 75, 70, 70, Color.Green, MathHelper.ToRadians(angleDeg));
rr.End();
base.Draw(gameTime);
}
}
}