1
0
forked from s425077/PotatoPlan
JoelForkTest/Tractor_VS/Game1/Sources/Input.cs
BOTLester 165f50b3fd Stable branch push
testin
2020-04-07 17:50:31 +02:00

101 lines
2.3 KiB
C#

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