PotatoPlan/Tractor_VS/Game1/Sources/Input.cs

101 lines
2.4 KiB
C#
Raw Normal View History

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();
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;
}
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++;
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--;
graphics.PreferredBackBufferWidth = (tileSize + Spacing) * (int)Size.X - Spacing;
2020-04-07 17:50: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++;
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--;
graphics.PreferredBackBufferHeight = (tileSize + Spacing) * (int)Size.Y - Spacing + 100;
2020-04-07 17:50:31 +02:00
}
return Size;
}
public void controlWindowSize()
2020-04-07 17:50:31 +02:00
{
if (Size.X * tileSize + 5 > GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width)
2020-04-07 17:50:31 +02:00
{
tileSize--;
}
if (Size.X * tileSize - 5 < GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width && tileSize < 56)
2020-04-07 17:50:31 +02:00
{
tileSize++;
}
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;
}
}