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
|
|
|
|
|
|
|
signal move
|
2020-01-15 14:43:08 +01:00
|
|
|
signal hit
|
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
|
|
|
|
|
|
|
|
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 18:48:07 +01:00
|
|
|
if not playing:
|
|
|
|
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
|
|
|
|
|
|
|
|
speed_y += speed_inc
|
|
|
|
|
|
|
|
position += Vector2(speed, speed_y * speed)
|
2020-01-14 22:20:17 +01:00
|
|
|
|
|
|
|
# TODO find the correct rotation, noob
|
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")
|
|
|
|
$CollisionShape2D.set_deferred("disabled", true)
|