Renamed MouseControl to MouseInput
This commit is contained in:
+119
-119
@@ -1,119 +1,119 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Audio;
|
using Microsoft.Xna.Framework.Audio;
|
||||||
using Microsoft.Xna.Framework.Content;
|
using Microsoft.Xna.Framework.Content;
|
||||||
using Microsoft.Xna.Framework.GamerServices;
|
using Microsoft.Xna.Framework.GamerServices;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using Microsoft.Xna.Framework.Input;
|
using Microsoft.Xna.Framework.Input;
|
||||||
using Microsoft.Xna.Framework.Media;
|
using Microsoft.Xna.Framework.Media;
|
||||||
|
|
||||||
namespace DepthsBelow
|
namespace DepthsBelow
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is the main type for your game
|
/// This is the main type for your game
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Core : Microsoft.Xna.Framework.Game
|
public class Core : Microsoft.Xna.Framework.Game
|
||||||
{
|
{
|
||||||
GraphicsDeviceManager graphics;
|
GraphicsDeviceManager graphics;
|
||||||
SpriteBatch spriteBatch;
|
SpriteBatch spriteBatch;
|
||||||
|
|
||||||
public Camera camera;
|
public Camera camera;
|
||||||
MouseControl mouse;
|
MouseInput mouse;
|
||||||
Soldier soldier;
|
Soldier soldier;
|
||||||
|
|
||||||
public Core()
|
public Core()
|
||||||
{
|
{
|
||||||
graphics = new GraphicsDeviceManager(this);
|
graphics = new GraphicsDeviceManager(this);
|
||||||
Content.RootDirectory = "Content";
|
Content.RootDirectory = "Content";
|
||||||
|
|
||||||
graphics.PreferredBackBufferWidth = 1280;
|
graphics.PreferredBackBufferWidth = 1280;
|
||||||
graphics.PreferredBackBufferHeight = 720;
|
graphics.PreferredBackBufferHeight = 720;
|
||||||
graphics.IsFullScreen = false;
|
graphics.IsFullScreen = false;
|
||||||
|
|
||||||
this.IsMouseVisible = true;
|
this.IsMouseVisible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows the game to perform any initialization it needs to before starting to run.
|
/// 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
|
/// 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
|
/// related content. Calling base.Initialize will enumerate through any components
|
||||||
/// and initialize them as well.
|
/// and initialize them as well.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected override void Initialize()
|
protected override void Initialize()
|
||||||
{
|
{
|
||||||
// TODO: Add your initialization logic here
|
// TODO: Add your initialization logic here
|
||||||
camera = new Camera(this);
|
camera = new Camera(this);
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// LoadContent will be called once per game and is the place to load
|
/// LoadContent will be called once per game and is the place to load
|
||||||
/// all of your content.
|
/// all of your content.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected override void LoadContent()
|
protected override void LoadContent()
|
||||||
{
|
{
|
||||||
// Create a new SpriteBatch, which can be used to draw textures.
|
// Create a new SpriteBatch, which can be used to draw textures.
|
||||||
spriteBatch = new SpriteBatch(GraphicsDevice);
|
spriteBatch = new SpriteBatch(GraphicsDevice);
|
||||||
|
|
||||||
// TODO: use this.Content to load your game content here
|
// TODO: use this.Content to load your game content here
|
||||||
Soldier.LoadContent(this);
|
Soldier.LoadContent(this);
|
||||||
soldier = new Soldier(this);
|
soldier = new Soldier(this);
|
||||||
|
|
||||||
mouse = new MouseControl(this);
|
mouse = new MouseInput(this);
|
||||||
mouse.LoadContent();
|
mouse.LoadContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// UnloadContent will be called once per game and is the place to unload
|
/// UnloadContent will be called once per game and is the place to unload
|
||||||
/// all content.
|
/// all content.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected override void UnloadContent()
|
protected override void UnloadContent()
|
||||||
{
|
{
|
||||||
// TODO: Unload any non ContentManager content here
|
// TODO: Unload any non ContentManager content here
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows the game to run logic such as updating the world,
|
/// Allows the game to run logic such as updating the world,
|
||||||
/// checking for collisions, gathering input, and playing audio.
|
/// checking for collisions, gathering input, and playing audio.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="gameTime">Provides a snapshot of timing values.</param>
|
/// <param name="gameTime">Provides a snapshot of timing values.</param>
|
||||||
protected override void Update(GameTime gameTime)
|
protected override void Update(GameTime gameTime)
|
||||||
{
|
{
|
||||||
// Allows the game to exit
|
// Allows the game to exit
|
||||||
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
|
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
|
||||||
this.Exit();
|
this.Exit();
|
||||||
|
|
||||||
camera.Update(gameTime);
|
camera.Update(gameTime);
|
||||||
mouse.Update(gameTime);
|
mouse.Update(gameTime);
|
||||||
|
|
||||||
// TODO: Add your update logic here
|
// TODO: Add your update logic here
|
||||||
soldier.Update(gameTime);
|
soldier.Update(gameTime);
|
||||||
|
|
||||||
base.Update(gameTime);
|
base.Update(gameTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is called when the game should draw itself.
|
/// This is called when the game should draw itself.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="gameTime">Provides a snapshot of timing values.</param>
|
/// <param name="gameTime">Provides a snapshot of timing values.</param>
|
||||||
protected override void Draw(GameTime gameTime)
|
protected override void Draw(GameTime gameTime)
|
||||||
{
|
{
|
||||||
GraphicsDevice.Clear(Color.CornflowerBlue);
|
GraphicsDevice.Clear(Color.CornflowerBlue);
|
||||||
|
|
||||||
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null, camera.Transform);
|
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null, camera.Transform);
|
||||||
|
|
||||||
// TODO: Foreach etc...
|
// TODO: Foreach etc...
|
||||||
Component.SpriteRenderer rc = soldier.GetComponent<Component.SpriteRenderer>();
|
Component.SpriteRenderer rc = soldier.GetComponent<Component.SpriteRenderer>();
|
||||||
if (rc != null)
|
if (rc != null)
|
||||||
rc.Draw(spriteBatch);
|
rc.Draw(spriteBatch);
|
||||||
|
|
||||||
mouse.Draw(spriteBatch);
|
mouse.Draw(spriteBatch);
|
||||||
|
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
|
|
||||||
base.Draw(gameTime);
|
base.Draw(gameTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,63 +1,63 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Content;
|
using Microsoft.Xna.Framework.Content;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using Microsoft.Xna.Framework.Input;
|
using Microsoft.Xna.Framework.Input;
|
||||||
using Microsoft.Xna.Framework.Media;
|
using Microsoft.Xna.Framework.Media;
|
||||||
|
|
||||||
namespace DepthsBelow
|
namespace DepthsBelow
|
||||||
{
|
{
|
||||||
class MouseControl
|
class MouseInput
|
||||||
{
|
{
|
||||||
Core core;
|
Core core;
|
||||||
MouseState lastMouseState;
|
MouseState lastMouseState;
|
||||||
Rectangle selectionRectangle;
|
Rectangle selectionRectangle;
|
||||||
Texture2D selectionTexture;
|
Texture2D selectionTexture;
|
||||||
|
|
||||||
public MouseControl(Core core)
|
public MouseInput(Core core)
|
||||||
{
|
{
|
||||||
this.core = core;
|
this.core = core;
|
||||||
|
|
||||||
selectionRectangle = Rectangle.Empty;
|
selectionRectangle = Rectangle.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadContent()
|
public void LoadContent()
|
||||||
{
|
{
|
||||||
selectionTexture = new Texture2D(core.GraphicsDevice, 1, 1);
|
selectionTexture = new Texture2D(core.GraphicsDevice, 1, 1);
|
||||||
selectionTexture.SetData(new Color[] { Color.White });
|
selectionTexture.SetData(new Color[] { Color.White });
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update(GameTime gameTime)
|
public void Update(GameTime gameTime)
|
||||||
{
|
{
|
||||||
MouseState ms = Mouse.GetState();
|
MouseState ms = Mouse.GetState();
|
||||||
|
|
||||||
if (ms.LeftButton == ButtonState.Pressed)
|
if (ms.LeftButton == ButtonState.Pressed)
|
||||||
{
|
{
|
||||||
if (selectionRectangle == Rectangle.Empty)
|
if (selectionRectangle == Rectangle.Empty)
|
||||||
{
|
{
|
||||||
selectionRectangle = new Rectangle(ms.X + (int)core.camera.Position.X, ms.Y + (int)core.camera.Position.Y, 0, 0);
|
selectionRectangle = new Rectangle(ms.X + (int)core.camera.Position.X, ms.Y + (int)core.camera.Position.Y, 0, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
selectionRectangle.Width = ms.X - selectionRectangle.X + (int)core.camera.Position.X;
|
selectionRectangle.Width = ms.X - selectionRectangle.X + (int)core.camera.Position.X;
|
||||||
selectionRectangle.Height = ms.Y - selectionRectangle.Y + (int)core.camera.Position.Y;
|
selectionRectangle.Height = ms.Y - selectionRectangle.Y + (int)core.camera.Position.Y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ms.LeftButton == ButtonState.Released && selectionRectangle != Rectangle.Empty)
|
if (ms.LeftButton == ButtonState.Released && selectionRectangle != Rectangle.Empty)
|
||||||
{
|
{
|
||||||
selectionRectangle = Rectangle.Empty;
|
selectionRectangle = Rectangle.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
lastMouseState = ms;
|
lastMouseState = ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Draw(SpriteBatch spriteBatch)
|
public void Draw(SpriteBatch spriteBatch)
|
||||||
{
|
{
|
||||||
spriteBatch.Draw(selectionTexture, selectionRectangle, Color.Red * 0.5f);
|
spriteBatch.Draw(selectionTexture, selectionRectangle, Color.Red * 0.5f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user