using Godot; using System; public partial class player : ship // Inherits from base ship class { public enum ShipColor{RED, GREEN, BLUE} [Signal] public delegate void HealthUpdateEventHandler(int health); [Signal] public delegate void PlayerDeathEventHandler(); [Export] public ShipColor color; [Export] public float FlightAssistValue { get; set; } = 2.5f; 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); //move into selection statement for toggling between fa off and on if(Input.GetAxis("strafe_left", "strafe_right") == 0){ Velocity = Velocity.MoveToward(Vector2.Zero, FlightAssistValue); } else if(Input.GetAxis("down", "up") == 0){ Velocity = Velocity.MoveToward(Vector2.Zero, FlightAssistValue); } //FA toggle if (Input.IsActionJustPressed("toggle_fa")) { ToggleFlightAssist(); } } public override void ShipDamage(int damage) { base.ShipDamage(damage); EmitSignal(SignalName.HealthUpdate, Health); } public void ToggleFlightAssist() { if (FlightAssistValue == 0f){FlightAssistValue = 2.5f;} else {FlightAssistValue = 0;} } public override void _Ready() { SetupVisual(); GD.Print(faction); switch(color) { case ShipColor.RED: this.spritePath = this.spritePath + "ShipRed.png"; break; case ShipColor.GREEN: this.spritePath = this.spritePath + "ShipGreen.png"; break; case ShipColor.BLUE: this.spritePath = this.spritePath + "ShipBlue.png"; break; } GD.Print(spritePath); Sprite.Texture = GD.Load(spritePath); LaserSpawn = GetNode("LaserSpawn"); //Connect("body_entered" +=) SetShipStats(); Health = MaxHealth; EmitSignal(SignalName.HealthUpdate, Health); } public override void _Process(double delta) { if(Input.IsActionJustPressed("shoot")) { ShootLaser(); } if (Health <= 0) { EmitSignal(SignalName.PlayerDeath); } } public override void _PhysicsProcess(double delta) { // every frame GetInput(); Rotation += _rotationDirection * RotationSpeed * (float)delta; Velocity.LimitLength(MaxSpeed); MoveAndSlide(); /* 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);} */ } }