added more sounds and autocollect coin

This commit is contained in:
Jonas Braus
2024-07-31 19:49:20 +02:00
parent 85736f82e0
commit b18dfee7dc
10 changed files with 56 additions and 8 deletions
+12 -1
View File
@@ -1,15 +1,21 @@
extends RigidBody2D
@onready var animated_sprite_2d = $AnimatedSprite2D
@export var hit_object:PackedScene
@export var auto_collect:bool
var destroyed = false
var instance = null
var _body = null
@onready var timer = $Timer
func _ready():
animated_sprite_2d.play("idle")#
func _on_activate_body_entered(body):
_body = body
if destroyed:
return
destroyed = true
animated_sprite_2d.play("destroy")
@@ -17,6 +23,11 @@ func _on_activate_body_entered(body):
if hit_object == null:
return
var instance = hit_object.instantiate()
instance = hit_object.instantiate()
add_child(instance)
instance.position.y -= 16
timer.start()
func _on_timer_timeout():
if auto_collect:
instance.collect_coin(_body)
+2 -1
View File
@@ -40,7 +40,8 @@ func f_die():
speed = 0
animated_sprite_2d.play("die")
timer.start()
die.queue_free()
if die != null:
die.queue_free()
die_sound.play()
ray_cast_left_2.queue_free()
ray_cast_right_2.queue_free()
+2
View File
@@ -1,10 +1,12 @@
extends RigidBody2D
@onready var timer = $Timer
var enter_count = 0
@onready var audio_stream_player_2d = $AudioStreamPlayer2D
# Called when the node enters the scene tree for the first time.
func _ready():
timer.start()
audio_stream_player_2d.play()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
+7 -3
View File
@@ -9,6 +9,7 @@ extends CharacterBody2D
@onready var pipedetector_ground = $pipedetector_ground
@onready var pipe_sound = $PipeSound
@onready var jump_sound = $JumpSound
@onready var shrink_sound = $shrinkSound
const SPEED = 130.0
@@ -42,8 +43,9 @@ func _unhandled_input(event):
if event.position.x < get_viewport_rect().size.x / 2:
touch_anchor = event.position
else:
if event.position.y > get_viewport_rect().size.y / 2 and not jump:
jump = true
if event.position.y > get_viewport_rect().size.y / 2:
if not jump:
jump = true
elif not fire:
fire = true
elif event.position.x < get_viewport_rect().size.x / 2:
@@ -101,7 +103,7 @@ func _physics_process(delta):
get_parent().add_child(instance)
instance.position.x = position.x -8 if animated_sprite_2d.flip_h else position.x + 8
instance.position.y = position.y
instance.linear_velocity.x = -400 if animated_sprite_2d.flip_h else 400
instance.linear_velocity.x = -200 if animated_sprite_2d.flip_h else 200
instance.linear_velocity.y = 50
instance.angular_velocity = 0
@@ -165,10 +167,12 @@ func flower():
func shrink():
if is_flower:
is_flower = false
shrink_sound.play()
elif is_big:
is_big = false
collision_shape_2d.shape.height = 16
pipedetector_ground.position.y -= 8
shrink_sound.play()
else:
print("dead")