1
0
forked from s425077/PotatoPlan
PotatoPlan/Tractor_VS/Game1/Sources/Input.cs
BOTLester 4d1b20b32f done by hand, but works eh.
First stable. RC_01
2020-04-08 20:04:31 +02:00

101 lines
2.4 KiB
C#

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;
class Input
{
private KeyboardState state = Keyboard.GetState();
private GraphicsDeviceManager graphics;
private Vector2 Size;
private int tileSize;
private int Spacing;
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;
}
private Vector2 changeSize()
{
KeyboardState state = Keyboard.GetState();
if (state.IsKeyDown(Keys.D) && Size.X < 100)
{
Size.X++;
graphics.PreferredBackBufferWidth = (tileSize + Spacing) * (int)Size.X - Spacing;
}
if (state.IsKeyDown(Keys.A) && Size.X > 2)
{
Size.X--;
graphics.PreferredBackBufferWidth = (tileSize + Spacing) * (int)Size.X - Spacing;
}
if (state.IsKeyDown(Keys.W) && Size.Y < (GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height / tileSize) - 125 / tileSize)
{
Size.Y++;
graphics.PreferredBackBufferHeight = (tileSize + Spacing) * (int)Size.Y - Spacing + 100;
}
if (state.IsKeyDown(Keys.S) && Size.Y > 2)
{
Size.Y--;
graphics.PreferredBackBufferHeight = (tileSize + Spacing) * (int)Size.Y - Spacing + 100;
}
return Size;
}
public void controlWindowSize()
{
if (Size.X * tileSize + 5 > GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width)
{
tileSize--;
}
if (Size.X * tileSize - 5 < GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width && tileSize < 56)
{
tileSize++;
}
changeSize();
graphics.ApplyChanges();
}
public int getTileSize()
{
return tileSize;
}
public int getSpacing()
{
return Spacing;
}
public Vector2 getSize()
{
return Size;
}
public void setTileSize(int newTileSize)
{
tileSize = newTileSize;
}
}