crabs-game/scripts/game1/Game1Script.gd

62 lines
1.2 KiB
GDScript

extends Node
var playing = false
onready var player = $Game/Player
onready var player_camera = $Game/Player/Camera2D
func _ready():
$Opening1.play('default')
yield($Opening1, 'animation_finished')
$Opening1.hide()
func launch_game():
$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()