Files
Nockin_On_Hells_Door/script/Player.cs
2024-10-18 23:49:52 +02:00

43 lines
824 B
C#

using Godot;
using System;
public partial class Player : CharacterBody2D
{
[Export] float Speed;
[ExportGroup("controls")]
[Export] Control menu;
public float PixelSize = 1.0f;
public override void _PhysicsProcess(double delta)
{
Vector2 velocity = Velocity;
if(Input.IsActionPressed("quit"))
{
Input.MouseMode = Input.MouseModeEnum.Visible;
GetTree().Paused= true;
menu.Visible = true;
}
Vector2 direction = Input.GetVector("left", "right", "up", "down");
direction = direction.Normalized();
if (direction != Vector2.Zero)
{
velocity = direction * Speed * (float)delta;
}
else
{
velocity.X = Mathf.MoveToward(Velocity.X, 0, Speed);
velocity.Y = Mathf.MoveToward(Velocity.Y, 0, Speed);
}
Velocity = velocity;
MoveAndSlide();
Position = Position.Round();
}
}