ship.gd 778 B

123456789101112131415161718192021222324252627282930313233
  1. extends Node2D
  2. onready var MAIN = find_parent("MAIN")
  3. # Declare member variables here. Examples:
  4. # var a: int = 2
  5. # var b: String = "text"
  6. var pulsating = true
  7. var phase = 0
  8. var hertz = 1
  9. func _process(delta: float) -> void:
  10. if MAIN.started:
  11. position.x += MAIN.speed * delta
  12. if pulsating:
  13. phase += delta*hertz*2*PI
  14. scale.x = 1 + pow(sin(phase),2)*0.2
  15. scale.y = 1 - pow(sin(phase+0.1),2)*0.1
  16. if position.x <= -200:
  17. queue_free()
  18. # Called when the node enters the scene tree for the first time.
  19. func _ready() -> void:
  20. $scaler/area.connect("body_entered",self,"on_hit")
  21. pass # Replace with function body.
  22. func on_hit(_body):
  23. MAIN.delegation_hit = true
  24. print("hit spaceship")
  25. $scaler/alive.visible = false
  26. $scaler/dead.visible = true
  27. pulsating = false