extends Area2D export var speed = 3 # How fast the player will move (pixels/sec). export var jump_speed = 4 export var speed_inc = 0.3 signal start # The bird starts signal passed # The bird passes a Tower signal hit # The bird is hit/flies off screen var tower_locations = [] var screen_size var playing = false var speed_y = 0 var x_offset func start(): position = screen_size / 2 # Called when the node enters the scene tree for the first time. func _ready(): screen_size = get_viewport_rect().size x_offset = get_global_transform().get_origin().x func _process(delta): if Input.is_action_just_pressed("ui_accept"): if not playing: emit_signal("start") speed_y = 0 playing = true $CollisionShape2D.set_deferred("disabled", false) speed_y = min(speed_y, 0) - 1 * jump_speed if not playing: return speed_y += speed_inc position += Vector2(speed, speed_y * speed) var global = get_global_transform().get_origin() while global.x - x_offset > tower_locations[0]: emit_signal("passed") tower_locations.pop_front() rotation = atan(speed_y / speed) if position.y > screen_size.y: emit_signal("hit") print(position) playing = false func _on_Player_body_entered(body): playing = false #hide() # Player disappears after being hit. emit_signal("hit") $CollisionShape2D.set_deferred("disabled", true) func _on_Tower_spawn(x): tower_locations.append(x)