starfighter/MB_FYP/script/ship.cs

51 lines
1.3 KiB
C#
Raw Normal View History

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]
public int MaxSpeed { get; set;} = 300;
[Export]
public int MainSpeed { get; set; } = 10;
[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);
}
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();
}
}