Last stretch
This commit is contained in:
parent
466a154972
commit
68271c94ed
13 changed files with 338 additions and 99 deletions
|
@ -55,6 +55,8 @@ public partial class GameManager : Node
|
|||
|
||||
public void OnPlayerDied() => _gameInfo.Attempts++;
|
||||
|
||||
public int GetAttempts() => _gameInfo.Attempts;
|
||||
|
||||
public void SetCurrentZone(PlayZone zone)
|
||||
{
|
||||
GD.Print($"New zone {zone}");
|
||||
|
|
28
scripts/WinScreen.cs
Normal file
28
scripts/WinScreen.cs
Normal file
|
@ -0,0 +1,28 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class WinScreen : TextureRect
|
||||
{
|
||||
[Export] public GameManager Manager;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Visible = false;
|
||||
}
|
||||
|
||||
public void Open()
|
||||
{
|
||||
Visible = true;
|
||||
|
||||
((Label)FindChild("Label2")).Text =
|
||||
$"It took you\n{Manager.GetAttempts()} attempts\nand {Manager.GetFormattedTimeElapsed()}\nto finish the game.";
|
||||
}
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
if (Visible && @event.IsActionPressed("ui_confirm"))
|
||||
{
|
||||
GetTree().ChangeSceneToFile("res://scenes/menu.tscn");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,18 +4,20 @@ using System;
|
|||
public partial class Claw : CharacterBody2D
|
||||
{
|
||||
[Export] public float MovingSpeed = 32f;
|
||||
|
||||
public enum State
|
||||
{
|
||||
Waiting,
|
||||
Moving,
|
||||
Prepare,
|
||||
Attack
|
||||
}
|
||||
|
||||
private State _state = State.Moving;
|
||||
private State _state = State.Waiting;
|
||||
private float _stateTimeout = 0;
|
||||
private bool _isPlayerNearBy = false;
|
||||
private AnimatedSprite2D _sprite;
|
||||
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
|
@ -32,6 +34,9 @@ public partial class Claw : CharacterBody2D
|
|||
_stateTimeout -= (float)delta;
|
||||
switch (_state)
|
||||
{
|
||||
case State.Waiting:
|
||||
break;
|
||||
|
||||
case State.Moving:
|
||||
var direction = (Player.Instance.Position - Position).Normalized();
|
||||
Velocity = direction * MovingSpeed;
|
||||
|
@ -46,6 +51,7 @@ public partial class Claw : CharacterBody2D
|
|||
_state = State.Attack;
|
||||
_stateTimeout = 0.25f;
|
||||
}
|
||||
|
||||
break;
|
||||
case State.Attack:
|
||||
_sprite.Play("attack");
|
||||
|
@ -55,10 +61,10 @@ public partial class Claw : CharacterBody2D
|
|||
if (_isPlayerNearBy)
|
||||
Player.Instance.Kill(this);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void _OnEntered(Node2D body)
|
||||
{
|
||||
|
@ -75,7 +81,10 @@ public partial class Claw : CharacterBody2D
|
|||
{
|
||||
_isPlayerNearBy = false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void Enable()
|
||||
{
|
||||
GD.Print("Boss enabled");
|
||||
_state = State.Moving;
|
||||
}
|
||||
}
|
||||
|
|
27
scripts/entities/Door.cs
Normal file
27
scripts/entities/Door.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
using Godot;
|
||||
|
||||
public partial class Door : Node2D
|
||||
{
|
||||
private AnimatedSprite2D _animatedSprite2D;
|
||||
private CollisionShape2D _collisionShape2D;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_animatedSprite2D = (AnimatedSprite2D)FindChild("AnimatedSprite2D");
|
||||
_collisionShape2D = (CollisionShape2D)FindChild("CollisionShape2D");
|
||||
|
||||
Close();
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
_animatedSprite2D.Play("close");
|
||||
_collisionShape2D.Disabled = false;
|
||||
}
|
||||
|
||||
public void Open()
|
||||
{
|
||||
_animatedSprite2D.Play("open");
|
||||
_collisionShape2D.Disabled = true;
|
||||
}
|
||||
}
|
20
scripts/entities/Teleport.cs
Normal file
20
scripts/entities/Teleport.cs
Normal file
|
@ -0,0 +1,20 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class Teleport : Area2D
|
||||
{
|
||||
[Signal]
|
||||
public delegate void TeleportTriggeredEventHandler();
|
||||
|
||||
[Export] public Node2D To;
|
||||
|
||||
private void OnPlayerEntered(Node2D body)
|
||||
{
|
||||
if (body is not Player player)
|
||||
return;
|
||||
|
||||
player.GlobalPosition = To.GlobalPosition;
|
||||
|
||||
EmitSignal(SignalName.TeleportTriggered);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue