mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-09 23:45:55 +00:00
3D Cameras with sweep and animation
This commit is contained in:
parent
4cc7a0c004
commit
7e76edc153
48 changed files with 3211 additions and 1511 deletions
27
Scripts/Actors/3D/AlarmSoundPlayer3D.cs
Normal file
27
Scripts/Actors/3D/AlarmSoundPlayer3D.cs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Actors._3D;
|
||||
|
||||
public partial class AlarmSoundPlayer3D : AudioStreamPlayer3D
|
||||
{
|
||||
public override void _Ready()
|
||||
{
|
||||
if (AlarmManager.Instance is not null)
|
||||
{
|
||||
this.Stream = AlarmManager.Instance.AlarmSound;
|
||||
|
||||
AlarmManager.Instance.AlarmEnabled3D += InstanceOnAlarmEnabled3D;
|
||||
AlarmManager.Instance.AlarmDisabled += InstanceOnAlarmDisabled;
|
||||
}
|
||||
}
|
||||
|
||||
private void InstanceOnAlarmDisabled()
|
||||
{
|
||||
this.Stop();
|
||||
}
|
||||
|
||||
private void InstanceOnAlarmEnabled3D(Vector3 location)
|
||||
{
|
||||
this.Play();
|
||||
}
|
||||
}
|
||||
1
Scripts/Actors/3D/AlarmSoundPlayer3D.cs.uid
Normal file
1
Scripts/Actors/3D/AlarmSoundPlayer3D.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://0g2sdu48c2x8
|
||||
24
Scripts/Actors/3D/SecurityCamera3D.cs
Normal file
24
Scripts/Actors/3D/SecurityCamera3D.cs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Actors._3D;
|
||||
|
||||
public partial class SecurityCamera3D : Destructible3D
|
||||
{
|
||||
[Export] public StringName SweepAnimation { get; private set; } = "SweepLoop";
|
||||
|
||||
[Signal]
|
||||
public delegate void AnimationStartEventHandler(string animationName);
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
if (Engine.IsEditorHint()) return;
|
||||
EmitSignalAnimationStart(SweepAnimation);
|
||||
}
|
||||
|
||||
public void OnBodySighted(Node3D body)
|
||||
{
|
||||
if (Engine.IsEditorHint()) return;
|
||||
GD.Print($"{body.Name} Sighted!");
|
||||
AlarmManager.Instance?.SoundAlarm(this.GlobalPosition);
|
||||
}
|
||||
}
|
||||
1
Scripts/Actors/3D/SecurityCamera3D.cs.uid
Normal file
1
Scripts/Actors/3D/SecurityCamera3D.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dg3aho2ulfngs
|
||||
|
|
@ -74,42 +74,6 @@ public partial class Destructible3D : StaticBody3D, IDestructible
|
|||
explosion.Initialize(ExplosionData.MakeBullet(new Vector2(this.GlobalPosition.X, this.GlobalPosition.Y)));
|
||||
}
|
||||
|
||||
// private void ApplyExplosionDamage()
|
||||
// {
|
||||
// var spaceState = GetWorld2D().DirectSpaceState;
|
||||
// var query = new PhysicsShapeQueryParameters2D();
|
||||
// var shape = new CircleShape2D { Radius = ExplosionRadius };
|
||||
//
|
||||
// query.SetShape(shape);
|
||||
// query.Transform = new Transform2D(0, GlobalPosition);
|
||||
// query.CollideWithBodies = false;
|
||||
// query.CollideWithAreas = true;
|
||||
// //query.CollisionMask = ;
|
||||
//
|
||||
// var results = spaceState.IntersectShape(query);
|
||||
//
|
||||
// GD.Print($"Shapes in range: {results.Count}");
|
||||
//
|
||||
// foreach (var result in results)
|
||||
// {
|
||||
// if (result.TryGetValue("collider", out var colliderObj))
|
||||
// {
|
||||
//
|
||||
// var collider = colliderObj.As<Node2D>();
|
||||
//
|
||||
//
|
||||
// if (collider.GetParent<Area2D>() is IDestructible destructible)
|
||||
// {
|
||||
// GD.Print($"HITTING {collider.Name}");
|
||||
// destructible.Hit(ExplosionDamage);
|
||||
// }
|
||||
// else {
|
||||
// GD.Print($"Collider {collider.Name} was not idestructible");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
private void CreateDebris()
|
||||
{
|
||||
if (DebrisScene == null) return;
|
||||
|
|
|
|||
|
|
@ -23,20 +23,25 @@ public partial class AlarmManager : Node
|
|||
[Signal]
|
||||
public delegate void AlarmDisabledEventHandler();
|
||||
|
||||
private AudioStreamPlayer2D _player;
|
||||
//private AudioStreamPlayer _player;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Instance = this;
|
||||
|
||||
if (AlarmSound is not null)
|
||||
{
|
||||
var player = new AudioStreamPlayer2D();
|
||||
player.Stream = AlarmSound;
|
||||
this.CallDeferred("add_child", player);
|
||||
|
||||
_player = player;
|
||||
}
|
||||
// if (AlarmSound is not null)
|
||||
// {
|
||||
// var player = GetNodeOrNull<AudioStreamPlayer>("AlarmSoundPlayer");
|
||||
// if (player is not null)
|
||||
// {
|
||||
// player.Stream = AlarmSound;
|
||||
// _player = player;
|
||||
// }
|
||||
//
|
||||
// //this.CallDeferred("add_child", player);
|
||||
//
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
||||
public void SoundAlarm(Vector2 location)
|
||||
|
|
@ -47,7 +52,7 @@ public partial class AlarmManager : Node
|
|||
EmitSignalAlarmEnabled(location);
|
||||
|
||||
GD.Print($"Alarm sounded at {location}");
|
||||
_player?.Play();
|
||||
//_player?.Play();
|
||||
}
|
||||
|
||||
public void SoundAlarm(Vector3 location)
|
||||
|
|
@ -58,7 +63,7 @@ public partial class AlarmManager : Node
|
|||
EmitSignalAlarmEnabled3D(location);
|
||||
|
||||
GD.Print($"Alarm sounded at {location}");
|
||||
_player?.Play();
|
||||
//_player?.Play();
|
||||
}
|
||||
|
||||
public void SoundSilentAlarm(Vector2 location)
|
||||
|
|
@ -71,6 +76,6 @@ public partial class AlarmManager : Node
|
|||
{
|
||||
IsAlarmOn = false;
|
||||
EmitSignal(nameof(AlarmDisabled));
|
||||
_player?.Stop();
|
||||
//_player?.Stop();
|
||||
}
|
||||
}
|
||||
|
|
@ -5,35 +5,53 @@ namespace Cirno.Scripts.Interactables;
|
|||
[Tool]
|
||||
public partial class AlarmBox3D : Interactable3D
|
||||
{
|
||||
private AudioStreamPlayer _activationSound;
|
||||
private readonly string _activationSoundName = "ActivationSound";
|
||||
private AnimationPlayer _animationPlayer;
|
||||
public StringName FlashAnimationName { get; private set; } = "Flash";
|
||||
|
||||
[Signal] public delegate void OnActivatedEventHandler(ActivationType activationType);
|
||||
|
||||
[Signal]
|
||||
public delegate void PlayActivationSoundEventHandler();
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
if (Engine.IsEditorHint()) return;
|
||||
|
||||
_activationSound = GetNodeOrNull<AudioStreamPlayer>(_activationSoundName);
|
||||
_animationPlayer = GetNode<AnimationPlayer>("AnimationPlayer");
|
||||
|
||||
//CallDeferred(MethodName.InitDeferred);
|
||||
InitDeferred();
|
||||
}
|
||||
|
||||
private void InitDeferred()
|
||||
{
|
||||
if (AlarmManager.Instance is not null)
|
||||
{
|
||||
AlarmManager.Instance.AlarmEnabled3D += OnAlarmEnabled3D;
|
||||
AlarmManager.Instance.AlarmDisabled += InstanceOnAlarmDisabled;
|
||||
}
|
||||
}
|
||||
|
||||
private void InstanceOnAlarmDisabled()
|
||||
{
|
||||
_animationPlayer.Stop();
|
||||
}
|
||||
|
||||
private void OnAlarmEnabled3D(Vector3 location)
|
||||
{
|
||||
// TODO: set animation, make blinky
|
||||
GD.Print($"Enabled alarm in box {this.Name}");
|
||||
_animationPlayer.Play(FlashAnimationName);
|
||||
}
|
||||
|
||||
public override bool Activate(ActivationType activationType = ActivationType.Toggle)
|
||||
{
|
||||
EmitSignal(SignalName.OnActivated, (int)activationType);
|
||||
|
||||
EmitSignalPlayActivationSound();
|
||||
if (AlarmManager.Instance is not null)
|
||||
{
|
||||
_activationSound.Play();
|
||||
//_activationSound?.Play();
|
||||
|
||||
AlarmManager.Instance.DisableAlarm();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue