Улучшение логики живого доспеха и нажимной плиты. Реализация шипов.
This commit is contained in:
parent
2e5d268f35
commit
602df1ed1d
6 changed files with 201 additions and 4 deletions
|
@ -83,7 +83,7 @@ public partial class LivingArmor : CharacterBody2D
|
|||
case State.Attack:
|
||||
break;
|
||||
case State.Waiting:
|
||||
_sprite.Stop();
|
||||
_sprite.Pause();
|
||||
break;
|
||||
|
||||
case State.Moving:
|
||||
|
|
|
@ -3,6 +3,12 @@ using System;
|
|||
|
||||
public partial class PressurePlate : Area2D
|
||||
{
|
||||
[Signal]
|
||||
public delegate void ButtonPressedEventHandler();
|
||||
|
||||
[Signal]
|
||||
public delegate void ButtonUnpressedEventHandler();
|
||||
|
||||
private bool _pressed = false;
|
||||
private int _onButton = 0;
|
||||
|
||||
|
@ -33,6 +39,10 @@ public partial class PressurePlate : Area2D
|
|||
|
||||
private void _onPressed(Node2D body)
|
||||
{
|
||||
if (_onButton <= 0)
|
||||
{
|
||||
EmitSignal(SignalName.ButtonPressed);
|
||||
}
|
||||
_onButton += 1;
|
||||
_pressed = true;
|
||||
}
|
||||
|
@ -44,6 +54,7 @@ public partial class PressurePlate : Area2D
|
|||
if (_onButton > 0)
|
||||
return;
|
||||
_pressed = false;
|
||||
EmitSignal(SignalName.ButtonUnpressed);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
105
scripts/entities/Spikes.cs
Normal file
105
scripts/entities/Spikes.cs
Normal file
|
@ -0,0 +1,105 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class Spikes : Area2D
|
||||
{
|
||||
public enum State
|
||||
{
|
||||
Waiting,
|
||||
Opening,
|
||||
Closing
|
||||
}
|
||||
|
||||
[Export] public bool Enabled = false;
|
||||
[Export] public float SpikesTimeout = 1f;
|
||||
[Export] public float StartOffset = 0f;
|
||||
private AnimatedSprite2D _sprite;
|
||||
private State _state = State.Waiting;
|
||||
private float _timeSinceState;
|
||||
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
_sprite = (AnimatedSprite2D)FindChild("AnimatedSprite2D");
|
||||
_timeSinceState -= StartOffset;
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
if (Enabled)
|
||||
{
|
||||
switch (_state)
|
||||
{
|
||||
case State.Waiting:
|
||||
_sprite.Stop();
|
||||
_timeSinceState += (float)delta;
|
||||
if (_timeSinceState > SpikesTimeout)
|
||||
{
|
||||
_state = State.Opening;
|
||||
_timeSinceState = 0;
|
||||
}
|
||||
break;
|
||||
case State.Opening:
|
||||
_sprite.Play("default");
|
||||
break;
|
||||
case State.Closing:
|
||||
_sprite.PlayBackwards("default");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void _OnEntered(Node2D body)
|
||||
{
|
||||
if (body is not Player player)
|
||||
return;
|
||||
|
||||
if (_state is State.Waiting)
|
||||
return;
|
||||
|
||||
player.Kill(this);
|
||||
}
|
||||
|
||||
|
||||
private void _OnExited(Node2D body)
|
||||
{
|
||||
// Replace with function body.
|
||||
}
|
||||
|
||||
private void _WhenOpened()
|
||||
{
|
||||
switch (_state)
|
||||
{
|
||||
case State.Waiting:
|
||||
break;
|
||||
case State.Opening:
|
||||
_state = State.Closing;
|
||||
break;
|
||||
case State.Closing:
|
||||
_state = State.Waiting;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void On()
|
||||
{
|
||||
Enabled = true;
|
||||
_timeSinceState = -StartOffset;
|
||||
}
|
||||
|
||||
private void Off()
|
||||
{
|
||||
_sprite.Stop();
|
||||
Enabled = false;
|
||||
_state = State.Waiting;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue