using System.Collections.Generic; using System.ComponentModel; using System.Linq; using Godot; using Godot.Bridge; using Godot.NativeInterop; [ScriptPath("res://Scripts/Slide.cs")] public partial class Slide : Area2D { private AudioStreamPlayer sound; private List areas = new List(); public override void _EnterTree() { base.BodyEntered += Enter; base.BodyExited += Exit; foreach (Node child in GetChildren()) { areas.Add((Node2D)child); } if (sound == null) { AudioStreamPlayer obj = new AudioStreamPlayer { Stream = GD.Load("res://Audio/Sounds/slide.wav"), Bus = "Sound", VolumeDb = Mathf.LinearToDb(1.5f) }; AudioStreamPlayer node = obj; sound = obj; AddChild(node, forceReadableName: false, InternalMode.Disabled); } } private void Enter(Node other) { if (other is Player) { Node2D[] array = areas.OrderBy((Node2D x) => x.GlobalPosition.DistanceSquaredTo(Player.instance.controlling.GlobalPosition)).ToArray(); if (Player.instance.GlobalPosition.Y < array[0].GlobalPosition.Y) { Audio.PlaySound("snd_noise.wav", 0.8f); sound.Play(); Player.instance.controlling.currentAnim = Entity.Animations.Slide; Player.instance.controlling.UpdateAnim(force: true); Player.instance.UpdateOverlay(); } Player.instance.slide = this; } } private void Exit(Node other) { if (other is Player && Player.instance.slide == this) { Player.instance.slide = null; Player.instance.ResetFollowStep(); Player.instance.LookAt(Vector2.Down); sound.Stop(); } } }