using Godot; using System; public partial class Player : RigidBody3D { [Export(PropertyHint.Range, "750.0, 3000.0")] float thrust = 1000.0f; // The amount of thrust the players has, in newtons [Export(PropertyHint.Range, "50.0, 200.0")] float torque = 100.0f; // The amount of torque the player has, in newton meters private Vector3 ZLeft; private Vector3 ZRight; private GpuParticles3D boosterParticles; private GpuParticles3D boosterLeftParticles; private GpuParticles3D boosterRightParticles; private GpuParticles3D explosionParticles; private GpuParticles3D successParticles; private AudioStreamPlayer deathAudioPlayer; private AudioStreamPlayer successAudioPlayer; private AudioStreamPlayer3D rocketAudioPlayer; public override void _Ready() { boosterParticles = GetNode("BoosterParticles"); boosterLeftParticles = GetNode("BoosterLeftParticles"); boosterRightParticles = GetNode("BoosterRightParticles"); explosionParticles = GetNode("ExplosionParticles"); successParticles = GetNode("SuccessParticles"); deathAudioPlayer = GetNode("DeathAudioPlayer"); successAudioPlayer = GetNode("SuccessAudioPlayer"); rocketAudioPlayer = GetNode("RocketAudioPlayer"); BodyEntered += OnPlayerCollision; ZLeft = new Vector3(0, 0, torque); ZRight = new Vector3(0, 0, -torque); } public override void _Process(double delta) { float fd = (float)delta; if (Input.IsActionPressed("boost")){ ApplyCentralForce(Basis.Y * fd * thrust); boosterParticles.Emitting = true; if (!rocketAudioPlayer.Playing){ rocketAudioPlayer.Play(); } } else { rocketAudioPlayer.Stop(); boosterParticles.Emitting = false; } if (Input.IsActionPressed("rotate_left")){ ApplyTorque(ZLeft * fd); boosterLeftParticles.Emitting = true; } else { boosterLeftParticles.Emitting = false; } if (Input.IsActionPressed("rotate_right")){ ApplyTorque(ZRight * fd); boosterRightParticles.Emitting = true; } else { boosterRightParticles.Emitting = false; } if (Input.IsActionPressed("ui_cancel")){ GetTree().Quit(); } } private void OnPlayerCollision(Node body) { if (body.GetGroups().Contains("Goal") && body is LandingPad) { LandingPad landingPad = (LandingPad)body; CompleteLevel(landingPad.nextLevel); } if (body.GetGroups().Contains("Hazard")) { CrashSequence(); } } private void CrashSequence(){ deathAudioPlayer.Play(); rocketAudioPlayer.Stop(); boosterParticles.Emitting = false; explosionParticles.Emitting = true; Tween tween = CreateTween(); tween.TweenInterval(2.5); tween.TweenCallback(Callable.From(() => DeferredCalls.ReloadCurrentScene(this))); SetProcess(false); BodyEntered -= OnPlayerCollision; } private void CompleteLevel(string nextLevel){ successAudioPlayer.Play(); successParticles.Emitting = true; Tween tween = CreateTween(); tween.TweenInterval(2.3); tween.TweenCallback(Callable.From(() => DeferredCalls.ChangeSceneToFile(this, nextLevel))); } }