Merge branch 'main' of https://gitty.informatik.hs-mannheim.de/3002102/gae_wild_jam
commit
708bb5e763
|
|
@ -13,28 +13,28 @@ func _ready() -> void:
|
||||||
launch(first.global_position)
|
launch(first.global_position)
|
||||||
|
|
||||||
func _on_body_entered(body: Node2D) -> void:
|
func _on_body_entered(body: Node2D) -> void:
|
||||||
if body.is_in_group("enemies"):
|
if body.is_in_group("enemies") and not body.is_hurt and not body.is_dying:
|
||||||
enemies_hit += 1
|
enemies_hit += 1
|
||||||
body.hit()
|
body.hit()
|
||||||
if enemies_hit == 20:
|
if enemies_hit == 20:
|
||||||
queue_free()
|
queue_free()
|
||||||
else:
|
else:
|
||||||
var next = get_nearest_enemy(global_position, body)
|
var next = get_nearest_enemy(global_position, body)
|
||||||
if next == null:
|
if next == null:
|
||||||
queue_free()
|
queue_free()
|
||||||
else:
|
else:
|
||||||
launch(next.global_position)
|
launch(next.global_position)
|
||||||
|
|
||||||
func get_nearest_enemy(from: Vector2, exclude: Node = null) -> Node:
|
func get_nearest_enemy(from: Vector2, exclude: Node = null) -> Node:
|
||||||
var nearest = null
|
var nearest = null
|
||||||
var min_distance = INF
|
var min_distance = INF
|
||||||
for enemy in get_tree().get_nodes_in_group("enemies"):
|
for enemy in get_tree().get_nodes_in_group("enemies"):
|
||||||
if enemy == exclude or enemy.is_dying:
|
if enemy == exclude or enemy.is_dying or enemy.is_hurt:
|
||||||
continue
|
continue
|
||||||
var dist = from.distance_to(enemy.global_position)
|
var dist = from.distance_to(enemy.global_position)
|
||||||
if dist < min_distance:
|
if dist < min_distance:
|
||||||
min_distance = dist
|
min_distance = dist
|
||||||
nearest = enemy
|
nearest = enemy
|
||||||
return nearest
|
return nearest
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue