mirror of
https://github.com/TheRavenwoodArts/LunaLightXMG.git
synced 2026-07-30 23:35:02 -07:00
145 lines
5.1 KiB
C#
145 lines
5.1 KiB
C#
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using Microsoft.Xna.Framework.Input;
|
|
using System;
|
|
|
|
namespace LunaLightXMG
|
|
{
|
|
public class Game1 : Game
|
|
{
|
|
private GraphicsDeviceManager graphics;
|
|
private SpriteBatch spriteBatch;
|
|
|
|
// Test Render Target
|
|
private RenderTarget2D renderTarget;
|
|
private Rectangle renderDestination;
|
|
bool resizing;
|
|
|
|
// Test sprites
|
|
Texture2D sprRo;
|
|
Texture2D sprCave1_background;
|
|
Texture2D sprCave1_foreground;
|
|
Texture2D sprCave1_walls;
|
|
|
|
// Test player input and movement with abstracted player input class
|
|
private PlayerInput playerInput;
|
|
private Vector2 objectPosition;
|
|
private float movementSpeed = 100f; // Movement speed in pixels per second
|
|
|
|
// Native retro scale
|
|
private int retroWidth = 320;
|
|
private int retroHeight = 180;
|
|
|
|
public Game1()
|
|
{
|
|
graphics = new GraphicsDeviceManager(this);
|
|
Content.RootDirectory = "Content";
|
|
IsMouseVisible = true;
|
|
|
|
Window.ClientSizeChanged += OnClientSizeChanged;
|
|
Window.AllowUserResizing = true;
|
|
IsMouseVisible = true;
|
|
|
|
// Test player input and movement with abstracted player input class
|
|
playerInput = new PlayerInput();
|
|
}
|
|
|
|
private void OnClientSizeChanged(object sender, EventArgs eventArgs)
|
|
{
|
|
if (!resizing && Window.ClientBounds.Width > 0 && Window.ClientBounds.Height > 0)
|
|
{
|
|
resizing = true;
|
|
CalculateRenderDestination();
|
|
resizing = false;
|
|
}
|
|
}
|
|
|
|
protected override void Initialize()
|
|
{
|
|
// Set initial window size
|
|
graphics.PreferredBackBufferWidth = 1920;
|
|
graphics.PreferredBackBufferHeight = 1080;
|
|
graphics.ApplyChanges();
|
|
|
|
// Test player input and movement with abstracted player input class
|
|
objectPosition = new Vector2(163, 63); // Initial position
|
|
|
|
base.Initialize();
|
|
CalculateRenderDestination(); // Jensen can implement
|
|
}
|
|
|
|
private void CalculateRenderDestination()
|
|
{
|
|
Point size = GraphicsDevice.Viewport.Bounds.Size;
|
|
|
|
float scaleX = (float)size.X / renderTarget.Width;
|
|
float scaleY = (float)size.Y / renderTarget.Height;
|
|
float scale = Math.Min(scaleX, scaleY);
|
|
|
|
renderDestination.Width = (int)(renderTarget.Width * scale);
|
|
renderDestination.Height = (int)(renderTarget.Height * scale);
|
|
|
|
renderDestination.X = (size.X - renderDestination.Width) / 2;
|
|
renderDestination.Y = (size.Y - renderDestination.Height) / 2;
|
|
}
|
|
protected override void LoadContent()
|
|
{
|
|
spriteBatch = new SpriteBatch(GraphicsDevice);
|
|
sprRo = Content.Load<Texture2D>("sprRo_Wall");
|
|
sprCave1_background = Content.Load<Texture2D>("spr_cave1_background");
|
|
sprCave1_foreground = Content.Load<Texture2D>("spr_Cave1_foreground");
|
|
sprCave1_walls = Content.Load<Texture2D>("spr_Cave1_walls");
|
|
|
|
// Test Render Target
|
|
renderTarget = new RenderTarget2D(GraphicsDevice, retroWidth, retroHeight);
|
|
}
|
|
|
|
protected override void Update(GameTime gameTime)
|
|
{
|
|
// Temporary quit game - eventually handle in a pause menu class
|
|
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
|
|
Exit();
|
|
|
|
playerInput.Update();
|
|
|
|
// Test player input and movement with abstracted player input class
|
|
// Update the object's position based on input
|
|
float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;
|
|
objectPosition = playerInput.MoveWithWASD(objectPosition, movementSpeed * deltaTime);
|
|
|
|
|
|
|
|
base.Update(gameTime);
|
|
}
|
|
|
|
protected override void Draw(GameTime gameTime)
|
|
{
|
|
GraphicsDevice.Clear(Color.CornflowerBlue);
|
|
|
|
// Test Render Target - Draw sprites to the render target
|
|
GraphicsDevice.SetRenderTarget(renderTarget);
|
|
|
|
// Test Sprite
|
|
spriteBatch.Begin(samplerState: SamplerState.PointClamp);
|
|
// Draw sprites here
|
|
spriteBatch.Draw(sprCave1_background,new Vector2(0,0),Color.White);
|
|
|
|
// Test player input and movement with abstracted player input class
|
|
spriteBatch.Draw(sprRo, objectPosition, Color.White);
|
|
|
|
spriteBatch.Draw(sprCave1_walls, new Vector2(0, 0), Color.White);
|
|
spriteBatch.Draw(sprCave1_foreground, new Vector2(0, 0), Color.White);
|
|
spriteBatch.End();
|
|
|
|
|
|
// Test Render Target - Draw render target to the screen
|
|
GraphicsDevice.SetRenderTarget(null);
|
|
spriteBatch.Begin(samplerState: SamplerState.PointClamp);
|
|
spriteBatch.Draw(renderTarget, renderDestination, Color.White);
|
|
spriteBatch.End();
|
|
|
|
base.Draw(gameTime);
|
|
}
|
|
}
|
|
}
|