2020-07-11 19:02:52 +00:00
|
|
|
using System;
|
|
|
|
using System.Drawing;
|
|
|
|
using System.Numerics;
|
|
|
|
using SDL2;
|
|
|
|
using SlatedGameToolkit.Framework.AssetSystem;
|
|
|
|
using SlatedGameToolkit.Framework.Graphics;
|
|
|
|
using SlatedGameToolkit.Framework.Graphics.Render;
|
|
|
|
using SlatedGameToolkit.Framework.Graphics.Text;
|
|
|
|
using SlatedGameToolkit.Framework.Graphics.Textures;
|
|
|
|
using SlatedGameToolkit.Framework.Graphics.Window;
|
|
|
|
using SlatedGameToolkit.Framework.Input.Devices;
|
|
|
|
using SlatedGameToolkit.Framework.Loaders;
|
|
|
|
using SlatedGameToolkit.Framework.StateSystem;
|
|
|
|
using SlatedGameToolkit.Framework.StateSystem.States;
|
|
|
|
|
2020-07-12 04:19:50 +00:00
|
|
|
namespace SkinnerBox.States
|
2020-07-11 19:02:52 +00:00
|
|
|
{
|
|
|
|
public class MenuState : IState
|
|
|
|
{
|
|
|
|
private StateManager manager;
|
|
|
|
WindowContext context;
|
|
|
|
AssetManager assets;
|
|
|
|
Camera2D camera;
|
|
|
|
MeshBatchRenderer renderer;
|
2020-07-12 17:45:12 +00:00
|
|
|
BitmapFont titleFont;
|
2020-07-11 19:02:52 +00:00
|
|
|
RectangleMesh serverUnit;
|
2020-07-12 17:26:36 +00:00
|
|
|
private BitmapFont genericFont;
|
|
|
|
|
2020-07-11 19:02:52 +00:00
|
|
|
public bool Activate()
|
|
|
|
{
|
|
|
|
Keyboard.keyboardUpdateEvent += KeyInput;
|
2020-07-12 04:19:50 +00:00
|
|
|
this.titleFont.PixelHeight = 120;
|
2020-07-12 17:45:12 +00:00
|
|
|
this.titleFont.PrepareCharacterGroup("Website Simulator".ToCharArray());
|
2020-07-12 04:19:50 +00:00
|
|
|
this.titleFont.PixelHeight = 40;
|
2020-07-12 17:45:12 +00:00
|
|
|
this.titleFont.PrepareCharacterGroup("How it feels to be on the other end...".ToCharArray());
|
|
|
|
this.titleFont.PrepareCharacterGroup("Press space to start...".ToCharArray());
|
2020-07-11 19:02:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool Deactivate()
|
|
|
|
{
|
|
|
|
Keyboard.keyboardUpdateEvent -= KeyInput;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Deinitialize()
|
|
|
|
{
|
2020-07-12 17:26:36 +00:00
|
|
|
titleFont.Dispose();
|
|
|
|
genericFont.Dispose();
|
2020-07-11 19:02:52 +00:00
|
|
|
this.renderer.Dispose();
|
|
|
|
this.assets.UnloadAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
public string getName()
|
|
|
|
{
|
|
|
|
return "Main";
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Initialize(StateManager manager)
|
|
|
|
{
|
|
|
|
this.manager = manager;
|
2020-07-12 17:45:12 +00:00
|
|
|
this.manager.backgroundColour = Color.LightGray;
|
|
|
|
this.context = new WindowContext("Website Simulator", width: 640, height: 640, options: SDL.SDL_WindowFlags.SDL_WINDOW_HIDDEN);
|
2020-07-11 19:02:52 +00:00
|
|
|
this.assets = new AssetManager();
|
|
|
|
this.assets.DefaultPathModifier = (p) => "resources/" + p;
|
|
|
|
this.assets.Loaders.TryAdd("png", TextureLoader.Load2DTexture);
|
|
|
|
this.camera = new Camera2D(Game.WIDTH_UNITS, Game.HEIGHT_UNITS);
|
|
|
|
this.camera.Position = new Vector2(Game.WIDTH_UNITS / 2, Game.HEIGHT_UNITS / 2);
|
|
|
|
this.camera.MoveTo = this.camera.Position;
|
|
|
|
this.renderer = new MeshBatchRenderer(camera);
|
|
|
|
|
2020-07-12 04:19:50 +00:00
|
|
|
//Set up title TTF
|
|
|
|
this.titleFont = new BitmapFont("resources/BigShouldersDisplay-Regular.ttf", textureSizes: 512);
|
|
|
|
this.titleFont.PixelsPerUnitHeight = 80;
|
|
|
|
this.titleFont.PixelsPerUnitWidth = 80;
|
2020-07-12 17:26:36 +00:00
|
|
|
genericFont = new BitmapFont("resources/BigShouldersDisplay-Light.ttf");
|
2020-07-11 23:43:47 +00:00
|
|
|
genericFont.PixelsPerUnitHeight = 80;
|
|
|
|
genericFont.PixelsPerUnitWidth = 80;
|
2020-07-12 04:19:50 +00:00
|
|
|
//Add additional states
|
|
|
|
GameOverState gameOverState = new GameOverState(genericFont, titleFont, renderer, assets);
|
|
|
|
manager.AddState(gameOverState);
|
|
|
|
manager.AddState(new GamePlayState(renderer, this.assets, genericFont, gameOverState));
|
2020-07-12 17:05:52 +00:00
|
|
|
manager.AddState(new TutorialState(renderer, assets));
|
2020-07-11 19:02:52 +00:00
|
|
|
|
|
|
|
//Load assets
|
2020-07-11 23:43:47 +00:00
|
|
|
assets.Load("serverunit.png");
|
|
|
|
assets.Load("packet.png");
|
|
|
|
assets.Load("warning.png");
|
|
|
|
assets.Load("downloadbar.png");
|
|
|
|
assets.Load("drag.png");
|
|
|
|
assets.Load("usage.png");
|
2020-07-12 04:19:50 +00:00
|
|
|
assets.Load("health.png");
|
2020-07-12 08:33:09 +00:00
|
|
|
assets.Load("beam.png");
|
2020-07-12 04:19:50 +00:00
|
|
|
assets.Load("ram.png");
|
2020-07-11 19:02:52 +00:00
|
|
|
|
2020-07-12 08:33:09 +00:00
|
|
|
Texture downloadBarTex = (Texture)assets["downloadbar.png"];
|
|
|
|
downloadBarTex.SetNearestFilter(true, true);
|
2020-07-11 19:02:52 +00:00
|
|
|
|
|
|
|
//Set up icon
|
|
|
|
Texture serverUnitTex = (Texture)assets["serverunit.png"];
|
|
|
|
serverUnitTex.SetNearestFilter(true, true);
|
2020-07-12 17:45:12 +00:00
|
|
|
this.serverUnit = new RectangleMesh(new RectangleF(Game.WIDTH_UNITS/2 - 0.75f, Game.HEIGHT_UNITS * 0.5f - 0.75f, 1.5f, 1.5f), serverUnitTex, Color.White);
|
2020-07-11 19:02:52 +00:00
|
|
|
|
|
|
|
this.context.Shown = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Render(double delta)
|
|
|
|
{
|
|
|
|
renderer.Begin(Matrix4x4.Identity, delta);
|
|
|
|
this.titleFont.PixelHeight = 120;
|
2020-07-12 17:45:12 +00:00
|
|
|
this.titleFont.WriteLine(renderer, 0.02f, 0.02f, "Website Simulator", Color.Black);
|
2020-07-11 19:02:52 +00:00
|
|
|
|
|
|
|
this.titleFont.PixelHeight = 40;
|
2020-07-12 17:45:12 +00:00
|
|
|
this.titleFont.WriteLine(renderer, 0, 1.2f, "How it feels to be on the other end...", Color.Gray);
|
2020-07-11 19:02:52 +00:00
|
|
|
|
|
|
|
renderer.Draw(serverUnit);
|
|
|
|
|
2020-07-12 17:45:12 +00:00
|
|
|
this.titleFont.WriteLine(renderer, Game.WIDTH_UNITS / 2f - 1.25f, Game.HEIGHT_UNITS / 2f + 1f, "Press space to start...", Color.Black);
|
2020-07-11 19:02:52 +00:00
|
|
|
renderer.End();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Update(double timeStep)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void KeyInput(SDL.SDL_Keycode keys, bool pressed)
|
|
|
|
{
|
2020-07-12 08:33:09 +00:00
|
|
|
if (!pressed && keys == SDL.SDL_Keycode.SDLK_SPACE)
|
2020-07-11 19:02:52 +00:00
|
|
|
{
|
2020-07-12 17:05:52 +00:00
|
|
|
manager.ChangeState("Tutorial");
|
2020-07-11 19:02:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|