59 lines
1.4 KiB
C#
59 lines
1.4 KiB
C#
using System.Numerics;
|
|
using Raylib_cs;
|
|
|
|
namespace deleteme;
|
|
|
|
public class Game
|
|
{
|
|
private Vector2 _playerPosition = Vector2.Zero;
|
|
private float _speed = 0.5f;
|
|
|
|
|
|
public Game()
|
|
{
|
|
Raylib.SetConfigFlags(ConfigFlags.ResizableWindow);
|
|
Raylib.InitWindow(1280,720,"Raylib");
|
|
|
|
_playerPosition = new Vector2(Raylib.GetScreenWidth() / 2, Raylib.GetScreenHeight() / 2);
|
|
|
|
while (!Raylib.WindowShouldClose())
|
|
{
|
|
Update();
|
|
Draw();
|
|
}
|
|
}
|
|
|
|
private void Draw()
|
|
{
|
|
Raylib.BeginDrawing();
|
|
Raylib.ClearBackground(new(10,0,30,255));
|
|
|
|
DrawPlayer();
|
|
|
|
Raylib.EndDrawing();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
Input();
|
|
}
|
|
|
|
private void Input()
|
|
{
|
|
Vector2 newPos = _playerPosition;
|
|
|
|
|
|
if (Raylib.IsKeyDown(KeyboardKey.D) && newPos.X < Raylib.GetScreenWidth() - 16) newPos.X += _speed;
|
|
if (Raylib.IsKeyDown(KeyboardKey.A) && newPos.X != 0) newPos.X -= _speed;
|
|
|
|
if (Raylib.IsKeyDown(KeyboardKey.W) && newPos.Y != 0) newPos.Y -= _speed;
|
|
if (Raylib.IsKeyDown(KeyboardKey.S) && newPos.Y < Raylib.GetScreenHeight() - 16) newPos.Y += _speed;
|
|
|
|
_playerPosition = newPos;
|
|
}
|
|
|
|
private void DrawPlayer()
|
|
{
|
|
Raylib.DrawRectangle((int)_playerPosition.X, (int)_playerPosition.Y, 16,16, Color.RayWhite);
|
|
}
|
|
} |