added dropsbase to grapes extend
parent
708bb5e763
commit
8c6005596b
|
|
@ -1,5 +1,6 @@
|
|||
[gd_scene format=3 uid="uid://cob0yjs7tx2ol"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://b6yek34613pbw" path="res://scripts/grape.gd" id="1_0gvam"]
|
||||
[ext_resource type="Texture2D" uid="uid://d2pinnrigixnp" path="res://assets/16x16 Pixelart Food Icons/Pixel_Foods(ARTLİNE).png" id="1_8daar"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_0gvam"]
|
||||
|
|
@ -9,6 +10,7 @@ region = Rect2(55, 19, 15, 16)
|
|||
[sub_resource type="CircleShape2D" id="CircleShape2D_cukkh"]
|
||||
|
||||
[node name="Grape" type="Area2D" unique_id=994786367]
|
||||
script = ExtResource("1_0gvam")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=2069064426]
|
||||
texture_filter = 1
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
extends DropsBase
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://b6yek34613pbw
|
||||
|
|
@ -13,28 +13,28 @@ func _ready() -> void:
|
|||
launch(first.global_position)
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
if body.is_in_group("enemies") and not body.is_hurt and not body.is_dying:
|
||||
enemies_hit += 1
|
||||
body.hit()
|
||||
if enemies_hit == 20:
|
||||
queue_free()
|
||||
else:
|
||||
var next = get_nearest_enemy(global_position, body)
|
||||
if next == null:
|
||||
queue_free()
|
||||
else:
|
||||
launch(next.global_position)
|
||||
if body.is_in_group("enemies") and not body.is_hurt and not body.is_dying:
|
||||
enemies_hit += 1
|
||||
body.hit()
|
||||
if enemies_hit == 20:
|
||||
queue_free()
|
||||
else:
|
||||
var next = get_nearest_enemy(global_position, body)
|
||||
if next == null:
|
||||
queue_free()
|
||||
else:
|
||||
launch(next.global_position)
|
||||
|
||||
func get_nearest_enemy(from: Vector2, exclude: Node = null) -> Node:
|
||||
var nearest = null
|
||||
var min_distance = INF
|
||||
for enemy in get_tree().get_nodes_in_group("enemies"):
|
||||
if enemy == exclude or enemy.is_dying or enemy.is_hurt:
|
||||
continue
|
||||
var dist = from.distance_to(enemy.global_position)
|
||||
if dist < min_distance:
|
||||
min_distance = dist
|
||||
nearest = enemy
|
||||
return nearest
|
||||
|
||||
|
||||
var nearest = null
|
||||
var min_distance = INF
|
||||
for enemy in get_tree().get_nodes_in_group("enemies"):
|
||||
if enemy == exclude or enemy.is_dying or enemy.is_hurt:
|
||||
continue
|
||||
var dist = from.distance_to(enemy.global_position)
|
||||
if dist < min_distance:
|
||||
min_distance = dist
|
||||
nearest = enemy
|
||||
return nearest
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue