Files
slatedgtk/src/SlatedGameToolkit.Tools/Utilities/Playground/MainState.cs

100 lines
3.1 KiB
C#

using System;
using System.Drawing;
using System.Numerics;
using SDL2;
using SlatedGameToolkit.Commons.Loaders;
using SlatedGameToolkit.Framework.Graphics.Render;
using SlatedGameToolkit.Framework.Graphics.Textures;
using SlatedGameToolkit.Framework.Graphics.Window;
using SlatedGameToolkit.Framework.Input.Devices;
using SlatedGameToolkit.Framework.StateSystem;
using SlatedGameToolkit.Framework.StateSystem.States;
namespace SlatedGameToolkit.Tools.Utilities.Playground
{
public class MainState : IState
{
private WindowContext window;
private Camera2D camera;
private MeshBatch renderer;
private Texture logoTexture, fillerTexture;
private RectangleMesh logo, textureTester, untextured;
public WindowContext CurrentWindow { get { return window;}}
public bool Activate()
{
return true;
}
public bool Deactivate()
{
return true;
}
public void Deinitialize()
{
logoTexture.Dispose();
fillerTexture.Dispose();
renderer.Dispose();
window.Dispose();
}
public string getName()
{
return "main state";
}
public void Initialize(StateManager manager)
{
window = new WindowContext("SlatedGameToolkit Playground");
camera = new Camera2D(2, 2);
renderer = new MeshBatch(camera);
logoTexture = TextureLoader.LoadTexture("Resources/Playground/yhdnbgnc.png", null);
logo = new RectangleMesh(logoTexture, Color.White);
logo.Width = 0.5f;
logo.Height = 0.5f;
logo.X = -0.25f;
logo.Y = -0.25f;
fillerTexture = TextureLoader.LoadTexture("Resources/Playground/filler.png", null);
textureTester = new RectangleMesh(fillerTexture, Color.White);
textureTester.Width = 0.15f;
textureTester.Height = 0.15f;
textureTester.X = 0.25f;
untextured = new RectangleMesh(null, Color.Red);
untextured.Width = 0.15f;
untextured.Height = 0.1f;
untextured.X = 0.25f;
untextured.Y = - 0.15f;
}
public void Render(double delta)
{
renderer.Begin(Matrix4x4.Identity, delta);
renderer.Draw(logo);
renderer.Draw(textureTester);
renderer.Draw(untextured);
renderer.End();
}
public void Update(double timeStep)
{
if (Keyboard.IsKeyPressed(SDL.SDL_Keycode.SDLK_DOWN)) {
camera.MoveTo += new Vector2(0, (-0.25f)) * (float) timeStep;
}
if (Keyboard.IsKeyPressed(SDL.SDL_Keycode.SDLK_UP)) {
camera.MoveTo += new Vector2(0, (0.25f)) * (float) timeStep;
}
if (Keyboard.IsKeyPressed(SDL.SDL_Keycode.SDLK_LEFT)) {
camera.MoveTo += new Vector2((-0.25f) * (float) timeStep, 0);
}
if (Keyboard.IsKeyPressed(SDL.SDL_Keycode.SDLK_RIGHT)) {
camera.MoveTo += new Vector2((0.25f) * (float) timeStep, 0);
}
}
}
}