door (20)
This commit is contained in:
118
script/Player.cs
118
script/Player.cs
@@ -1,5 +1,7 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
public partial class Player : CharacterBody2D
|
||||
{
|
||||
@@ -12,8 +14,26 @@ public partial class Player : CharacterBody2D
|
||||
[Export] Control menu;
|
||||
[Export] float minute_part_second = 1;
|
||||
[Export] Label time;
|
||||
[Export] Sprite2D over;
|
||||
[Export] CanvasLayer gameover;
|
||||
[Export] AudioStreamPlayer audio;
|
||||
float minute;
|
||||
int heure = 18;
|
||||
|
||||
[ExportGroup("gameover")]
|
||||
[Export] Texture2D caniche;
|
||||
[Export] Texture2D shotgun;
|
||||
[Export] Texture2D caramel;
|
||||
[Export] Texture2D glissemie;
|
||||
[Export] Texture2D voiture;
|
||||
[Export] Texture2D win;
|
||||
|
||||
[Export] AudioStream aud_caniche;
|
||||
[Export] AudioStream aud_shotgun;
|
||||
[Export] AudioStream aud_caramel;
|
||||
[Export] AudioStream aud_glissemie;
|
||||
[Export] AudioStream aud_voiture;
|
||||
[Export] AudioStream aud_win;
|
||||
|
||||
|
||||
|
||||
@@ -21,31 +41,57 @@ public partial class Player : CharacterBody2D
|
||||
|
||||
float sugar { get; set;}= 50;
|
||||
const float MAX_SUGAR = 100;
|
||||
bool end = false;
|
||||
|
||||
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
this.AddToGroup("player");
|
||||
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
Vector2 velocity = Velocity;
|
||||
|
||||
|
||||
if (end == false)
|
||||
{
|
||||
sugar -= (float)delta / sugar_speed;
|
||||
}
|
||||
|
||||
|
||||
sugar -= (float)delta / sugar_speed;
|
||||
bar.Value = sugar;
|
||||
|
||||
if(sugar <= 0)
|
||||
|
||||
if(sugar <= 5)
|
||||
{
|
||||
|
||||
sugar = 50;
|
||||
end = true;
|
||||
OverGlissemie();
|
||||
}
|
||||
else if (sugar >= 100)
|
||||
else if (sugar >= 90)
|
||||
{
|
||||
|
||||
sugar = 50;
|
||||
end = true;
|
||||
OverCaramel();
|
||||
}
|
||||
|
||||
minute += minute_part_second * (float) delta;
|
||||
|
||||
if (minute >= 60)
|
||||
{
|
||||
|
||||
minute = 0;
|
||||
heure +=1;
|
||||
}
|
||||
UpdateTime();
|
||||
|
||||
if (heure >= 22)
|
||||
{
|
||||
heure = 0;
|
||||
OverWin();
|
||||
}
|
||||
|
||||
Vector2 direction = Input.GetVector("left", "right", "up", "down");
|
||||
direction = direction.Normalized();
|
||||
@@ -65,8 +111,8 @@ public partial class Player : CharacterBody2D
|
||||
if(Input.IsActionPressed("quit"))
|
||||
{
|
||||
Input.MouseMode = Input.MouseModeEnum.Visible;
|
||||
anim.Play("paused");
|
||||
GetTree().Paused= true;
|
||||
anim.Play("paused");
|
||||
}
|
||||
else if(velocity.X > 0)
|
||||
{
|
||||
@@ -101,4 +147,62 @@ public partial class Player : CharacterBody2D
|
||||
{
|
||||
time.Text = string.Format("{0:D2}:{1:D2}", heure, (int)Math.Floor(minute));
|
||||
}
|
||||
|
||||
void OverCaniche()
|
||||
{
|
||||
GetTree().Paused = true;
|
||||
audio.Stream = aud_caniche;
|
||||
audio.Play();
|
||||
over.Texture = caniche;
|
||||
gameover.Visible = true;
|
||||
end = true;
|
||||
}
|
||||
async void OverShotgun()
|
||||
{
|
||||
await ToSignal(GetTree().CreateTimer(0.8), "timeout");
|
||||
audio.Stream = aud_shotgun;
|
||||
audio.Play();
|
||||
GetTree().Paused = true;
|
||||
over.Texture = shotgun;
|
||||
gameover.Visible = true;
|
||||
end = true;
|
||||
}
|
||||
void OverCaramel()
|
||||
{
|
||||
audio.Stream = aud_caramel;
|
||||
audio.Play();
|
||||
|
||||
GetTree().Paused = true;
|
||||
over.Texture = caramel;
|
||||
gameover.Visible = true;
|
||||
end = true;
|
||||
}
|
||||
void OverGlissemie()
|
||||
{
|
||||
audio.Stream = aud_glissemie;
|
||||
audio.Play();
|
||||
GetTree().Paused = true;
|
||||
over.Texture = glissemie;
|
||||
gameover.Visible = true;
|
||||
end = true;
|
||||
}
|
||||
void OverVoiture()
|
||||
{
|
||||
audio.Stream = aud_voiture;
|
||||
audio.Play();
|
||||
GetTree().Paused = true;
|
||||
over.Texture = voiture;
|
||||
gameover.Visible = true;
|
||||
end = true;
|
||||
}
|
||||
void OverWin()
|
||||
{
|
||||
audio.Stream = aud_win;
|
||||
audio.Play();
|
||||
GetTree().Paused = true;
|
||||
over.Texture = win;
|
||||
gameover.Visible = true;
|
||||
end = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user