No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pickup.gd 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. extends Node2D
  2. export var sprite_texture : Texture
  3. export var type := "bonus" setget , get_type
  4. export var scroll_speed = 9
  5. onready var sprite = $Sprite
  6. onready var audio_stream = $AudioStreamPlayer
  7. onready var timer = $Timer
  8. var malus_sound = preload("res://mini-game/ressources/sounds/error_006.wav")
  9. var bonus_sound = preload("res://mini-game/ressources/sounds/select_006.wav")
  10. var picked_up := false
  11. func _ready():
  12. sprite.texture = sprite_texture
  13. func _on_notifier_screen_exited() -> void:
  14. if not picked_up:
  15. queue_free()
  16. func _physics_process(delta):
  17. move()
  18. func get_type():
  19. return type
  20. func move():
  21. self.position.x -= scroll_speed
  22. func pickup():
  23. picked_up = true
  24. timer.start()
  25. sprite.hide()
  26. if type == "bonus":
  27. audio_stream.stream = bonus_sound
  28. elif type == "malus":
  29. audio_stream.stream = malus_sound
  30. audio_stream.play()
  31. func _on_Area2D_body_entered(body: Node) -> void:
  32. if body.has_method("bonus") and body.has_method("hit"):
  33. pickup()
  34. if type == "bonus":
  35. body.bonus()
  36. elif type == "malus":
  37. body.hit()
  38. func _on_AudioStreamPlayer_finished() -> void:
  39. queue_free()