add flight assist toggle and corresponding label for it
This commit is contained in:
parent
c942179ebd
commit
b9c05c7ac3
|
|
@ -16,7 +16,6 @@ script = ExtResource("1_dukjm")
|
||||||
position = Vector2(800, 450)
|
position = Vector2(800, 450)
|
||||||
scale = Vector2(0.6, 0.6)
|
scale = Vector2(0.6, 0.6)
|
||||||
collision_layer = 8
|
collision_layer = 8
|
||||||
color = 1
|
|
||||||
type = 1
|
type = 1
|
||||||
|
|
||||||
[node name="Lasers" type="Node" parent="."]
|
[node name="Lasers" type="Node" parent="."]
|
||||||
|
|
|
||||||
|
|
@ -27,3 +27,12 @@ offset_right = 384.0
|
||||||
offset_bottom = 167.0
|
offset_bottom = 167.0
|
||||||
text = "Health:"
|
text = "Health:"
|
||||||
label_settings = ExtResource("2_ns78v")
|
label_settings = ExtResource("2_ns78v")
|
||||||
|
|
||||||
|
[node name="FlightAssist" type="Label" parent="."]
|
||||||
|
layout_mode = 0
|
||||||
|
offset_left = 19.0
|
||||||
|
offset_top = 174.0
|
||||||
|
offset_right = 226.0
|
||||||
|
offset_bottom = 237.0
|
||||||
|
text = "FA: ON"
|
||||||
|
label_settings = ExtResource("2_ns78v")
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ public partial class game : Node2D
|
||||||
|
|
||||||
public Label HealthLabel = null;
|
public Label HealthLabel = null;
|
||||||
|
|
||||||
|
public Label FlightAssistLabel = null;
|
||||||
|
|
||||||
public hud h;
|
public hud h;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -24,6 +26,7 @@ public partial class game : Node2D
|
||||||
{
|
{
|
||||||
HUD = GetNode<Control>("UI/HUD");
|
HUD = GetNode<Control>("UI/HUD");
|
||||||
ScoreLabel = GetNode<Label>("UI/HUD/Score");
|
ScoreLabel = GetNode<Label>("UI/HUD/Score");
|
||||||
|
FlightAssistLabel = GetNode<Label>("UI/HUD/FlightAssist");
|
||||||
//HealthLabel = GetNode<Label>("UI/HUD/Health");
|
//HealthLabel = GetNode<Label>("UI/HUD/Health");
|
||||||
|
|
||||||
Asteroids = GetNode<Node>("Asteroids");
|
Asteroids = GetNode<Node>("Asteroids");
|
||||||
|
|
@ -45,6 +48,11 @@ public partial class game : Node2D
|
||||||
{
|
{
|
||||||
GetTree().ReloadCurrentScene();
|
GetTree().ReloadCurrentScene();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Input.IsActionJustPressed("toggle_fa"))
|
||||||
|
{
|
||||||
|
UpdateFALabel();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SpawnAsteroid(Vector2 position, int size)
|
public void SpawnAsteroid(Vector2 position, int size)
|
||||||
|
|
@ -76,6 +84,13 @@ public partial class game : Node2D
|
||||||
HealthLabel.Text = "HEALTH: " + health.ToString();
|
HealthLabel.Text = "HEALTH: " + health.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void UpdateFALabel()
|
||||||
|
{
|
||||||
|
// Bit of a hacky implementation I think, but it works.
|
||||||
|
if (FlightAssistLabel.Text == "FA: OFF"){FlightAssistLabel.Text = "FA: ON";}
|
||||||
|
else if (FlightAssistLabel.Text == "FA: ON"){FlightAssistLabel.Text = "FA: OFF";}
|
||||||
|
}
|
||||||
|
|
||||||
//Signals and Connections
|
//Signals and Connections
|
||||||
public void OnPlayerLaserShot(Area2D Laser)
|
public void OnPlayerLaserShot(Area2D Laser)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,15 @@ using System;
|
||||||
public partial class hud : Control
|
public partial class hud : Control
|
||||||
{
|
{
|
||||||
public Label Score = new();
|
public Label Score = new();
|
||||||
|
public Label FlightAssist = new();
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
Score = GetNode<Label>("Score");
|
Score = GetNode<Label>("Score");
|
||||||
Score.Text = "SCORE: 0";
|
Score.Text = "SCORE: 0";
|
||||||
|
// Keeping health being initialised in game.cs
|
||||||
|
|
||||||
|
FlightAssist = GetNode<Label>("FlightAssist");
|
||||||
|
FlightAssist.Text = "FA: ON"; // Should be on by default
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -9,10 +9,13 @@ public partial class player : ship // Inherits from base ship class
|
||||||
public delegate void HealthUpdateEventHandler(int health);
|
public delegate void HealthUpdateEventHandler(int health);
|
||||||
|
|
||||||
[Export]
|
[Export]
|
||||||
public ShipColor color;
|
public ShipColor Color;
|
||||||
|
|
||||||
public Sprite2D Sprite = new Sprite2D();
|
public Sprite2D Sprite = new Sprite2D();
|
||||||
|
|
||||||
|
[Export]
|
||||||
|
public float FlightAssistValue { get; set; } = 2.5f;
|
||||||
|
|
||||||
public void GetInput()
|
public void GetInput()
|
||||||
{
|
{
|
||||||
/*LookAt(GetGlobalMousePosition()); //used for mouse-based rotation and movement
|
/*LookAt(GetGlobalMousePosition()); //used for mouse-based rotation and movement
|
||||||
|
|
@ -26,10 +29,16 @@ public partial class player : ship // Inherits from base ship class
|
||||||
|
|
||||||
//move into selection statement for toggling between fa off and on
|
//move into selection statement for toggling between fa off and on
|
||||||
if(Input.GetAxis("strafe_left", "strafe_right") == 0){
|
if(Input.GetAxis("strafe_left", "strafe_right") == 0){
|
||||||
Velocity = Velocity.MoveToward(Vector2.Zero, 2.5f);
|
Velocity = Velocity.MoveToward(Vector2.Zero, FlightAssistValue);
|
||||||
}
|
}
|
||||||
else if(Input.GetAxis("down", "up") == 0){
|
else if(Input.GetAxis("down", "up") == 0){
|
||||||
Velocity = Velocity.MoveToward(Vector2.Zero, 2.5f);
|
Velocity = Velocity.MoveToward(Vector2.Zero, FlightAssistValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
//FA toggle
|
||||||
|
if (Input.IsActionJustPressed("toggle_fa"))
|
||||||
|
{
|
||||||
|
ToggleFlightAssist();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -39,10 +48,16 @@ public partial class player : ship // Inherits from base ship class
|
||||||
EmitSignal(SignalName.HealthUpdate, Health);
|
EmitSignal(SignalName.HealthUpdate, Health);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ToggleFlightAssist()
|
||||||
|
{
|
||||||
|
if (FlightAssistValue == 0f){FlightAssistValue = 2.5f;}
|
||||||
|
else {FlightAssistValue = 0;}
|
||||||
|
}
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
Sprite = GetNode<Sprite2D>("ShipSprite");
|
Sprite = GetNode<Sprite2D>("ShipSprite");
|
||||||
string spritePath = "";
|
string spritePath = ""; // Have to initialise as "" because of switch statements
|
||||||
|
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
|
|
@ -60,7 +75,7 @@ public partial class player : ship // Inherits from base ship class
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(color)
|
switch(Color)
|
||||||
{
|
{
|
||||||
case ShipColor.RED:
|
case ShipColor.RED:
|
||||||
spritePath = spritePath + "ShipRed.png";
|
spritePath = spritePath + "ShipRed.png";
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue