Spinning chairs

This commit is contained in:
Marco 2025-03-10 15:49:28 +01:00
commit 72ce9fb932
16 changed files with 290 additions and 24 deletions

34
Scripts/Activables/NPC.cs Normal file
View file

@ -0,0 +1,34 @@
using Cirno.Scripts.Interactables;
using Cirno.Scripts.Resources.Events;
using Godot;
using Godot.Collections;
namespace Cirno.Scripts.Activables;
public partial class NPC : Area2D, IInteractable
{
[Export] public Array<EventResource> Events;
private ScriptableBase _scriptable;
public override void _Ready()
{
_scriptable = new ScriptableBase();
_scriptable.Events = Events;
this.CallDeferred("add_child", _scriptable);
}
public bool Activate(ActivationType activationType = ActivationType.Toggle)
{
_scriptable?.Activate(activationType);
return true;
}
public bool CanActivate()
{
return true;
}
}

View file

@ -0,0 +1 @@
uid://cjy38nsh83ug1

View file

@ -8,7 +8,7 @@ namespace Cirno.Scripts.Activables;
public partial class ScriptableBase : Node2D, IActivable
{
[Export] public Array<EventResource> Events;
[Export] public Array<EventResource> Events { get; set; } = [];
private EventResource CurrentEvent => Events[_currentEventIndex];

56
Scripts/Actors/Chair.cs Normal file
View file

@ -0,0 +1,56 @@
using Godot;
using System;
using System.Threading.Tasks;
public partial class Chair : StaticBody2D
{
[Export]
public ChairDirection Direction { get; private set; } = ChairDirection.Down;
private AnimatedSprite2D _animatedSprite;
[Export]
public StringName SpinAnimationName = "Spin";
[Export] public float SpinTime { get; private set; } = 4f;
private double _timer = 0f;
public override void _Ready()
{
_animatedSprite = GetNode<AnimatedSprite2D>("AnimatedSprite2D");
_animatedSprite.Play(Direction.ToString());
}
public override void _Process(double delta)
{
if (_animatedSprite.Animation != SpinAnimationName) return;
_timer += delta;
if (_timer >= SpinTime)
{
_timer = 0;
_animatedSprite.SpeedScale = 0;
}
}
private void OnBulletCollision(Area2D area)
{
_animatedSprite.SpeedScale = 1;
_animatedSprite.Play("Spin");
_timer = 0;
}
public enum ChairDirection
{
Up,
Down,
Left,
Right,
}
}

View file

@ -0,0 +1 @@
uid://0hfmpf6i0icv

View file

@ -5,7 +5,7 @@ namespace Cirno.Scripts.Resources.Events;
[GlobalClass]
public partial class DialogueStartEvent : EventResource
{
[Export] public string TimelineName = "timeline";
[Export] public StringName TimelineName = "timeline";
private Node _dialogic;
private GameManager _gameManager;
private bool _isComplete = false;
@ -27,7 +27,7 @@ public partial class DialogueStartEvent : EventResource
_dialogic.Connect("timeline_ended", Callable.From(OnTimelineEnded));
var dialogicNode =_dialogic.Call("start", TimelineName);
var dialogicNode =_dialogic.Call("start", TimelineName.ToString());
((Node)dialogicNode).ProcessMode = Node.ProcessModeEnum.Always;
_gameManager.ChangeState(GameState.Dialogue);
}