using Godot; using System; public partial class Cage : StaticBody2D { private Area2D probe; // probe to detect ghosts triggers private Area2D cageTrigger; // an area to tell other objects that it has collected a ghost private AnimatedSprite2D sprite; // animated sprite of cage private AudioStreamPlayer GhostCaged; //an audio track public bool activated; //if activated [Export] public bool red; //do you want it cherry flavored? [Export] // you can edit this in the inspector public Vector2 triggerPos; // where the trigger will get sent after a ghost is collected private void _on_probe_area_entered(Area2D area) { if (area.IsInGroup("Ghost")) // if probe detects a ghost's probe { cageTrigger.GlobalPosition = triggerPos; //sends trigger to specified position if(activated == false) { GhostCaged.Play(); area.GetParent().QueueFree(); //deletes the ghost RemoveFromGroup("Cage"); //the cage is no longer considered a cage for the ghost's collision checks activated = true; //activation animations can play } } } // Called when the node enters the scene tree for the first time. public override void _Ready() { //setting values that can't be preloaded probe = GetNode("Probe"); sprite = GetNode("CageSprite"); GhostCaged = GetNode("GhostCaged"); cageTrigger = GetNode("Trigger"); } // Called every frame. 'delta' is the elapsed time since the previous frame. public override void _Process(double delta) { animations(); } private void animations() { // animations for the cage are determined by it's activation, not a timer like the player or ghost if(red == false) { if (activated == true) { sprite.Play("Active"); } if (activated == false) { sprite.Play("Idle"); } } if(red == true) { if (activated == true) { sprite.Play("RedActive"); } if (activated == false) { sprite.Play("RedIdle"); } } } }