game1: make start and finish work and fix collisions

This commit is contained in:
Alice Gaudon 2020-08-18 21:15:10 +02:00
parent 4493cecedc
commit 3b1af3754d
5 changed files with 81 additions and 60 deletions

View File

@ -1,11 +1,10 @@
[gd_scene load_steps=38 format=2]
[gd_scene load_steps=36 format=2]
[ext_resource path="res://images/game1/opening.tres" type="SpriteFrames" id=1]
[ext_resource path="res://images/game1/opening2bg.tres" type="SpriteFrames" id=2]
[ext_resource path="res://scripts/game1/Game1Script.gd" type="Script" id=3]
[ext_resource path="res://scenes/game1/opening2_player.tscn" type="PackedScene" id=4]
[ext_resource path="res://scripts/game1/opening2_next_step_trigger.gd" type="Script" id=5]
[ext_resource path="res://scenes/game1/Level2.tscn" type="PackedScene" id=6]
[ext_resource path="res://images/goo/BigGoo1.png" type="Texture" id=8]
[ext_resource path="res://images/goo/BigGoo1_Outlines.png" type="Texture" id=9]
[ext_resource path="res://images/goo/BigGoo2_Outlines.png" type="Texture" id=10]
@ -27,7 +26,6 @@
[ext_resource path="res://images/goo/goo7_Outlines.png" type="Texture" id=26]
[ext_resource path="res://images/goo/goo8.png" type="Texture" id=27]
[ext_resource path="res://images/goo/goo8_Outlines.png" type="Texture" id=28]
[ext_resource path="res://scenes/game1/Level1.tscn" type="PackedScene" id=29]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 114.063, 10 )
@ -82,13 +80,7 @@ script = ExtResource( 3 )
[node name="Game" type="Node2D" parent="."]
[node name="Level1" parent="Game" instance=ExtResource( 29 )]
[node name="Level2" parent="Game" instance=ExtResource( 6 )]
visible = false
[node name="Opening2" type="Node2D" parent="."]
visible = false
[node name="Opening2Bg" type="AnimatedSprite" parent="Opening2"]
frames = ExtResource( 2 )
@ -229,6 +221,5 @@ texture = ExtResource( 27 )
normal_map = ExtResource( 28 )
[node name="Opening1" type="AnimatedSprite" parent="."]
visible = false
frames = ExtResource( 1 )
centered = false

File diff suppressed because one or more lines are too long

View File

@ -37,7 +37,6 @@ format = 1
tile_data = PoolIntArray( -786419, 50, 11, -720887, 50, 65536, -655350, 50, 3, -589814, 9, 0, -589811, 22, 0, -524280, 21, 0, -524276, 14, 0, -327681, 49, 65549, -393214, 44, 0, -393210, 10, 0, -393208, 23, 0, -393207, 11, 0, -393204, 15, 0, -393203, 49, 11, -327680, 44, 0, -327677, 44, 0, -327676, 50, 65546, -327675, 22, 0, -327667, 21, 0, -327664, 50, 13, -262142, 44, 0, -262141, 50, 10, -262131, 5, 0, -262130, 11, 0, -262126, 22, 0, -131073, 9, 0, -196607, 44, 0, -196606, 40, 0, -196593, 49, 11, -196592, 29, 0, -65539, 22, 0, -131065, 23, 0, -131061, 56, 0, -1, 49, 65551, -65528, 26, 0, -65522, 50, 13, -65520, 27, 0, 65541, 50, 65544, 65551, 30, 0, 196607, 49, 12, 131075, 20, 0, 131085, 10, 0, 262142, 23, 0, 196608, 14, 0, 196612, 8, 0, 196614, 12, 0, 196617, 13, 0, 196618, 9, 0, 196620, 11, 0, 262145, 50, 1, 262148, 49, 16, 262151, 50, 65542, 262152, 12, 0, 262153, 50, 2, 262155, 50, 13, 262162, 50, 10, 327682, 50, 10, 327687, 21, 0, 327698, 50, 9, 393220, 22, 0, 393231, 12, 0, 393233, 50, 12, 458766, 22, 0 )
[node name="Air" type="TileMap" parent="."]
position = Vector2( -1, 0 )
z_index = 1
tile_set = ExtResource( 1 )
cell_size = Vector2( 16, 16 )

View File

@ -3,71 +3,93 @@ extends Node
var playing = false
onready var player = preload('res://scenes/game1/Player.tscn').instance()
onready var player_camera = player.get_node("Camera2D")
onready var player_fab = preload('res://scenes/game1/Player.tscn')
var player : AnimatedSprite
var player_camera : Camera2D
onready var levels = [
$Game/Level1,
$Game/Level2,
'Level1',
'Level2',
'Level3',
'Level4',
'Level5',
]
var current_level = 0
var current_level = -1
var spawn_pos = Vector2()
var exit_points = []
func _ready():
launch_game()
$Opening1.play('default')
yield($Opening1, 'animation_finished')
$Opening1.hide()
$Opening1.queue_free()
func launch_game():
# Prepare levels
spawn_entities()
func start_game():
# Hide opening
$Opening2.hide()
$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
# Prepare level
var level = load("res://scenes/game1/" + levels[current_level] + ".tscn").instance()
$Game.add_child(level)
spawn_entities(level)
# Prepare player
var level = levels[current_level]
player = player_fab.instance()
player_camera = player.get_node("Camera2D")
level.add_child_below_node(level.get_node("Entities"), player)
playing = true
player_camera.make_current()
player.connect('frame_changed', self, 'update_camera')
# Spawn player
var spawn_pos = Vector2()
#todo: get spawn pos from map
player.position = spawn_pos + Vector2(8, 8)
func spawn_entities():
for node in levels:
var entities = Node2D.new()
entities.name = 'Entities'
node.add_child_below_node(node.get_node('Props'), entities)
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
for layer in node.get_children():
if !(layer is TileMap): continue
var tm = layer as TileMap
var tileset = tm.tile_set
# 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
# Flatfish cells
var cells = []
for tile in ['flatfish_s', 'flatfish_s_hidden', 'flatfish_t', 'flatfish_t_hidden']:
cells += tm.get_used_cells_by_id(tileset.find_tile_by_name(tile))
for cell in cells:
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)
# Exit points
for cell in tm.get_used_cells_by_id(tileset.find_tile_by_name('finish')):
exit_points.append(cell)
var go_right = false
@ -122,7 +144,7 @@ func move_right():
player.frame = 0
offset_player(16)
is_camera_moving = false
move()
if !check_exit(): move()
func move_left():
is_camera_moving = true
@ -135,7 +157,17 @@ func move_left():
player.play('default')
player.frame = 0
is_camera_moving = false
move()
if !check_exit(): move()
func check_exit() -> bool:
var player_pos = (player.position - Vector2(8, 8)) / 16
print(player_pos)
for exit in exit_points:
if player_pos == exit:
print('OK')
next_level()
return true
return false
func offset_player(offset):
var r = int(ceil(player.rotation_degrees / 90.0)) % 4
@ -159,7 +191,7 @@ func interact():
if !playing || !do_interact || is_interacting || trying_to_move || is_camera_moving: return
is_interacting = true
var level = levels[current_level]
var level = $Game.get_node(levels[current_level])
var entities = level.get_node('Entities').get_children()
var fish = null

View File

@ -9,4 +9,4 @@ func _ready():
func on_body_entered(body : Node):
if body.name == 'Player':
root.launch_game()
root.start_game()