added the ability to collect apples

pull/1/head
Artur David 2026-04-13 22:17:00 +02:00
parent 7851a25a65
commit 3c1dfb3f55
2 changed files with 25 additions and 6 deletions

View File

@ -1,8 +1,14 @@
extends Area2D extends Area2D
class_name DropsBase class_name DropsBase
var witch
var player
var is_spawning = true
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready() -> void: func _ready() -> void:
body_entered.connect(_on_body_entered)
witch = get_node("/root/Game/Witch")
player = get_node("/root/Game/Player")
_animate_spawn() _animate_spawn()
pass # Replace with function body. pass # Replace with function body.
@ -19,14 +25,27 @@ func _get_random_landing_position() -> Vector2:
return Vector2(offset_x,offset_y) return Vector2(offset_x,offset_y)
func _animate_spawn() -> void: func _animate_spawn() -> void:
scale = Vector2.ZERO
var size_scling = create_tween()
size_scling.tween_property(self, "scale", Vector2(1,1),0.4)
var jump = create_tween() var jump = create_tween()
var landing = _get_random_landing_position() var landing = _get_random_landing_position()
jump.tween_property(self, "global_position:x", landing.x, 0.2).set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_QUAD) jump.tween_property(self, "global_position:x", landing.x, 0.2).set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_QUAD)
jump.parallel() jump.parallel()
jump.tween_property(self, "global_position:y", global_position.y - 5, 0.2).set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_QUAD) jump.tween_property(self, "global_position:y", global_position.y - 20, 0.2).set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_QUAD)
jump.tween_property(self, "global_position:y", landing.y, 0.2).set_ease(Tween.EASE_IN).set_trans(Tween.TRANS_QUAD) jump.tween_property(self, "global_position:y", landing.y, 0.2).set_ease(Tween.EASE_IN).set_trans(Tween.TRANS_QUAD)
await jump.finished
is_spawning = false
func _on_body_entered(body: Node2D) -> void:
if body == player and not is_spawning:
collect()
pass
func collect():
var position_drop = create_tween()
var target = witch.global_position
position_drop.tween_property(self, "global_position:y", global_position.y - 20, 0.2).set_ease(Tween.EASE_IN).set_trans(Tween.TRANS_QUAD)
position_drop.tween_property(self, "global_position:y", target.y, 0.5).set_ease(Tween.EASE_IN).set_trans(Tween.TRANS_QUAD)
position_drop.parallel()
position_drop.tween_property(self, "global_position:x", target.x, 0.5).set_ease(Tween.EASE_IN).set_trans(Tween.TRANS_QUAD)
await position_drop.finished
var scale_tween = create_tween()
scale_tween.tween_property(self, "scale", Vector2.ZERO,0.2)

View File

@ -12,7 +12,7 @@ func _process(delta: float) -> void:
pass pass
func on_enemy_died(enemy): func on_enemy_died(enemy):
drop_item(enemy) call_deferred("drop_item", enemy)
func drop_item(enemy): func drop_item(enemy):
for entry in enemy.drop_table: for entry in enemy.drop_table: