2020-08-17 12:15:41 +02:00
|
|
|
extends Node
|
|
|
|
|
|
|
|
|
2020-08-17 17:27:28 +02:00
|
|
|
var playing = false
|
|
|
|
|
|
|
|
onready var player = $Game/Player
|
|
|
|
onready var player_camera = $Game/Player/Camera2D
|
|
|
|
|
2020-08-17 12:15:41 +02:00
|
|
|
func _ready():
|
2020-08-17 17:27:28 +02:00
|
|
|
$Opening1.play('default')
|
|
|
|
yield($Opening1, 'animation_finished')
|
|
|
|
$Opening1.hide()
|
2020-08-17 14:37:07 +02:00
|
|
|
|
|
|
|
func launch_game():
|
2020-08-17 17:27:28 +02:00
|
|
|
$Opening2.hide()
|
|
|
|
playing = true
|
|
|
|
player_camera.make_current()
|
|
|
|
player.connect('frame_changed', self, 'update_camera')
|
|
|
|
|
|
|
|
func _input(event):
|
|
|
|
if playing && !is_camera_moving:
|
|
|
|
if event.is_action_pressed('right'):
|
|
|
|
move_right()
|
|
|
|
if event.is_action_pressed('left'):
|
|
|
|
move_left()
|
|
|
|
|
|
|
|
func move_right():
|
|
|
|
is_camera_moving = true
|
|
|
|
player.play('moving')
|
|
|
|
update_camera()
|
|
|
|
|
|
|
|
yield(player, 'animation_finished')
|
|
|
|
|
|
|
|
is_camera_moving = false
|
|
|
|
player.play('default')
|
|
|
|
|
|
|
|
player.frame = 0
|
|
|
|
player.position.x += 16
|
|
|
|
|
|
|
|
func move_left():
|
|
|
|
player.position.x -= 16
|
|
|
|
|
|
|
|
is_camera_moving = true
|
|
|
|
player.play('moving', true)
|
|
|
|
update_camera()
|
|
|
|
|
|
|
|
yield(player, 'animation_finished')
|
|
|
|
|
|
|
|
is_camera_moving = false
|
|
|
|
player.play('default')
|
|
|
|
|
|
|
|
player.frame = 0
|
|
|
|
|
|
|
|
|
|
|
|
const animation_steps = [3, 6, 10, 13]
|
|
|
|
var is_camera_moving = false
|
|
|
|
func update_camera():
|
|
|
|
if is_camera_moving:
|
|
|
|
player_camera.position = Vector2(animation_steps[player.frame], 0)
|
|
|
|
else:
|
|
|
|
player_camera.position = Vector2()
|