flappy-bird/Player.gd

49 lines
1 KiB
GDScript3
Raw Normal View History

2020-01-14 21:20:17 +00:00
extends Area2D
2020-01-15 17:48:07 +00: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 21:20:17 +00:00
signal move
2020-01-15 13:43:08 +00:00
signal hit
2020-01-14 21:20:17 +00:00
var screen_size
2020-01-15 17:48:07 +00:00
var playing = false
2020-01-14 21:20:17 +00:00
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"):
2020-01-15 17:48:07 +00:00
if not playing:
speed_y = 0
playing = true
$CollisionShape2D.set_deferred("disabled", false)
2020-01-14 21:20:17 +00:00
speed_y = min(speed_y, 0) - 1 * jump_speed
2020-01-15 17:48:07 +00:00
if not playing:
return
speed_y += speed_inc
position += Vector2(speed, speed_y * speed)
2020-01-14 21:20:17 +00:00
# TODO find the correct rotation, noob
2020-01-29 20:51:40 +00:00
rotation = atan(speed_y / speed)
2020-01-15 17:48:07 +00:00
2020-01-29 20:51:40 +00:00
if position.y > screen_size.y:
2020-01-15 17:48:07 +00:00
emit_signal("hit")
print(position)
playing = false
2020-01-15 13:43:08 +00:00
func _on_Player_body_entered(body):
2020-01-15 17:48:07 +00:00
playing = false
2020-01-15 14:44:46 +00:00
#hide() # Player disappears after being hit.
2020-01-15 13:43:08 +00:00
emit_signal("hit")
$CollisionShape2D.set_deferred("disabled", true)