flappy-bird/Player.gd

37 lines
785 B
GDScript3
Raw Normal View History

2020-01-14 22:20:17 +01:00
extends Area2D
export var speed = 1 # How fast the player will move (pixels/sec).
export var jump_speed = 10
signal move
2020-01-15 14:43:08 +01:00
signal hit
2020-01-14 22:20:17 +01:00
var screen_size
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"):
speed_y = min(speed_y, 0) - 1 * jump_speed
speed_y += 1
position.x += 1
position.y += speed_y * speed
emit_signal("move")
# TODO find the correct rotation, noob
rotation = atan(speed_y / speed) + PI / 2
2020-01-15 14:43:08 +01:00
func _on_Player_body_entered(body):
print("HIT")
hide() # Player disappears after being hit.
emit_signal("hit")
$CollisionShape2D.set_deferred("disabled", true)