-feat: lasers and asteroids now despawn when collide with world border.
-fix: asteroids blown up by ai do not increase score.
This commit is contained in:
parent
6a03a1d878
commit
cf500dc06e
File diff suppressed because one or more lines are too long
|
|
@ -28,7 +28,7 @@ public partial class Laser : Area2D
|
|||
{
|
||||
if (area is asteroid asteroid)
|
||||
{
|
||||
asteroid.Explode();
|
||||
asteroid.Explode(Shooter);
|
||||
QueueFree();
|
||||
}
|
||||
}
|
||||
|
|
@ -63,5 +63,11 @@ public partial class Laser : Area2D
|
|||
QueueFree();
|
||||
}
|
||||
}
|
||||
|
||||
else if (body is StaticBody2D)
|
||||
{
|
||||
//GD.Print("laser hit border");
|
||||
QueueFree();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ using System;
|
|||
public partial class asteroid : Area2D
|
||||
{
|
||||
[Signal]
|
||||
public delegate void ExplodedEventHandler(Vector2 pos, int size);
|
||||
public delegate void ExplodedEventHandler(Vector2 pos, int size, ship shooter);
|
||||
|
||||
public enum AsteroidSize {LARGE, MEDIUM, SMALL};
|
||||
|
||||
|
|
@ -68,16 +68,16 @@ public partial class asteroid : Area2D
|
|||
}
|
||||
}
|
||||
|
||||
public void Explode()
|
||||
public void Explode(ship shooter)
|
||||
{
|
||||
//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, shooter);
|
||||
QueueFree();
|
||||
}
|
||||
|
||||
private static void OnBodyEntered(CharacterBody2D body)
|
||||
private void OnBodyEntered(Node body)
|
||||
{
|
||||
/*if (body is player player)
|
||||
{
|
||||
|
|
@ -85,11 +85,17 @@ public partial class asteroid : Area2D
|
|||
GD.Print("player asteroid collide");
|
||||
}*/
|
||||
|
||||
if (body is not ship ship) return;
|
||||
if (body is ship ship)
|
||||
{
|
||||
ship.ShipDamage((30));
|
||||
GD.Print(("ship asteroid collide"));
|
||||
GD.Print(ship.Name, ship.Health);
|
||||
}
|
||||
else if (body is StaticBody2D)
|
||||
{
|
||||
QueueFree();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
|
|
|
|||
|
|
@ -156,27 +156,35 @@ public partial class game : Node2D
|
|||
GetTree().ReloadCurrentScene();
|
||||
}
|
||||
|
||||
private void OnAsteroidExploded(Vector2 pos, int size)
|
||||
private void OnAsteroidExploded(Vector2 pos, int size, ship shooter)
|
||||
{
|
||||
// DEBUG PRINT
|
||||
GD.Print($"DEBUG: Asteroid exploded at {pos}, size: {size}");
|
||||
if (size == 0)
|
||||
|
||||
switch (size)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
for (int i = 0; i < 2; i++){
|
||||
SpawnAsteroid(pos, (int)asteroid.AsteroidSize.MEDIUM);
|
||||
}
|
||||
if (shooter is not player) return;
|
||||
_score += 60;
|
||||
break;
|
||||
}
|
||||
else if (size == 1)
|
||||
case 1:
|
||||
{
|
||||
for (int i = 0; i < 2; i++){
|
||||
SpawnAsteroid(pos, (int)asteroid.AsteroidSize.SMALL);
|
||||
}
|
||||
if (shooter is not player) return;
|
||||
_score += 40;
|
||||
break;
|
||||
}
|
||||
else if (size == 2)
|
||||
{
|
||||
case 2:
|
||||
if (shooter is not player) return;
|
||||
_score += 20;
|
||||
break;
|
||||
}
|
||||
GD.Print(_score);
|
||||
UpdateScoreLabel(_score);
|
||||
|
|
|
|||
Loading…
Reference in a new issue