mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-10 18:25:54 +00:00
Spinning chairs
This commit is contained in:
parent
e41fd125de
commit
72ce9fb932
16 changed files with 290 additions and 24 deletions
56
Scripts/Actors/Chair.cs
Normal file
56
Scripts/Actors/Chair.cs
Normal 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,
|
||||
}
|
||||
}
|
||||
|
||||
1
Scripts/Actors/Chair.cs.uid
Normal file
1
Scripts/Actors/Chair.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://0hfmpf6i0icv
|
||||
Loading…
Add table
Add a link
Reference in a new issue