54 lines
1.5 KiB
C#
54 lines
1.5 KiB
C#
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;
|
|
|
|
public override void _Ready()
|
|
{
|
|
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);
|
|
}
|
|
if (Input.IsActionPressed("rotate_left")){
|
|
ApplyTorque(ZLeft * fd);
|
|
}
|
|
if (Input.IsActionPressed("rotate_right")){
|
|
ApplyTorque(ZRight * fd);
|
|
}
|
|
}
|
|
|
|
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(){
|
|
GD.Print("Player crashed on the floor :(");
|
|
DeferredCalls.ReloadCurrentScene(this);
|
|
}
|
|
|
|
private void CompleteLevel(string nextLevel){
|
|
DeferredCalls.ChangeSceneToFile(this, nextLevel);
|
|
}
|
|
}
|