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 14:40:37 +00:00
|
|
|
[Export]
|
|
|
|
|
public ShipColor color;
|
2023-11-20 09:35:59 +00:00
|
|
|
|
2024-08-15 14:40:37 +00:00
|
|
|
public Sprite2D Sprite = new Sprite2D();
|
2023-11-19 20:24:14 +00:00
|
|
|
|
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){
|
|
|
|
|
Velocity = Velocity.MoveToward(Vector2.Zero, 1.5f);
|
|
|
|
|
}
|
|
|
|
|
else if(Input.GetAxis("down", "up") == 0){
|
|
|
|
|
Velocity = Velocity.MoveToward(Vector2.Zero, 1.5f);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-19 20:24:14 +00:00
|
|
|
|
2024-08-12 18:47:47 +00:00
|
|
|
public override void _Ready()
|
|
|
|
|
{
|
2024-08-15 14:40:37 +00:00
|
|
|
Sprite = GetNode<Sprite2D>("ShipSprite");
|
|
|
|
|
string spritePath = "";
|
|
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case ShipType.FIGHTER:
|
|
|
|
|
spritePath = "res://assets/Player/Fighter/";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ShipType.INTERCEPTOR:
|
|
|
|
|
spritePath = "res://assets/Player/Interceptor/";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ShipType.GUARDIAN:
|
|
|
|
|
spritePath = "res://assets/Player/Guardian/";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch(color)
|
|
|
|
|
{
|
|
|
|
|
case ShipColor.RED:
|
|
|
|
|
spritePath = spritePath + "ShipRed.png";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ShipColor.GREEN:
|
|
|
|
|
spritePath = spritePath + "ShipGreen.png";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ShipColor.BLUE:
|
|
|
|
|
spritePath = spritePath + "ShipBlue.png";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
GD.Print(spritePath);
|
|
|
|
|
Sprite.Texture = GD.Load<Texture2D>(spritePath);
|
|
|
|
|
|
|
|
|
|
|
2024-08-12 18:47:47 +00:00
|
|
|
LaserSpawn = GetNode<Node2D>("LaserSpawn");
|
|
|
|
|
}
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public override void _PhysicsProcess(double delta)
|
|
|
|
|
{ // every frame
|
|
|
|
|
GetInput();
|
|
|
|
|
Rotation += _rotationDirection * RotationSpeed * (float)delta;
|
|
|
|
|
Velocity.LimitLength(MaxSpeed);
|
|
|
|
|
|
|
|
|
|
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);}
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
}
|