Forcefield Shader

This commit is contained in:
MaddoScientisto 2025-02-23 01:24:29 +01:00
commit f23d84071a
9 changed files with 210 additions and 14 deletions

View file

@ -0,0 +1,52 @@
using Godot;
using System;
using Cirno.Scripts;
using System.Threading.Tasks;
public partial class ForceField : Door
{
[Export]
public Shader TurnOffShader { get; private set; }
[Export]
public Shader ActiveShader { get; private set; }
// Disable
public override void Open()
{
base.Open();
if (TurnOffShader is null) return;
((ShaderMaterial)_animatedSprite.Material).Shader = TurnOffShader;
_ = AnimateShutdownAsync();
}
protected async Task AnimateShutdownAsync()
{
Tween tween = GetTree().CreateTween();
tween.TweenMethod(Callable.From((float value) => SetShaderScanlineDensity(value)), 0f, 50f, 0.5);
tween.Parallel().TweenMethod(Callable.From((float value) => SetShaderTeleportProgress(value)), 0f, 1f, 0.5);
await ToSignal(tween, "finished");
}
// Enable
public override void Close()
{
base.Close();
if (ActiveShader is null) return;
((ShaderMaterial)_animatedSprite.Material).Shader = ActiveShader;
}
private void SetShaderTeleportProgress(float value)
{
((ShaderMaterial)_animatedSprite.Material).SetShaderParameter("teleport_progress", value);
}
private void SetShaderScanlineDensity(float value)
{
((ShaderMaterial)_animatedSprite.Material).SetShaderParameter("scanline_density", value);
}
}

View file

@ -5,9 +5,9 @@ using Cirno.Scripts;
public partial class Door : Activable
{
private AnimatedSprite2D _animatedSprite;
private CollisionShape2D _collisionShape;
private CollisionShape2D _solidShape;
protected AnimatedSprite2D _animatedSprite;
protected CollisionShape2D _collisionShape;
protected CollisionShape2D _solidShape;
// Called when the node enters the scene tree for the first time.
[Export]
@ -27,7 +27,7 @@ public partial class Door : Activable
{
}
public void Open()
public virtual void Open()
{
_animatedSprite.Play("Opening");
State = DoorState.Open;
@ -36,7 +36,7 @@ public partial class Door : Activable
//_solidShape.Disabled = true;
}
public void Close()
public virtual void Close()
{
_animatedSprite.Play("Closing");
State = DoorState.Closed;