2020-01-14 22:20:17 +01:00
|
|
|
extends Area2D
|
|
|
|
|
2020-01-15 18:48:07 +01:00
|
|
|
export var speed = 3 # How fast the player will move (pixels/sec).
|
|
|
|
export var jump_speed = 4
|
|
|
|
export var speed_inc = 0.3
|
2020-01-14 22:20:17 +01:00
|
|
|
|
2020-04-08 12:40:43 +02:00
|
|
|
signal start # The bird starts
|
|
|
|
signal passed # The bird passes a Tower
|
|
|
|
signal hit # The bird is hit/flies off screen
|
|
|
|
|
|
|
|
var tower_locations = []
|
2020-01-14 22:20:17 +01:00
|
|
|
|
|
|
|
var screen_size
|
2020-01-15 18:48:07 +01:00
|
|
|
var playing = false
|
2020-01-14 22:20:17 +01:00
|
|
|
|
|
|
|
var speed_y = 0
|
|
|
|
|
2020-04-08 12:40:43 +02:00
|
|
|
var x_offset
|
|
|
|
|
2020-01-14 22:20:17 +01:00
|
|
|
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
|
2020-04-08 12:40:43 +02:00
|
|
|
x_offset = get_global_transform().get_origin().x
|
2020-01-14 22:20:17 +01:00
|
|
|
|
|
|
|
func _process(delta):
|
|
|
|
if Input.is_action_just_pressed("ui_accept"):
|
2020-01-15 18:48:07 +01:00
|
|
|
if not playing:
|
2020-04-08 12:40:43 +02:00
|
|
|
emit_signal("start")
|
2020-01-15 18:48:07 +01:00
|
|
|
speed_y = 0
|
|
|
|
playing = true
|
|
|
|
$CollisionShape2D.set_deferred("disabled", false)
|
2020-01-14 22:20:17 +01:00
|
|
|
speed_y = min(speed_y, 0) - 1 * jump_speed
|
|
|
|
|
2020-01-15 18:48:07 +01:00
|
|
|
if not playing:
|
|
|
|
return
|
2020-04-08 12:40:43 +02:00
|
|
|
|
2020-01-15 18:48:07 +01:00
|
|
|
speed_y += speed_inc
|
|
|
|
|
|
|
|
position += Vector2(speed, speed_y * speed)
|
2020-01-14 22:20:17 +01:00
|
|
|
|
2020-04-08 12:40:43 +02:00
|
|
|
var global = get_global_transform().get_origin()
|
|
|
|
while global.x - x_offset > tower_locations[0]:
|
|
|
|
emit_signal("passed")
|
|
|
|
tower_locations.pop_front()
|
2020-02-08 11:36:48 +01:00
|
|
|
|
2020-01-29 21:51:40 +01:00
|
|
|
rotation = atan(speed_y / speed)
|
2020-01-15 18:48:07 +01:00
|
|
|
|
2020-01-29 21:51:40 +01:00
|
|
|
if position.y > screen_size.y:
|
2020-01-15 18:48:07 +01:00
|
|
|
emit_signal("hit")
|
|
|
|
print(position)
|
|
|
|
playing = false
|
2020-01-15 14:43:08 +01:00
|
|
|
|
|
|
|
func _on_Player_body_entered(body):
|
2020-01-15 18:48:07 +01:00
|
|
|
playing = false
|
2020-01-15 15:44:46 +01:00
|
|
|
#hide() # Player disappears after being hit.
|
2020-01-15 14:43:08 +01:00
|
|
|
emit_signal("hit")
|
2020-04-08 12:40:43 +02:00
|
|
|
$CollisionShape2D.set_deferred("disabled", true)
|
|
|
|
|
|
|
|
func _on_Tower_spawn(x):
|
|
|
|
tower_locations.append(x)
|