menu + player
This commit is contained in:
@@ -3,32 +3,34 @@ using System;
|
||||
|
||||
public partial class Player : CharacterBody2D
|
||||
{
|
||||
public const float Speed = 300.0f;
|
||||
public const float JumpVelocity = -400.0f;
|
||||
[Export] float Speed;
|
||||
public float PixelSize = 1.0f;
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
Vector2 velocity = Velocity;
|
||||
|
||||
// Handle Jump.
|
||||
if (Input.IsActionJustPressed("ui_accept") && IsOnFloor())
|
||||
if(Input.IsActionPressed("quit"))
|
||||
{
|
||||
velocity.Y = JumpVelocity;
|
||||
GetTree().Quit();
|
||||
}
|
||||
|
||||
// Get the input direction and handle the movement/deceleration.
|
||||
// As good practice, you should replace UI actions with custom gameplay actions.
|
||||
Vector2 direction = Input.GetVector("ui_left", "ui_right", "ui_up", "ui_down");
|
||||
|
||||
Vector2 direction = Input.GetVector("left", "right", "up", "down");
|
||||
direction = direction.Normalized();
|
||||
if (direction != Vector2.Zero)
|
||||
{
|
||||
velocity.X = direction.X * Speed;
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user