mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
Openable doors
This commit is contained in:
parent
fa954af626
commit
447a43eda2
14 changed files with 319 additions and 32 deletions
97
Scripts/Door.cs
Normal file
97
Scripts/Door.cs
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
using Godot;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Cirno.Scripts;
|
||||
|
||||
public partial class Door : Activable
|
||||
{
|
||||
private AnimatedSprite2D _animatedSprite;
|
||||
private CollisionShape2D _collisionShape;
|
||||
private CollisionShape2D _solidShape;
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
|
||||
[Export]
|
||||
public DoorState State { get; set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_animatedSprite = GetNode<AnimatedSprite2D>("AnimatedSprite2D");
|
||||
_collisionShape = GetNode<CollisionShape2D>("CollisionShape2D");
|
||||
_solidShape = GetNode<CollisionShape2D>("RigidBody2D/CollisionShape2D");
|
||||
|
||||
SetState(State);
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
}
|
||||
|
||||
public void Open()
|
||||
{
|
||||
_animatedSprite.Play("Opening");
|
||||
State = DoorState.Open;
|
||||
_collisionShape.Disabled = true;
|
||||
_solidShape.Disabled = true;
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
_animatedSprite.Play("Closing");
|
||||
State = DoorState.Closed;
|
||||
_collisionShape.Disabled = false;
|
||||
_solidShape.Disabled = false;
|
||||
|
||||
}
|
||||
|
||||
public override void Activate()
|
||||
{
|
||||
switch (State)
|
||||
{
|
||||
case DoorState.Closed:
|
||||
Open();
|
||||
break;
|
||||
case DoorState.Open:
|
||||
Close();
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
private void SetState(DoorState state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case DoorState.Closed:
|
||||
Close();
|
||||
break;
|
||||
case DoorState.Open:
|
||||
Open();
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
public void _on_animated_sprite_2d_animation_changed()
|
||||
{
|
||||
switch (_animatedSprite.Animation)
|
||||
{
|
||||
case "Opening":
|
||||
|
||||
break;
|
||||
case "Closing":
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum DoorState
|
||||
{
|
||||
Closed,
|
||||
Open
|
||||
}
|
||||
6
Scripts/IActivable.cs
Normal file
6
Scripts/IActivable.cs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
namespace Cirno.Scripts;
|
||||
|
||||
public interface IActivable
|
||||
{
|
||||
void Activate();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue