Files
Nockin_On_Hells_Door/script/Player.cs
2024-10-20 10:31:07 +02:00

105 lines
1.7 KiB
C#

using Godot;
using System;
public partial class Player : CharacterBody2D
{
[Export] float Speed;
[Export] float sugar_speed;
[Export] AnimationPlayer anim;
[Export] Camera2D cam;
[Export] TextureProgressBar bar;
[ExportGroup("controls")]
[Export] Control menu;
[Export] float minute_part_second = 1;
[Export] Label time;
float minute;
int heure = 18;
public float PixelSize = 1.0f;
float sugar { get; set;}= 50;
const float MAX_SUGAR = 100;
public override void _PhysicsProcess(double delta)
{
Vector2 velocity = Velocity;
sugar -= (float)delta / sugar_speed;
bar.Value = sugar;
if(sugar <= 0)
{
}
else if (sugar >= 100)
{
}
minute += minute_part_second * (float) delta;
if (minute >= 60)
{
minute = 0;
heure +=1;
}
UpdateTime();
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.Round();
}
if(Input.IsActionPressed("quit"))
{
Input.MouseMode = Input.MouseModeEnum.Visible;
anim.Play("paused");
GetTree().Paused= true;
}
else if(velocity.X > 0)
{
anim.Play("right");
}
else if (velocity.X < 0)
{
anim.Play("left");
}
else if (velocity.Y > 0)
{
anim.Play("down");
}
else if (velocity.Y < 0)
{
anim.Play("up");
}
else
{
anim.Play("idle");
}
Velocity = velocity;
MoveAndSlide();
Position = Position.Round();
}
void UpdateTime()
{
time.Text = string.Format("{0:D2}:{1:D2}", heure, (int)Math.Floor(minute));
}
}