2020-04-07 17:50:31 +02:00
|
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
|
using Microsoft.Xna.Framework.Input;
|
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Input
|
|
|
|
|
{
|
|
|
|
|
private KeyboardState state = Keyboard.GetState();
|
2020-04-08 20:04:31 +02:00
|
|
|
|
private GraphicsDeviceManager graphics;
|
|
|
|
|
private Vector2 Size;
|
|
|
|
|
private int tileSize;
|
|
|
|
|
private int Spacing;
|
2020-04-07 17:50:31 +02:00
|
|
|
|
|
|
|
|
|
public void init(GraphicsDeviceManager Graphics, Vector2 size, int TileSize, int SPacing)
|
|
|
|
|
{
|
|
|
|
|
graphics = Graphics;
|
|
|
|
|
tileSize = TileSize;
|
|
|
|
|
Spacing = SPacing;
|
|
|
|
|
Size = size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int changeSpeed(int speed)
|
|
|
|
|
{
|
|
|
|
|
KeyboardState state = Keyboard.GetState();
|
|
|
|
|
if (state.IsKeyDown(Keys.Right))
|
|
|
|
|
{
|
|
|
|
|
speed++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (state.IsKeyDown(Keys.Left) && speed > 0)
|
|
|
|
|
{
|
|
|
|
|
speed--;
|
|
|
|
|
}
|
|
|
|
|
return speed;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-08 20:04:31 +02:00
|
|
|
|
private Vector2 changeSize()
|
2020-04-07 17:50:31 +02:00
|
|
|
|
{
|
|
|
|
|
KeyboardState state = Keyboard.GetState();
|
|
|
|
|
if (state.IsKeyDown(Keys.D) && Size.X < 100)
|
|
|
|
|
{
|
|
|
|
|
Size.X++;
|
2020-04-08 20:04:31 +02:00
|
|
|
|
graphics.PreferredBackBufferWidth = (tileSize + Spacing) * (int)Size.X - Spacing;
|
2020-04-07 17:50:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (state.IsKeyDown(Keys.A) && Size.X > 2)
|
|
|
|
|
{
|
|
|
|
|
Size.X--;
|
2020-04-08 20:04:31 +02:00
|
|
|
|
graphics.PreferredBackBufferWidth = (tileSize + Spacing) * (int)Size.X - Spacing;
|
2020-04-07 17:50:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-08 20:04:31 +02:00
|
|
|
|
if (state.IsKeyDown(Keys.W) && Size.Y < (GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height / tileSize) - 125 / tileSize)
|
2020-04-07 17:50:31 +02:00
|
|
|
|
{
|
|
|
|
|
Size.Y++;
|
2020-04-08 20:04:31 +02:00
|
|
|
|
graphics.PreferredBackBufferHeight = (tileSize + Spacing) * (int)Size.Y - Spacing + 100;
|
2020-04-07 17:50:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (state.IsKeyDown(Keys.S) && Size.Y > 2)
|
|
|
|
|
{
|
|
|
|
|
Size.Y--;
|
2020-04-08 20:04:31 +02:00
|
|
|
|
graphics.PreferredBackBufferHeight = (tileSize + Spacing) * (int)Size.Y - Spacing + 100;
|
2020-04-07 17:50:31 +02:00
|
|
|
|
}
|
|
|
|
|
return Size;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-08 20:04:31 +02:00
|
|
|
|
public void controlWindowSize()
|
2020-04-07 17:50:31 +02:00
|
|
|
|
{
|
2020-04-08 20:04:31 +02:00
|
|
|
|
if (Size.X * tileSize + 5 > GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width)
|
2020-04-07 17:50:31 +02:00
|
|
|
|
{
|
|
|
|
|
tileSize--;
|
|
|
|
|
}
|
2020-04-08 20:04:31 +02:00
|
|
|
|
if (Size.X * tileSize - 5 < GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width && tileSize < 56)
|
2020-04-07 17:50:31 +02:00
|
|
|
|
{
|
|
|
|
|
tileSize++;
|
|
|
|
|
}
|
2020-04-08 20:04:31 +02:00
|
|
|
|
changeSize();
|
2020-04-07 17:50:31 +02:00
|
|
|
|
graphics.ApplyChanges();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getTileSize()
|
|
|
|
|
{
|
|
|
|
|
return tileSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getSpacing()
|
|
|
|
|
{
|
|
|
|
|
return Spacing;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Vector2 getSize()
|
|
|
|
|
{
|
|
|
|
|
return Size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setTileSize(int newTileSize)
|
|
|
|
|
{
|
|
|
|
|
tileSize = newTileSize;
|
|
|
|
|
}
|
|
|
|
|
}
|