flappy-bird/Player.gd
2020-01-29 21:51:40 +01:00

49 lines
No EOL
1 KiB
GDScript

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 move
signal hit
var screen_size
var playing = false
var speed_y = 0
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
func _process(delta):
if Input.is_action_just_pressed("ui_accept"):
if not playing:
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)
# TODO find the correct rotation, noob
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)