2020-08-17 12:15:41 +02:00
|
|
|
extends Node
|
|
|
|
|
2020-08-20 17:03:30 +02:00
|
|
|
signal can_leave
|
|
|
|
|
2020-08-17 17:27:28 +02:00
|
|
|
var playing = false
|
|
|
|
|
2020-08-18 21:15:10 +02:00
|
|
|
onready var player_fab = preload('res://scenes/game1/Player.tscn')
|
|
|
|
var player : AnimatedSprite
|
|
|
|
var player_camera : Camera2D
|
2020-08-18 16:55:40 +02:00
|
|
|
|
2020-08-20 15:18:39 +02:00
|
|
|
onready var dialogue_box = $UI/Dialog
|
|
|
|
export (String, FILE, '*.json') var dialogue
|
|
|
|
|
2020-08-20 17:32:24 +02:00
|
|
|
onready var music_player = get_node('/root/MusicPlayer') as MusicPlayer
|
|
|
|
|
2020-08-18 16:55:40 +02:00
|
|
|
onready var levels = [
|
2020-08-19 11:56:10 +02:00
|
|
|
#'TestLogEntity',
|
2020-08-18 21:15:10 +02:00
|
|
|
'Level1',
|
|
|
|
'Level2',
|
|
|
|
'Level3',
|
|
|
|
'Level4',
|
|
|
|
'Level5',
|
2020-08-18 16:55:40 +02:00
|
|
|
]
|
|
|
|
|
2020-08-19 13:01:47 +02:00
|
|
|
export var skipToLevel = ''
|
|
|
|
|
2020-08-18 21:15:10 +02:00
|
|
|
var current_level = -1
|
|
|
|
var spawn_pos = Vector2()
|
|
|
|
var exit_points = []
|
2020-08-20 17:03:30 +02:00
|
|
|
var can_leave = false
|
2020-08-17 17:27:28 +02:00
|
|
|
|
2020-08-17 12:15:41 +02:00
|
|
|
func _ready():
|
2020-08-20 15:18:39 +02:00
|
|
|
assert(dialogue != null)
|
|
|
|
|
2020-08-19 13:01:47 +02:00
|
|
|
if skipToLevel != '':
|
|
|
|
$Opening1.queue_free()
|
|
|
|
start_game()
|
|
|
|
while levels[current_level] != skipToLevel:
|
|
|
|
next_level()
|
|
|
|
return
|
|
|
|
|
2020-08-20 15:18:39 +02:00
|
|
|
yield(get_tree().create_timer(6), "timeout")
|
2020-08-20 17:32:24 +02:00
|
|
|
music_player.play("Chris Zabriskie - Direct to Video - 03 I Don't See the Branches, I See the Leaves")
|
2020-08-17 17:27:28 +02:00
|
|
|
$Opening1.play('default')
|
2020-08-20 15:18:39 +02:00
|
|
|
$Opening1/Mask.play('default')
|
|
|
|
$Opening1/OpeningOver.play('default')
|
2020-08-17 17:27:28 +02:00
|
|
|
yield($Opening1, 'animation_finished')
|
2020-08-18 21:15:10 +02:00
|
|
|
$Opening1.queue_free()
|
2020-08-20 15:18:39 +02:00
|
|
|
|
2020-08-19 18:59:29 +02:00
|
|
|
$Opening2/Player.sleep = false
|
2020-08-20 15:18:39 +02:00
|
|
|
yield(dialogue_box.start_dialogue(dialogue), 'end')
|
2020-08-20 17:03:30 +02:00
|
|
|
can_leave = true
|
|
|
|
emit_signal("can_leave")
|
2020-08-17 14:37:07 +02:00
|
|
|
|
2020-08-18 21:15:10 +02:00
|
|
|
func start_game():
|
2020-08-20 17:03:30 +02:00
|
|
|
$Opening2/Player.sleep = true
|
|
|
|
if !can_leave:
|
|
|
|
yield(self, 'can_leave')
|
2020-08-18 16:55:40 +02:00
|
|
|
# Hide opening
|
2020-08-18 21:15:10 +02:00
|
|
|
$Opening2.queue_free()
|
|
|
|
next_level()
|
|
|
|
|
|
|
|
func next_level():
|
|
|
|
if current_level >= 0:
|
|
|
|
var level = $Game.get_node(levels[current_level])
|
|
|
|
level.queue_free()
|
|
|
|
|
|
|
|
current_level += 1
|
|
|
|
|
2020-08-19 17:04:26 +02:00
|
|
|
if current_level >= levels.size():
|
|
|
|
get_tree().change_scene("res://scenes/oil_tanker.tscn")
|
|
|
|
return
|
|
|
|
|
2020-08-18 21:15:10 +02:00
|
|
|
# Prepare level
|
|
|
|
var level = load("res://scenes/game1/" + levels[current_level] + ".tscn").instance()
|
|
|
|
$Game.add_child(level)
|
|
|
|
spawn_entities(level)
|
2020-08-18 16:55:40 +02:00
|
|
|
|
|
|
|
# Prepare player
|
2020-08-18 21:15:10 +02:00
|
|
|
player = player_fab.instance()
|
|
|
|
player_camera = player.get_node("Camera2D")
|
2020-08-18 17:45:22 +02:00
|
|
|
level.add_child_below_node(level.get_node("Entities"), player)
|
2020-08-17 17:27:28 +02:00
|
|
|
playing = true
|
|
|
|
player_camera.make_current()
|
|
|
|
player.connect('frame_changed', self, 'update_camera')
|
2020-08-18 16:55:40 +02:00
|
|
|
|
|
|
|
# Spawn player
|
2020-08-18 21:22:14 +02:00
|
|
|
player.position = spawn_pos * 16 + Vector2(8, 8)
|
2020-08-18 16:55:40 +02:00
|
|
|
|
2020-08-18 21:15:10 +02:00
|
|
|
func spawn_entities(level : Node):
|
|
|
|
exit_points = []
|
|
|
|
var entities = Node2D.new()
|
|
|
|
entities.name = 'Entities'
|
|
|
|
level.add_child_below_node(level.get_node('Props'), entities)
|
|
|
|
|
|
|
|
for layer in level.get_children():
|
|
|
|
if !(layer is TileMap): continue
|
|
|
|
var tm = layer as TileMap
|
|
|
|
var tileset = tm.tile_set
|
2020-08-18 17:45:22 +02:00
|
|
|
|
2020-08-18 21:15:10 +02:00
|
|
|
# Flatfish
|
|
|
|
var fishes = []
|
|
|
|
for tile in ['flatfish_s', 'flatfish_s_hidden', 'flatfish_t', 'flatfish_t_hidden']:
|
|
|
|
fishes += tm.get_used_cells_by_id(tileset.find_tile_by_name(tile))
|
|
|
|
|
|
|
|
for cell in fishes:
|
|
|
|
var fish = Flatfish.new()
|
|
|
|
fish.position = cell * 16 + Vector2(8, 8)
|
|
|
|
var t = tm.is_cell_transposed(cell.x, cell.y)
|
|
|
|
var x = tm.is_cell_x_flipped(cell.x, cell.y)
|
|
|
|
var y = tm.is_cell_y_flipped(cell.x, cell.y)
|
|
|
|
if t && x:
|
|
|
|
fish.rotation_degrees = 90
|
|
|
|
elif x && y:
|
|
|
|
fish.rotation_degrees = 180
|
|
|
|
elif t && y:
|
|
|
|
fish.rotation_degrees = 270
|
|
|
|
entities.add_child(fish)
|
|
|
|
tm.set_cell(cell.x, cell.y, -1)
|
|
|
|
|
|
|
|
# Spawn point
|
|
|
|
for cell in tm.get_used_cells_by_id(tileset.find_tile_by_name('start')):
|
|
|
|
spawn_pos = cell
|
2020-08-20 16:19:53 +02:00
|
|
|
tm.set_cell(cell.x, cell.y, -1)
|
2020-08-18 16:55:40 +02:00
|
|
|
|
2020-08-18 21:15:10 +02:00
|
|
|
# Exit points
|
|
|
|
for cell in tm.get_used_cells_by_id(tileset.find_tile_by_name('finish')):
|
|
|
|
exit_points.append(cell)
|
2020-08-19 11:56:10 +02:00
|
|
|
|
|
|
|
# Logs
|
|
|
|
for d in ['horizontal', 'vertical']:
|
|
|
|
for i in [1, 2, 3, 4]:
|
|
|
|
for cell in tm.get_used_cells_by_id(tileset.find_tile_by_name('log_' + d + '_' + String(i))):
|
|
|
|
var log_entity = LogEntity.new(LogEntity.Type.H if d == 'horizontal' else LogEntity.Type.V, i - 1)
|
|
|
|
log_entity.spawn_at(cell * 16 + Vector2(16, 16))
|
|
|
|
entities.add_child(log_entity)
|
|
|
|
tm.set_cell(cell.x, cell.y, -1)
|
2020-08-18 16:55:40 +02:00
|
|
|
|
|
|
|
var go_right = false
|
|
|
|
var go_left = false
|
2020-08-18 17:45:22 +02:00
|
|
|
var do_interact = false
|
2020-08-17 17:27:28 +02:00
|
|
|
|
|
|
|
func _input(event):
|
2020-08-18 16:55:40 +02:00
|
|
|
if playing:
|
2020-08-17 17:27:28 +02:00
|
|
|
if event.is_action_pressed('right'):
|
2020-08-18 16:55:40 +02:00
|
|
|
go_right = true
|
2020-08-17 17:27:28 +02:00
|
|
|
if event.is_action_pressed('left'):
|
2020-08-18 16:55:40 +02:00
|
|
|
go_left = true
|
2020-08-18 17:45:22 +02:00
|
|
|
if event.is_action_pressed('interact'):
|
|
|
|
do_interact = true
|
2020-08-18 16:55:40 +02:00
|
|
|
|
|
|
|
if event.is_action_released('right'):
|
|
|
|
go_right = false
|
|
|
|
if event.is_action_released('left'):
|
|
|
|
go_left = false
|
2020-08-18 17:45:22 +02:00
|
|
|
if event.is_action_released('interact'):
|
|
|
|
do_interact = false
|
2020-08-18 16:55:40 +02:00
|
|
|
|
2020-08-18 18:49:16 +02:00
|
|
|
var trying_to_move = false
|
2020-08-18 16:55:40 +02:00
|
|
|
func move():
|
2020-08-18 18:49:16 +02:00
|
|
|
if !playing || trying_to_move || is_interacting || is_camera_moving: return
|
|
|
|
|
|
|
|
trying_to_move = true
|
|
|
|
yield(get_tree(), "physics_frame")
|
|
|
|
yield(get_tree(), "physics_frame")
|
|
|
|
if go_right && !go_left && can_move_towards('Right'):
|
|
|
|
move_right()
|
|
|
|
elif go_left && !go_right && can_move_towards('Left'):
|
|
|
|
move_left()
|
|
|
|
trying_to_move = false
|
|
|
|
|
2020-08-20 19:40:24 +02:00
|
|
|
func _process(_delta):
|
2020-08-18 18:49:16 +02:00
|
|
|
interact()
|
|
|
|
move()
|
|
|
|
|
|
|
|
func can_move_towards(sensorName : String) -> bool:
|
|
|
|
var sensor = player.get_node("Sensors/" + sensorName) as Area2D
|
2020-08-19 11:56:10 +02:00
|
|
|
var bodies = sensor.get_overlapping_bodies()
|
|
|
|
var areas = sensor.get_overlapping_areas()
|
|
|
|
|
|
|
|
# Check for pushables and push
|
|
|
|
for body in bodies + areas:
|
|
|
|
var p = body.get_parent()
|
|
|
|
if p is LogEntity:
|
|
|
|
var rot = int(floor(player.rotation_degrees / 90.0)) % 4
|
|
|
|
var dir = 1 if (rot == 0 || rot == 1) && sensorName == 'Right' || (rot == 2 || rot == 3) && sensorName == 'Left' else -1
|
|
|
|
|
|
|
|
# Push and fall
|
|
|
|
if p.push((player.position / 16) - Vector2(0.5, 0.5), dir):
|
|
|
|
var level = $Game.get_node(levels[current_level])
|
|
|
|
var pos = (p.position / 16) - Vector2(1, 1)
|
|
|
|
for layer in level.get_children():
|
|
|
|
if !(layer is TileMap): continue
|
|
|
|
var tm = layer as TileMap
|
|
|
|
var tileset = tm.tile_set
|
|
|
|
|
|
|
|
var name = tileset.tile_get_name(tm.get_cellv(pos))
|
|
|
|
if name != null && name.rfind('hole_') == 0:
|
|
|
|
tm.set_cellv(pos, tileset.find_tile_by_name("log_in_" + name), tm.is_cell_x_flipped(pos.x, pos.y), tm.is_cell_y_flipped(pos.x, pos.y), tm.is_cell_transposed(pos.x, pos.y))
|
|
|
|
p.queue_free()
|
|
|
|
|
|
|
|
return bodies.size() == 0 && areas.size() == 0
|
2020-08-17 17:27:28 +02:00
|
|
|
|
|
|
|
func move_right():
|
|
|
|
is_camera_moving = true
|
|
|
|
player.play('moving')
|
|
|
|
update_camera()
|
|
|
|
|
|
|
|
yield(player, 'animation_finished')
|
|
|
|
|
|
|
|
player.play('default')
|
|
|
|
player.frame = 0
|
2020-08-18 17:45:22 +02:00
|
|
|
offset_player(16)
|
2020-08-18 16:55:40 +02:00
|
|
|
is_camera_moving = false
|
2020-08-18 21:15:10 +02:00
|
|
|
if !check_exit(): move()
|
2020-08-17 17:27:28 +02:00
|
|
|
|
|
|
|
func move_left():
|
|
|
|
is_camera_moving = true
|
2020-08-18 17:45:22 +02:00
|
|
|
offset_player(-16)
|
2020-08-17 17:27:28 +02:00
|
|
|
player.play('moving', true)
|
|
|
|
update_camera()
|
|
|
|
|
|
|
|
yield(player, 'animation_finished')
|
|
|
|
|
|
|
|
player.play('default')
|
|
|
|
player.frame = 0
|
2020-08-18 16:55:40 +02:00
|
|
|
is_camera_moving = false
|
2020-08-18 21:15:10 +02:00
|
|
|
if !check_exit(): move()
|
|
|
|
|
|
|
|
func check_exit() -> bool:
|
|
|
|
var player_pos = (player.position - Vector2(8, 8)) / 16
|
2020-08-20 16:19:53 +02:00
|
|
|
|
|
|
|
if !Globals.ui_interact_flatfish_tip:
|
|
|
|
var level = $Game.get_node(levels[current_level])
|
|
|
|
var shown = false
|
|
|
|
for e in level.get_node('Entities').get_children():
|
|
|
|
if e is Flatfish && e.position == player.position:
|
|
|
|
$GameControlIndicator.show_press('interact')
|
|
|
|
$GameControlIndicator.position = player.position + Vector2(0, 8 + 16)
|
|
|
|
shown = true
|
|
|
|
break
|
|
|
|
if !shown:
|
|
|
|
$GameControlIndicator.hide()
|
|
|
|
|
2020-08-18 21:15:10 +02:00
|
|
|
print(player_pos)
|
|
|
|
for exit in exit_points:
|
|
|
|
if player_pos == exit:
|
2020-08-19 11:56:10 +02:00
|
|
|
print('exit')
|
2020-08-18 21:15:10 +02:00
|
|
|
next_level()
|
|
|
|
return true
|
|
|
|
return false
|
2020-08-17 17:27:28 +02:00
|
|
|
|
2020-08-18 17:45:22 +02:00
|
|
|
func offset_player(offset):
|
|
|
|
var r = int(ceil(player.rotation_degrees / 90.0)) % 4
|
|
|
|
if r == 0: player.position.x += offset
|
|
|
|
elif r == 1: player.position.y += offset
|
|
|
|
elif r == 2: player.position.x -= offset
|
|
|
|
elif r == 3: player.position.y -= offset
|
|
|
|
|
2020-08-17 17:27:28 +02:00
|
|
|
const animation_steps = [3, 6, 10, 13]
|
|
|
|
var is_camera_moving = false
|
|
|
|
func update_camera():
|
2020-08-18 17:45:22 +02:00
|
|
|
if is_camera_moving && !is_interacting:
|
2020-08-17 17:27:28 +02:00
|
|
|
player_camera.position = Vector2(animation_steps[player.frame], 0)
|
|
|
|
else:
|
|
|
|
player_camera.position = Vector2()
|
2020-08-18 17:45:22 +02:00
|
|
|
|
|
|
|
var is_interacting = false
|
|
|
|
func interact():
|
2020-08-18 18:49:16 +02:00
|
|
|
if !playing || !do_interact || is_interacting || trying_to_move || is_camera_moving: return
|
2020-08-18 17:45:22 +02:00
|
|
|
is_interacting = true
|
|
|
|
|
2020-08-18 21:15:10 +02:00
|
|
|
var level = $Game.get_node(levels[current_level])
|
2020-08-18 17:45:22 +02:00
|
|
|
var entities = level.get_node('Entities').get_children()
|
|
|
|
|
|
|
|
var fish = null
|
|
|
|
for e in entities:
|
|
|
|
if e is Flatfish && e.position == player.position:
|
|
|
|
fish = e
|
|
|
|
break
|
|
|
|
|
|
|
|
if fish != null:
|
2020-08-20 16:19:53 +02:00
|
|
|
Globals.ui_interact_flatfish_tip = true
|
|
|
|
$GameControlIndicator.hide()
|
|
|
|
|
2020-08-18 17:45:22 +02:00
|
|
|
fish.appear()
|
|
|
|
yield(get_tree().create_timer(0.2), "timeout")
|
|
|
|
|
|
|
|
fish.do_rotation()
|
|
|
|
player.rotation_degrees += 45
|
|
|
|
yield(get_tree().create_timer(0.2), "timeout")
|
|
|
|
|
|
|
|
fish.do_rotation()
|
|
|
|
player.rotation_degrees += 45
|
|
|
|
yield(get_tree().create_timer(0.2), "timeout")
|
|
|
|
|
|
|
|
fish.disappear()
|
|
|
|
|
|
|
|
is_interacting = false
|
|
|
|
if fish != null: interact()
|