60 lines
1 KiB
C#
60 lines
1 KiB
C#
using Godot;
|
|
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;
|
|
|
|
private AnimatedSprite2D _sprite;
|
|
// Called when the node enters the scene tree for the first time.
|
|
public override void _Ready()
|
|
{
|
|
_sprite = (AnimatedSprite2D)FindChild("AnimatedSprite2D");
|
|
}
|
|
|
|
// 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 (_pressed)
|
|
{
|
|
_sprite.Play("pressed");
|
|
}
|
|
else
|
|
{
|
|
_sprite.Play("default");
|
|
}
|
|
|
|
}
|
|
|
|
private void _onPressed(Node2D body)
|
|
{
|
|
if (_onButton <= 0)
|
|
{
|
|
EmitSignal(SignalName.ButtonPressed);
|
|
}
|
|
_onButton += 1;
|
|
_pressed = true;
|
|
}
|
|
|
|
|
|
private void _onUnpressed(Node2D body)
|
|
{
|
|
_onButton -= 1;
|
|
if (_onButton > 0)
|
|
return;
|
|
_pressed = false;
|
|
EmitSignal(SignalName.ButtonUnpressed);
|
|
}
|
|
|
|
}
|