added animated apple drop with tween

pull/1/head
Artur David 2026-04-13 18:52:54 +02:00
parent e65e98754d
commit 7851a25a65
7 changed files with 44 additions and 2 deletions

6
scenes/apple.gd 100644
View File

@ -0,0 +1,6 @@
extends DropsBase
# Called when the node enters the scene tree for the first time.
# Called every frame. 'delta' is the elapsed time since the previous frame.

View File

@ -0,0 +1 @@
uid://bewhtchahb2sy

View File

@ -1,5 +1,6 @@
[gd_scene format=3 uid="uid://dm6d2jg52vi41"] [gd_scene format=3 uid="uid://dm6d2jg52vi41"]
[ext_resource type="Script" uid="uid://bewhtchahb2sy" path="res://scenes/apple.gd" id="1_7vr8k"]
[ext_resource type="Texture2D" uid="uid://d2pinnrigixnp" path="res://assets/16x16 Pixelart Food Icons/Pixel_Foods(ARTLİNE).png" id="1_h071m"] [ext_resource type="Texture2D" uid="uid://d2pinnrigixnp" path="res://assets/16x16 Pixelart Food Icons/Pixel_Foods(ARTLİNE).png" id="1_h071m"]
[sub_resource type="AtlasTexture" id="AtlasTexture_7vr8k"] [sub_resource type="AtlasTexture" id="AtlasTexture_7vr8k"]
@ -11,6 +12,7 @@ radius = 9.0
height = 18.0 height = 18.0
[node name="Apple" type="Area2D" unique_id=1121088527] [node name="Apple" type="Area2D" unique_id=1121088527]
script = ExtResource("1_7vr8k")
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=1596918550] [node name="Sprite2D" type="Sprite2D" parent="." unique_id=1596918550]
texture_filter = 1 texture_filter = 1

View File

@ -10,7 +10,7 @@
[sub_resource type="Resource" id="Resource_gstla"] [sub_resource type="Resource" id="Resource_gstla"]
script = ExtResource("2_2npkn") script = ExtResource("2_2npkn")
drop = ExtResource("3_fd6lc") drop = ExtResource("3_fd6lc")
chance = 0.3 chance = 1.0
metadata/_custom_type_script = "uid://cjkaw7wqw4e30" metadata/_custom_type_script = "uid://cjkaw7wqw4e30"
[sub_resource type="AtlasTexture" id="AtlasTexture_v5wyi"] [sub_resource type="AtlasTexture" id="AtlasTexture_v5wyi"]

View File

@ -0,0 +1,32 @@
extends Area2D
class_name DropsBase
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
_animate_spawn()
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func _get_random_landing_position() -> Vector2:
var offset_x = randf_range(-20,20)
var offset_y = randf_range(-20,20)
offset_x += global_position.x
offset_y += global_position.y
return Vector2(offset_x,offset_y)
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 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.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", landing.y, 0.2).set_ease(Tween.EASE_IN).set_trans(Tween.TRANS_QUAD)

View File

@ -0,0 +1 @@
uid://cwp7q24t3nxly

View File

@ -26,8 +26,8 @@ func _die():
player.stream = death_sound player.stream = death_sound
player.bus = "SFX" player.bus = "SFX"
player.play() player.play()
await animated_sprite_2d.animation_finished
died.emit(self) died.emit(self)
await animated_sprite_2d.animation_finished
queue_free() queue_free()