2024-08-15 17:12:48 +00:00
|
|
|
using System.Collections;
|
2024-08-15 14:40:37 +00:00
|
|
|
using Godot;
|
|
|
|
|
|
|
|
|
|
public partial class ship : CharacterBody2D
|
|
|
|
|
{
|
|
|
|
|
public enum ShipType { FIGHTER, INTERCEPTOR, GUARDIAN }
|
|
|
|
|
|
|
|
|
|
[Signal]
|
|
|
|
|
public delegate void LaserShotEventHandler(Area2D Laser);
|
|
|
|
|
|
|
|
|
|
//[Export]
|
|
|
|
|
//public Vector2 ScreenSize;
|
|
|
|
|
[Export]
|
2024-08-15 17:12:48 +00:00
|
|
|
public int Health { get; set; } = 100;
|
|
|
|
|
[Export]
|
|
|
|
|
public int MaxHealth { get; set; } = 100;
|
|
|
|
|
[Export]
|
2024-08-15 14:40:37 +00:00
|
|
|
public int MaxSpeed { get; set;} = 300;
|
|
|
|
|
[Export]
|
2024-08-15 17:12:48 +00:00
|
|
|
public int MainSpeed { get; set; } = 20;
|
2024-08-15 14:40:37 +00:00
|
|
|
[Export]
|
|
|
|
|
public int StrafeSpeed { get; set; } = 5;
|
|
|
|
|
[Export]
|
|
|
|
|
public float RotationSpeed { get; set; } = 2f;
|
|
|
|
|
[Export]
|
|
|
|
|
public ShipType type;
|
|
|
|
|
|
|
|
|
|
public Node2D LaserSpawn = null;
|
|
|
|
|
|
|
|
|
|
protected int _rotationDirection;
|
|
|
|
|
protected readonly PackedScene LaserScene = GD.Load<PackedScene>("res://scenes/laser.tscn");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public virtual void ShootLaser()
|
|
|
|
|
{
|
|
|
|
|
Node2D Laser = LaserScene.Instantiate<Node2D>();
|
|
|
|
|
Laser.Position = LaserSpawn.GlobalPosition;
|
|
|
|
|
Laser.Rotation = Rotation;
|
|
|
|
|
EmitSignal(SignalName.LaserShot, Laser);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-15 17:12:48 +00:00
|
|
|
public void SetShipStats()
|
|
|
|
|
{
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case ShipType.INTERCEPTOR:
|
|
|
|
|
MaxSpeed = 450;
|
|
|
|
|
MainSpeed = 35;
|
|
|
|
|
StrafeSpeed = 10;
|
|
|
|
|
RotationSpeed = 4f;
|
|
|
|
|
MaxHealth = 75;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ShipType.GUARDIAN:
|
|
|
|
|
MaxSpeed = 200;
|
|
|
|
|
MainSpeed = 10;
|
|
|
|
|
StrafeSpeed = 3;
|
|
|
|
|
RotationSpeed = 1f;
|
|
|
|
|
MaxHealth = 250;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void ShipDamage(int damage)
|
|
|
|
|
{
|
|
|
|
|
Health -= damage;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-15 14:40:37 +00:00
|
|
|
public override void _Ready()
|
|
|
|
|
{
|
|
|
|
|
//ScreenSize = GetViewportRect().Size;
|
|
|
|
|
LaserSpawn = GetNode<Node2D>("LaserSpawn");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void _PhysicsProcess(double delta)
|
|
|
|
|
{
|
|
|
|
|
// Common movement logic for all ships
|
|
|
|
|
Rotation += _rotationDirection * RotationSpeed * (float)delta;
|
|
|
|
|
Velocity.LimitLength(MaxSpeed);
|
|
|
|
|
|
|
|
|
|
MoveAndSlide();
|
|
|
|
|
}
|
|
|
|
|
}
|