mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-13 16:25:53 +00:00
Modularized doors and lightbridges
This commit is contained in:
parent
1a24711984
commit
1a5bd1b6d8
27 changed files with 513 additions and 346 deletions
29
Scripts/Components/Actors/DoorSpriteComponent.cs
Normal file
29
Scripts/Components/Actors/DoorSpriteComponent.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.Actors;
|
||||
|
||||
public partial class DoorSpriteComponent : AnimatedSprite2D
|
||||
{
|
||||
protected Door _door;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
|
||||
_door = GetParent<Door>();
|
||||
|
||||
_door.DoorOpened += DoorOpened;
|
||||
_door.DoorClosed += DoorClosed;
|
||||
}
|
||||
|
||||
protected virtual void DoorClosed()
|
||||
{
|
||||
this.Play("Closing");
|
||||
}
|
||||
|
||||
protected virtual void DoorOpened()
|
||||
{
|
||||
this.Play("Opening");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
1
Scripts/Components/Actors/DoorSpriteComponent.cs.uid
Normal file
1
Scripts/Components/Actors/DoorSpriteComponent.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bbuhaam28lwld
|
||||
39
Scripts/Components/Actors/ForceFieldCollisionDisabler.cs
Normal file
39
Scripts/Components/Actors/ForceFieldCollisionDisabler.cs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.Actors;
|
||||
|
||||
public partial class ForceFieldCollisionDisabler : CollisionShape2D
|
||||
{
|
||||
[Export]
|
||||
protected Door _door;
|
||||
|
||||
[Export]
|
||||
public bool Invert { get; private set; } = false;
|
||||
public override void _Ready()
|
||||
{
|
||||
//_door = GetParent<Door>();
|
||||
|
||||
_door.DoorOpened += DoorOpened;
|
||||
_door.DoorClosed += DoorClosed;
|
||||
}
|
||||
|
||||
protected virtual void DoorClosed()
|
||||
{
|
||||
CallDeferred(MethodName.Enable);
|
||||
}
|
||||
|
||||
private void Disable()
|
||||
{
|
||||
this.Disabled = !Invert;
|
||||
}
|
||||
|
||||
protected virtual void DoorOpened()
|
||||
{
|
||||
CallDeferred(MethodName.Disable);
|
||||
}
|
||||
|
||||
private void Enable()
|
||||
{
|
||||
this.Disabled = Invert;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://crpkvxepkcrir
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.Actors;
|
||||
|
||||
public partial class ForceFieldMaterialAnimationHandler : Node2D
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://dmi8k8ogkwogi
|
||||
48
Scripts/Components/Actors/ForceFieldSpriteComponent.cs
Normal file
48
Scripts/Components/Actors/ForceFieldSpriteComponent.cs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
using System.Threading.Tasks;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.Actors;
|
||||
|
||||
public partial class ForceFieldSpriteComponent : DoorSpriteComponent
|
||||
{
|
||||
[Export]
|
||||
public Material TurnOffMaterial { get; private set; }
|
||||
|
||||
[Export]
|
||||
public Material ActiveMaterial { get; private set; }
|
||||
|
||||
protected override void DoorOpened()
|
||||
{
|
||||
base.DoorOpened();
|
||||
if (TurnOffMaterial is null) return;
|
||||
|
||||
this.Material = TurnOffMaterial;
|
||||
_ = AnimateShutdownAsync();
|
||||
}
|
||||
|
||||
protected override void DoorClosed()
|
||||
{
|
||||
base.DoorClosed();
|
||||
if (ActiveMaterial is null) return;
|
||||
this.Material = ActiveMaterial;
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
private void SetShaderTeleportProgress(float value)
|
||||
{
|
||||
((ShaderMaterial)this.Material).SetShaderParameter("teleport_progress", value);
|
||||
}
|
||||
|
||||
private void SetShaderScanlineDensity(float value)
|
||||
{
|
||||
((ShaderMaterial)this.Material).SetShaderParameter("scanline_density", value);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://cvsrm74jftau8
|
||||
57
Scripts/Components/Actors/LightBridgeSpriteComponent.cs
Normal file
57
Scripts/Components/Actors/LightBridgeSpriteComponent.cs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
using System.Threading.Tasks;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.Actors;
|
||||
|
||||
public partial class LightBridgeSpriteComponent : Sprite2D
|
||||
{
|
||||
[Export]
|
||||
public Material TurnOffMaterial { get; private set; }
|
||||
|
||||
[Export]
|
||||
public Material ActiveMaterial { get; private set; }
|
||||
|
||||
protected Door _door;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
|
||||
_door = GetParent<Door>();
|
||||
|
||||
_door.DoorOpened += DoorOpened;
|
||||
_door.DoorClosed += DoorClosed;
|
||||
}
|
||||
|
||||
protected virtual void DoorOpened()
|
||||
{
|
||||
if (TurnOffMaterial is null) return;
|
||||
|
||||
this.Material = TurnOffMaterial;
|
||||
_ = AnimateShutdownAsync();
|
||||
}
|
||||
|
||||
protected virtual void DoorClosed()
|
||||
{
|
||||
if (ActiveMaterial is null) return;
|
||||
this.Material = ActiveMaterial;
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
private void SetShaderTeleportProgress(float value)
|
||||
{
|
||||
((ShaderMaterial)this.Material).SetShaderParameter("teleport_progress", value);
|
||||
}
|
||||
|
||||
private void SetShaderScanlineDensity(float value)
|
||||
{
|
||||
((ShaderMaterial)this.Material).SetShaderParameter("scanline_density", value);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://cwnfsmogt11mn
|
||||
|
|
@ -15,6 +15,8 @@ public partial class PlayerDamageReceiver : Area2D
|
|||
private ActorResourceProvider _healthProvider;
|
||||
[Export]
|
||||
private ActorResourceProvider _shieldProvider;
|
||||
|
||||
[Export] public StringName AcidGroupName { get; private set; } = "Acid";
|
||||
|
||||
[Signal]
|
||||
public delegate void HealthChangedEventHandler(float newValue, float maxValue);
|
||||
|
|
@ -88,10 +90,23 @@ public partial class PlayerDamageReceiver : Area2D
|
|||
{
|
||||
if (!Enabled) return;
|
||||
if (Invulnerable) return;
|
||||
if (area.IsInGroup(AcidGroupName))
|
||||
{
|
||||
// Handle acid death
|
||||
AcidDeath();
|
||||
return;
|
||||
}
|
||||
if (area is not Bullet bullet || bullet.BulletOwner == BulletGroup) return;
|
||||
this.Hit(bullet.Damage, bullet.DamageType);
|
||||
bullet.RequestCollisionDestruction();
|
||||
}
|
||||
|
||||
private void AcidDeath()
|
||||
{
|
||||
if (!Enabled) return;
|
||||
GD.Print("Acid death");
|
||||
_healthProvider.CurrentResource = 0;
|
||||
}
|
||||
|
||||
public void Hit(float damage, DamageType type = DamageType.Neutral)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue