fix: prevent duplicate asteroid signal connection
- fixes double scoring issue
This commit is contained in:
parent
55cf630cb1
commit
729fb29770
|
|
@ -16,7 +16,7 @@ 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
|
||||||
type = 1
|
type = 0
|
||||||
|
|
||||||
[node name="Lasers" type="Node" parent="."]
|
[node name="Lasers" type="Node" parent="."]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,28 +29,3 @@ offset_right = 157.8
|
||||||
offset_bottom = 44.0
|
offset_bottom = 44.0
|
||||||
text = "Exit Game
|
text = "Exit Game
|
||||||
"
|
"
|
||||||
|
|
||||||
[node name="OptionButton" type="Button" parent="."]
|
|
||||||
layout_mode = 0
|
|
||||||
offset_top = 68.0
|
|
||||||
offset_right = 96.0
|
|
||||||
offset_bottom = 99.0
|
|
||||||
text = "Options
|
|
||||||
"
|
|
||||||
|
|
||||||
[node name="Label" type="Label" parent="."]
|
|
||||||
layout_mode = 1
|
|
||||||
anchors_preset = -1
|
|
||||||
anchor_left = 16.1
|
|
||||||
anchor_top = 5.7
|
|
||||||
anchor_right = 33.175
|
|
||||||
anchor_bottom = 10.4
|
|
||||||
offset_left = -2.0
|
|
||||||
offset_top = 2.99998
|
|
||||||
offset_right = -2.00012
|
|
||||||
offset_bottom = 2.99997
|
|
||||||
grow_horizontal = 0
|
|
||||||
grow_vertical = 0
|
|
||||||
theme_override_font_sizes/font_size = 80
|
|
||||||
text = "Name in Progress"
|
|
||||||
horizontal_alignment = 1
|
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,9 @@ public partial class asteroid : Area2D
|
||||||
|
|
||||||
public void Explode()
|
public void Explode()
|
||||||
{
|
{
|
||||||
|
//DEBUG PRINT
|
||||||
|
GD.Print($"DEBUG: Explode() called for {Name} at {GlobalPosition}");
|
||||||
|
GD.Print($"DEBUG: {Name} calling Explode()");
|
||||||
EmitSignal(SignalName.Exploded, GlobalPosition, (int)size);
|
EmitSignal(SignalName.Exploded, GlobalPosition, (int)size);
|
||||||
QueueFree();
|
QueueFree();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,13 +28,7 @@ public partial class game : Node2D
|
||||||
ScoreLabel = GetNode<Label>("UI/HUD/Score");
|
ScoreLabel = GetNode<Label>("UI/HUD/Score");
|
||||||
FlightAssistLabel = GetNode<Label>("UI/HUD/FlightAssist");
|
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");
|
||||||
var a = new asteroid();
|
|
||||||
for (int i = 0; i == Asteroids.GetChildCount() - 1; i++){
|
|
||||||
a = (asteroid)Asteroids.GetChild(i);
|
|
||||||
a.Exploded += OnAsteroidExploded;
|
|
||||||
}
|
|
||||||
|
|
||||||
Lasers = GetNode<Node>("Lasers");
|
Lasers = GetNode<Node>("Lasers");
|
||||||
Player = GetNode<CharacterBody2D>("Player");
|
Player = GetNode<CharacterBody2D>("Player");
|
||||||
|
|
@ -54,6 +48,7 @@ public partial class game : Node2D
|
||||||
UpdateFALabel();
|
UpdateFALabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* //AUTO SPAWN AFTER CLEAR
|
||||||
if (Asteroids.GetChildCount() == 0)
|
if (Asteroids.GetChildCount() == 0)
|
||||||
{
|
{
|
||||||
Random rand = new Random();
|
Random rand = new Random();
|
||||||
|
|
@ -61,7 +56,7 @@ public partial class game : Node2D
|
||||||
{
|
{
|
||||||
SpawnAsteroid(new Vector2(rand.Next(10, 800), rand.Next(10, 800)), (int)asteroid.AsteroidSize.LARGE);
|
SpawnAsteroid(new Vector2(rand.Next(10, 800), rand.Next(10, 800)), (int)asteroid.AsteroidSize.LARGE);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SpawnAsteroid(Vector2 position, int size)
|
public void SpawnAsteroid(Vector2 position, int size)
|
||||||
|
|
@ -120,22 +115,26 @@ public partial class game : Node2D
|
||||||
|
|
||||||
public void OnAsteroidExploded(Vector2 pos, int size)
|
public void OnAsteroidExploded(Vector2 pos, int size)
|
||||||
{
|
{
|
||||||
//score hardcoded for now, will make implementation of enemy scores easier later on
|
// DEBUG PRINT
|
||||||
// score = score * 2 (for loop)
|
GD.Print($"DEBUG: Asteroid exploded at {pos}, size: {size}");
|
||||||
for(int i = 0; i < 2; i++){
|
if (size == 0)
|
||||||
if (size == 0){
|
{
|
||||||
|
for (int i = 0; i < 2; i++){
|
||||||
SpawnAsteroid(pos, (int)asteroid.AsteroidSize.MEDIUM);
|
SpawnAsteroid(pos, (int)asteroid.AsteroidSize.MEDIUM);
|
||||||
|
}
|
||||||
Score += 60;
|
Score += 60;
|
||||||
}
|
}
|
||||||
else if (size == 1){
|
else if (size == 1)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 2; i++){
|
||||||
SpawnAsteroid(pos, (int)asteroid.AsteroidSize.SMALL);
|
SpawnAsteroid(pos, (int)asteroid.AsteroidSize.SMALL);
|
||||||
|
}
|
||||||
Score += 40;
|
Score += 40;
|
||||||
}
|
}
|
||||||
else if (size == 2)
|
else if (size == 2)
|
||||||
{
|
{
|
||||||
Score += 20;
|
Score += 20;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
GD.Print(Score);
|
GD.Print(Score);
|
||||||
UpdateScoreLabel(Score);
|
UpdateScoreLabel(Score);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue