door (20)
This commit is contained in:
17
script/Car.cs
Normal file
17
script/Car.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class Car : CharacterBody2D
|
||||
{
|
||||
[Export] PackedScene player;
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
}
|
||||
public void BodyEntered(Node2D body)
|
||||
{
|
||||
if (body.IsInGroup("player"))
|
||||
{
|
||||
body.Call("OverVoiture");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,19 +8,24 @@ public partial class Door : Node2D
|
||||
[Export] string answerA;
|
||||
[Export] string answerB;
|
||||
[Export] bool answerA_good;
|
||||
[Export] bool shot;
|
||||
[Export] bool caniche;
|
||||
[Export] AudioStream audio;
|
||||
|
||||
[ExportGroup("image")]
|
||||
[Export] Texture2D image_mob;
|
||||
bool player_in = false;
|
||||
CharacterBody2D player;
|
||||
bool open = false;
|
||||
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
|
||||
if(player_in && Input.IsActionPressed("interact"))
|
||||
if(player_in && Input.IsActionPressed("interact") && open == false)
|
||||
{
|
||||
open = true;
|
||||
Control view = player.GetNode<Control>("Camera2D/door_view");
|
||||
|
||||
view.Set("text_char", text_char);
|
||||
@@ -28,6 +33,8 @@ public partial class Door : Node2D
|
||||
view.Set("answerB", answerB);
|
||||
view.Set("answerA_good", answerA_good);
|
||||
view.Set("mobTex", image_mob);
|
||||
view.Set("shot", shot);
|
||||
view.Set("caniche", caniche);
|
||||
view.Call("start");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,24 +13,44 @@ public partial class DoorView : Control
|
||||
string answerA{get; set;}
|
||||
string answerB{get; set;}
|
||||
bool answerA_good {get; set;}
|
||||
|
||||
|
||||
bool shot {get; set;}= true;
|
||||
bool caniche {get; set;}= false;
|
||||
|
||||
CharacterBody2D player;
|
||||
|
||||
[Export] Label text_mob;
|
||||
[Export] Button butA;
|
||||
[Export] Button butB;
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
player = (CharacterBody2D)GetParent().GetParent();
|
||||
}
|
||||
public void start()
|
||||
public async void start()
|
||||
{
|
||||
GetParent<Camera2D>().PositionSmoothingEnabled = false;
|
||||
Input.MouseMode = Input.MouseModeEnum.Visible;
|
||||
GetTree().Paused = true;
|
||||
Visible = true;
|
||||
mob.Texture = mobTex;
|
||||
anim.Play("enter");
|
||||
|
||||
if(shot)
|
||||
{
|
||||
anim.Play("shot");
|
||||
player.Call("OverShotgun");
|
||||
}
|
||||
else if (caniche)
|
||||
{
|
||||
anim.Play("can");
|
||||
}
|
||||
else
|
||||
{
|
||||
anim.Play("enter");
|
||||
}
|
||||
}
|
||||
|
||||
public void stop()
|
||||
|
||||
15
script/Gameover.cs
Normal file
15
script/Gameover.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class Gameover : CanvasLayer
|
||||
{
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ public partial class Principal : Control
|
||||
{
|
||||
[Export] Panel sub;
|
||||
[Export] Panel credit;
|
||||
[Export] AnimationPlayer anim;
|
||||
bool play_pressed = false;
|
||||
bool enter = false;
|
||||
|
||||
|
||||
Node parent;
|
||||
@@ -12,6 +15,7 @@ public partial class Principal : Control
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
GetTree().Paused = false;
|
||||
parent = GetParent();
|
||||
sub.Visible = false;
|
||||
}
|
||||
@@ -19,6 +23,16 @@ public partial class Principal : Control
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if(play_pressed && Input.IsActionJustPressed("valid") && !enter)
|
||||
{
|
||||
enter = true;
|
||||
anim.Play("play2");
|
||||
}else if (enter && Input.IsActionJustPressed("valid"))
|
||||
{
|
||||
//GetTree().Paused = false;
|
||||
parent.Call("ToCityFunc");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void EnterPressed()
|
||||
@@ -40,9 +54,13 @@ public partial class Principal : Control
|
||||
|
||||
public void PlayPressed()
|
||||
{
|
||||
parent.Call("ToCityFunc");
|
||||
//EmitSignal("ToCityEventHandler");
|
||||
//GetTree().ChangeSceneToPacked(play);
|
||||
if (!play_pressed)
|
||||
{
|
||||
play_pressed = true;
|
||||
anim.Play("play");
|
||||
}
|
||||
//parent.Call("ToCityFunc");
|
||||
|
||||
}
|
||||
|
||||
public void ExitGlobPressed()
|
||||
|
||||
Reference in New Issue
Block a user