2023-11-19 20:24:14 +00:00
|
|
|
using Godot;
|
|
|
|
|
using System;
|
|
|
|
|
|
2024-08-15 14:40:37 +00:00
|
|
|
public partial class player : ship // Inherits from base ship class
|
2023-11-19 20:24:14 +00:00
|
|
|
{
|
2024-08-15 14:40:37 +00:00
|
|
|
public enum ShipColor{RED, GREEN, BLUE}
|
2023-11-19 20:24:14 +00:00
|
|
|
|
2024-08-15 17:12:48 +00:00
|
|
|
[Signal]
|
|
|
|
|
public delegate void HealthUpdateEventHandler(int health);
|
|
|
|
|
|
2024-08-16 10:18:44 +00:00
|
|
|
[Signal]
|
|
|
|
|
public delegate void PlayerDeathEventHandler();
|
|
|
|
|
|
2024-08-15 14:40:37 +00:00
|
|
|
[Export]
|
2025-04-17 18:24:50 +00:00
|
|
|
public ShipColor color;
|
|
|
|
|
|
2024-08-15 21:55:44 +00:00
|
|
|
[Export]
|
|
|
|
|
public float FlightAssistValue { get; set; } = 2.5f;
|
|
|
|
|
|
2024-08-12 18:47:47 +00:00
|
|
|
public void GetInput()
|
|
|
|
|
{
|
|
|
|
|
/*LookAt(GetGlobalMousePosition()); //used for mouse-based rotation and movement
|
|
|
|
|
Velocity = Transform.X * Input.GetAxis("down", "up") * Speed;
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Movement, could probably move into its own methods instead of GetInput()
|
|
|
|
|
_rotationDirection = (int)Input.GetAxis("left", "right");
|
|
|
|
|
Velocity += (Transform.X * Input.GetAxis("strafe_left", "strafe_right") * StrafeSpeed) + (Transform.Y * Input.GetAxis("up", "down") * MainSpeed);
|
|
|
|
|
Velocity = Velocity.LimitLength(MaxSpeed);
|
2023-11-20 03:27:16 +00:00
|
|
|
|
2024-08-12 18:47:47 +00:00
|
|
|
//move into selection statement for toggling between fa off and on
|
|
|
|
|
if(Input.GetAxis("strafe_left", "strafe_right") == 0){
|
2024-08-15 21:55:44 +00:00
|
|
|
Velocity = Velocity.MoveToward(Vector2.Zero, FlightAssistValue);
|
2024-08-12 18:47:47 +00:00
|
|
|
}
|
|
|
|
|
else if(Input.GetAxis("down", "up") == 0){
|
2024-08-15 21:55:44 +00:00
|
|
|
Velocity = Velocity.MoveToward(Vector2.Zero, FlightAssistValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//FA toggle
|
|
|
|
|
if (Input.IsActionJustPressed("toggle_fa"))
|
|
|
|
|
{
|
|
|
|
|
ToggleFlightAssist();
|
2024-08-12 18:47:47 +00:00
|
|
|
}
|
|
|
|
|
}
|
2023-11-19 20:24:14 +00:00
|
|
|
|
2024-08-15 17:12:48 +00:00
|
|
|
public override void ShipDamage(int damage)
|
|
|
|
|
{
|
|
|
|
|
base.ShipDamage(damage);
|
|
|
|
|
EmitSignal(SignalName.HealthUpdate, Health);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-15 21:55:44 +00:00
|
|
|
public void ToggleFlightAssist()
|
|
|
|
|
{
|
|
|
|
|
if (FlightAssistValue == 0f){FlightAssistValue = 2.5f;}
|
|
|
|
|
else {FlightAssistValue = 0;}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-15 17:12:48 +00:00
|
|
|
public override void _Ready()
|
|
|
|
|
{
|
2025-04-17 18:24:50 +00:00
|
|
|
SetupVisual();
|
|
|
|
|
GD.Print(faction);
|
2024-08-15 14:40:37 +00:00
|
|
|
|
2025-04-17 18:24:50 +00:00
|
|
|
switch(color)
|
2024-08-15 14:40:37 +00:00
|
|
|
{
|
|
|
|
|
case ShipColor.RED:
|
2025-04-17 18:24:50 +00:00
|
|
|
this.spritePath = this.spritePath + "ShipRed.png";
|
2024-08-15 14:40:37 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ShipColor.GREEN:
|
2025-04-17 18:24:50 +00:00
|
|
|
this.spritePath = this.spritePath + "ShipGreen.png";
|
2024-08-15 14:40:37 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ShipColor.BLUE:
|
2025-04-17 18:24:50 +00:00
|
|
|
this.spritePath = this.spritePath + "ShipBlue.png";
|
2024-08-15 14:40:37 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
GD.Print(spritePath);
|
|
|
|
|
Sprite.Texture = GD.Load<Texture2D>(spritePath);
|
|
|
|
|
|
|
|
|
|
|
2024-08-12 18:47:47 +00:00
|
|
|
LaserSpawn = GetNode<Node2D>("LaserSpawn");
|
2024-08-15 17:12:48 +00:00
|
|
|
//Connect("body_entered" +=)
|
|
|
|
|
SetShipStats();
|
|
|
|
|
Health = MaxHealth;
|
|
|
|
|
EmitSignal(SignalName.HealthUpdate, Health);
|
2024-08-12 18:47:47 +00:00
|
|
|
}
|
2023-11-19 20:24:14 +00:00
|
|
|
|
2024-08-12 18:47:47 +00:00
|
|
|
public override void _Process(double delta)
|
|
|
|
|
{
|
|
|
|
|
if(Input.IsActionJustPressed("shoot"))
|
|
|
|
|
{
|
|
|
|
|
ShootLaser();
|
|
|
|
|
}
|
2024-08-15 17:12:48 +00:00
|
|
|
|
2024-08-16 10:18:44 +00:00
|
|
|
if (Health <= 0)
|
2024-08-15 17:12:48 +00:00
|
|
|
{
|
2024-08-16 10:18:44 +00:00
|
|
|
EmitSignal(SignalName.PlayerDeath);
|
2024-08-15 17:12:48 +00:00
|
|
|
}
|
|
|
|
|
|
2024-08-12 18:47:47 +00:00
|
|
|
}
|
|
|
|
|
public override void _PhysicsProcess(double delta)
|
|
|
|
|
{ // every frame
|
|
|
|
|
GetInput();
|
|
|
|
|
Rotation += _rotationDirection * RotationSpeed * (float)delta;
|
|
|
|
|
Velocity.LimitLength(MaxSpeed);
|
2025-04-18 01:07:51 +00:00
|
|
|
|
|
|
|
|
//GD.Print(MainSpeed);
|
|
|
|
|
//GD.Print("v ",Velocity, "v");
|
|
|
|
|
GD.Print(Name, ": MainSpeed = ", MainSpeed, " Velocity = ", Velocity.Length());
|
2024-08-12 18:47:47 +00:00
|
|
|
|
|
|
|
|
MoveAndSlide();
|
2023-11-20 03:27:16 +00:00
|
|
|
|
2024-08-12 18:47:47 +00:00
|
|
|
/*
|
|
|
|
|
if (Position.Y < 0) {Position = new Vector2(Position.X, ScreenSize.Y);}
|
|
|
|
|
if (Position.Y > ScreenSize.Y) {Position = new Vector2(Position.X, 0);}
|
|
|
|
|
if (Position.X < 0) { Position = new Vector2(ScreenSize.X, Position.Y);}
|
|
|
|
|
if (Position.X > ScreenSize.X) { Position = new Vector2(0, Position.Y);}
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
}
|