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-19 22:24:46 +00:00
|
|
|
public ShipColor Color;
|
2025-04-17 18:24:50 +00:00
|
|
|
|
2024-08-15 21:55:44 +00:00
|
|
|
[Export]
|
|
|
|
|
public float FlightAssistValue { get; set; } = 2.5f;
|
|
|
|
|
|
2025-04-21 19:03:51 +00:00
|
|
|
private float _angularVelocity;
|
|
|
|
|
private float _angularAccel = 0.3f;
|
|
|
|
|
|
2025-04-18 23:21:19 +00:00
|
|
|
|
2025-04-19 22:24:46 +00:00
|
|
|
private void GetInput()
|
2024-08-12 18:47:47 +00:00
|
|
|
{
|
|
|
|
|
/*LookAt(GetGlobalMousePosition()); //used for mouse-based rotation and movement
|
|
|
|
|
Velocity = Transform.X * Input.GetAxis("down", "up") * Speed;
|
|
|
|
|
*/
|
2025-04-21 19:03:51 +00:00
|
|
|
|
2024-08-12 18:47:47 +00:00
|
|
|
// Movement, could probably move into its own methods instead of GetInput()
|
2025-04-19 22:24:46 +00:00
|
|
|
RotationDirection = (int)Input.GetAxis("left", "right");
|
2025-04-21 19:03:51 +00:00
|
|
|
_angularVelocity += RotationDirection * _angularAccel;
|
|
|
|
|
_angularVelocity = Mathf.Clamp(_angularVelocity, -RotationSpeed, RotationSpeed);
|
|
|
|
|
|
|
|
|
|
if (RotationDirection == 0 && FlightAssistValue > 0f)
|
|
|
|
|
{
|
|
|
|
|
_angularVelocity = Mathf.MoveToward(_angularVelocity, 0f, FlightAssistValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//GD.Print(RotationDirection);
|
2024-08-12 18:47:47 +00:00
|
|
|
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);
|
2025-04-19 22:24:46 +00:00
|
|
|
|
|
|
|
|
if (Health <= 0)
|
|
|
|
|
{
|
|
|
|
|
EmitSignal(SignalName.PlayerDeath);
|
|
|
|
|
}
|
2024-08-15 17:12:48 +00:00
|
|
|
}
|
|
|
|
|
|
2025-04-22 04:43:03 +00:00
|
|
|
public void HealShip(int health)
|
|
|
|
|
{
|
|
|
|
|
Health += health;
|
|
|
|
|
if (Health > MaxHealth) Health = MaxHealth;
|
2025-04-23 04:33:38 +00:00
|
|
|
EmitSignal(SignalName.HealthUpdate, Health);
|
2025-04-22 04:43:03 +00:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-23 04:33:38 +00:00
|
|
|
public void HealthUpgrade() // sets health stats (upgrades)
|
|
|
|
|
{
|
|
|
|
|
MaxHealth = (int)(MaxHealth * 1.1f);
|
|
|
|
|
Health = MaxHealth;;
|
|
|
|
|
EmitSignal(SignalName.HealthUpdate, Health);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DamageUpgrade() // sets new damage stat (upgrades)
|
|
|
|
|
{
|
|
|
|
|
Damage = (int)(Damage * 1.1f);;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SpeedUpgrade() // sets new speed stats (upgrades)
|
|
|
|
|
{
|
|
|
|
|
MaxSpeed = (int)(MaxSpeed * 1.1f);
|
|
|
|
|
MainSpeed = (int)(MainSpeed * 1.1f);
|
|
|
|
|
StrafeSpeed = (int)(StrafeSpeed * 1.1f);
|
|
|
|
|
RotationSpeed = RotationSpeed * 1.1f;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-19 22:24:46 +00:00
|
|
|
private void ToggleFlightAssist()
|
2024-08-15 21:55:44 +00:00
|
|
|
{
|
|
|
|
|
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();
|
2025-04-23 04:33:38 +00:00
|
|
|
//GD.Print(Faction);
|
2024-08-15 14:40:37 +00:00
|
|
|
|
2025-04-19 22:33:53 +00:00
|
|
|
this.SpritePath = Color switch
|
2024-08-15 14:40:37 +00:00
|
|
|
{
|
2025-04-19 22:33:53 +00:00
|
|
|
ShipColor.RED => this.SpritePath + "ShipRed.png",
|
|
|
|
|
ShipColor.GREEN => this.SpritePath + "ShipGreen.png",
|
|
|
|
|
ShipColor.BLUE => this.SpritePath + "ShipBlue.png",
|
|
|
|
|
_ => this.SpritePath
|
2025-04-19 22:24:46 +00:00
|
|
|
};
|
2025-04-23 04:33:38 +00:00
|
|
|
//GD.Print(SpritePath);
|
2025-04-19 22:33:53 +00:00
|
|
|
Sprite.Texture = GD.Load<Texture2D>(SpritePath);
|
2024-08-15 14:40:37 +00:00
|
|
|
|
|
|
|
|
|
2024-08-12 18:47:47 +00:00
|
|
|
LaserSpawn = GetNode<Node2D>("LaserSpawn");
|
2024-08-15 17:12:48 +00:00
|
|
|
//Connect("body_entered" +=)
|
2025-04-22 04:43:03 +00:00
|
|
|
StatModifier = 1.3f;
|
2024-08-15 17:12:48 +00:00
|
|
|
SetShipStats();
|
2025-04-22 04:43:03 +00:00
|
|
|
MaxHealth *= 4; // quadruple player health (balancing)
|
2024-08-15 17:12:48 +00:00
|
|
|
Health = MaxHealth;
|
2025-04-22 04:43:03 +00:00
|
|
|
Damage *= 2; // double player damage (balancing)
|
2024-08-15 17:12:48 +00:00
|
|
|
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)
|
|
|
|
|
{
|
2025-04-19 22:33:53 +00:00
|
|
|
FireTimer -= (float)delta;
|
2025-04-18 23:21:19 +00:00
|
|
|
|
2025-04-19 22:24:46 +00:00
|
|
|
if(Input.IsActionPressed("shoot"))
|
2024-08-12 18:47:47 +00:00
|
|
|
{
|
2025-04-23 04:33:38 +00:00
|
|
|
//GD.Print("DEBUG: FIRING PLAYER LASER");
|
2025-04-19 22:33:53 +00:00
|
|
|
if (FireTimer > 0f) return;
|
2024-08-12 18:47:47 +00:00
|
|
|
ShootLaser();
|
2025-04-19 22:33:53 +00:00
|
|
|
FireTimer = FireCooldown;
|
2024-08-12 18:47:47 +00:00
|
|
|
}
|
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();
|
2025-04-21 19:03:51 +00:00
|
|
|
Rotation += _angularVelocity * (float)delta;
|
2024-08-12 18:47:47 +00:00
|
|
|
Velocity.LimitLength(MaxSpeed);
|
2025-04-18 01:07:51 +00:00
|
|
|
|
|
|
|
|
//GD.Print(MainSpeed);
|
|
|
|
|
//GD.Print("v ",Velocity, "v");
|
2025-04-18 23:21:19 +00:00
|
|
|
//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);}
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
}
|