+ Game UI

This commit is contained in:
2022-10-20 09:48:48 +02:00
parent 1d93d70024
commit 711d0d4e36
8 changed files with 183 additions and 60 deletions
+22 -22
View File
@@ -22,17 +22,17 @@ namespace client
// Constructors
public Player()
{
this.Position = new Vector2(0, 0);
this.DefaultPosition = new Vector2(0, 0);
this.width = 20;
this.height = 100;
this.speed = 100f;
Position = new Vector2(0, 0);
DefaultPosition = new Vector2(0, 0);
width = 20;
height = 100;
speed = 100f;
}
public Player(Vector2 position, int width, int height, float speed)
{
this.Position = position;
this.DefaultPosition = position;
Position = position;
DefaultPosition = position;
this.width = width;
this.height = height;
this.speed = speed;
@@ -41,73 +41,73 @@ namespace client
// Update the player's position
public Player setPos(Vector2 pos)
{
this.Position = pos;
Position = pos;
return this;
}
// Set | Get default player position
public Player setDefaultPos(Vector2 pos)
{
this.DefaultPosition = pos;
DefaultPosition = pos;
return this;
}
public Vector2 getDefaultPos()
{
return this.DefaultPosition;
return DefaultPosition;
}
public Player BackToDefaultPos()
{
this.Position = this.DefaultPosition;
Position = DefaultPosition;
return this;
}
// Set controllable by input
public Player SetControllable(bool state)
{
this.canMove = state;
canMove = state;
return this;
}
// Draw player on screen
public Player DrawPlayer(SpriteBatch spriteBatch, GraphicsDevice _graphicsDevice)
{
Texture2D texture = new Texture2D(_graphicsDevice, this.width, this.height);
Color[] data = new Color[this.width * this.height];
Texture2D texture = new Texture2D(_graphicsDevice, width, height);
Color[] data = new Color[width * height];
for (int i = 0; i < data.Length; ++i)
{
data[i] = Color.White;
}
texture.SetData(data);
spriteBatch.Draw(texture, this.Position, Color.White);
spriteBatch.Draw(texture, Position, Color.White);
return this;
}
// Inputs controls
public Player InputsControls(GameTime gameTime, float screenHeight)
{
if (this.canMove)
if (canMove)
{
if (Keyboard.GetState().IsKeyDown(Keys.Up))
{
Vector2 asked = new Vector2(this.Position.X, this.Position.Y - this.speed * (float)gameTime.ElapsedGameTime.TotalSeconds);
Vector2 asked = new Vector2(Position.X, Position.Y - speed * (float)gameTime.ElapsedGameTime.TotalSeconds);
if (asked.Y <= 0)
{
asked.Y = 0f;
}
this.Position = asked;
Position = asked;
}
if (Keyboard.GetState().IsKeyDown(Keys.Down))
{
Vector2 asked = new Vector2(this.Position.X, this.Position.Y + this.speed * (float)gameTime.ElapsedGameTime.TotalSeconds);
if (asked.Y >= screenHeight - this.height)
Vector2 asked = new Vector2(Position.X, Position.Y + speed * (float)gameTime.ElapsedGameTime.TotalSeconds);
if (asked.Y >= screenHeight - height)
{
asked.Y = screenHeight - this.height;
asked.Y = screenHeight - height;
}
this.Position = asked;
Position = asked;
}
}
return this;