From 3b1af3754d044de45b50ddabceac1b086d4af7ee Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Tue, 18 Aug 2020 21:15:10 +0200 Subject: [PATCH] game1: make start and finish work and fix collisions --- scenes/game1.tscn | 11 +- scenes/game1/Level2.tscn | 3 +- scenes/game1/Level4.tscn | 1 - scripts/game1/Game1Script.gd | 124 ++++++++++++-------- scripts/game1/opening2_next_step_trigger.gd | 2 +- 5 files changed, 81 insertions(+), 60 deletions(-) diff --git a/scenes/game1.tscn b/scenes/game1.tscn index 40e0e98..5279c40 100644 --- a/scenes/game1.tscn +++ b/scenes/game1.tscn @@ -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 diff --git a/scenes/game1/Level2.tscn b/scenes/game1/Level2.tscn index 344eed8..8c46d46 100644 --- a/scenes/game1/Level2.tscn +++ b/scenes/game1/Level2.tscn @@ -13,7 +13,6 @@ format = 1 tile_data = PoolIntArray( -524294, 0, 0, -524293, 0, 0, -524292, 0, 0, -524291, 0, 0, -524290, 0, 0, -524289, 0, 0, -589824, 0, 0, -589823, 0, 0, -589822, 0, 0, -589821, 0, 0, -589820, 0, 0, -589819, 0, 0, -589818, 0, 0, -589817, 0, 0, -589816, 0, 0, -589815, 0, 0, -589814, 0, 0, -589813, 0, 0, -589812, 0, 0, -589811, 0, 0, -589810, 0, 0, -589809, 0, 0, -589808, 0, 0, -589807, 0, 0, -589806, 0, 0, -589805, 0, 0, -589804, 0, 0, -589803, 0, 0, -589802, 0, 0, -589801, 0, 0, -458758, 0, 0, -458757, 0, 0, -458756, 0, 0, -458755, 0, 0, -458754, 0, 0, -458753, 0, 0, -524288, 0, 0, -524287, 0, 0, -524286, 0, 0, -524285, 0, 0, -524284, 0, 0, -524283, 0, 0, -524282, 0, 0, -524281, 0, 0, -524280, 0, 0, -524279, 0, 0, -524278, 0, 0, -524277, 0, 0, -524276, 0, 0, -524275, 0, 0, -524274, 0, 0, -524273, 0, 0, -524272, 0, 0, -524271, 0, 0, -524270, 0, 0, -524269, 0, 0, -524268, 0, 0, -524267, 0, 0, -524266, 0, 0, -524265, 0, 0, -393222, 0, 0, -393221, 0, 0, -393220, 0, 0, -393219, 0, 0, -393218, 0, 0, -393217, 0, 0, -458752, 0, 0, -458751, 0, 0, -458750, 0, 0, -458749, 0, 0, -458748, 0, 0, -458747, 0, 0, -458746, 0, 0, -458745, 0, 0, -458744, 0, 0, -458743, 0, 0, -458742, 0, 0, -458741, 0, 0, -458740, 0, 0, -458739, 0, 0, -458738, 0, 0, -458737, 0, 0, -458736, 0, 0, -458735, 0, 0, -458734, 0, 0, -458733, 0, 0, -458732, 0, 0, -458731, 0, 0, -458730, 0, 0, -458729, 0, 0, -327686, 0, 0, -327685, 0, 0, -327684, 0, 0, -327683, 0, 0, -327682, 536870912, 0, -327681, 0, 0, -393216, 0, 0, -393215, 0, 0, -393214, 0, 0, -393213, 0, 0, -393212, 0, 0, -393211, 0, 0, -393210, 0, 0, -393209, 0, 0, -393208, 0, 0, -393207, 0, 0, -393206, 0, 0, -393205, 0, 0, -393204, 0, 0, -393203, 0, 0, -393202, 0, 0, -393201, 0, 0, -393200, 0, 0, -393199, 0, 0, -393198, 0, 0, -393197, 0, 0, -393196, 0, 0, -393195, 0, 0, -393194, 0, 0, -393193, 0, 0, -262150, 0, 0, -262149, 0, 0, -262148, 536870912, 0, -262147, 536870912, 0, -262146, 536870912, 0, -262145, 0, 0, -327680, 0, 0, -327679, 0, 0, -327678, 0, 0, -327677, 0, 0, -327676, 0, 0, -327675, 0, 0, -327674, 0, 0, -327673, 0, 0, -327672, 0, 0, -327671, 0, 0, -327670, 0, 0, -327669, 0, 0, -327668, 0, 0, -327667, 0, 0, -327666, 0, 0, -327665, 0, 0, -327664, 0, 0, -327663, 0, 0, -327662, 0, 0, -327661, 0, 0, -327660, 0, 0, -327659, 0, 0, -327658, 0, 0, -327657, 0, 0, -196614, 0, 0, -196613, 0, 0, -196612, 536870912, 0, -196611, 536870912, 0, -196610, 536870912, 0, -196609, 0, 0, -262144, 0, 0, -262143, 0, 0, -262142, 0, 0, -262141, 0, 0, -262140, 0, 0, -262139, 0, 0, -262138, 0, 0, -262137, 0, 0, -262136, 0, 0, -262135, 0, 0, -262134, 0, 0, -262133, 0, 0, -262132, 0, 0, -262131, 0, 0, -262130, 0, 0, -262129, 0, 0, -262128, 0, 0, -262127, 0, 0, -262126, 0, 0, -262125, 0, 0, -262124, 0, 0, -262123, 0, 0, -262122, 0, 0, -262121, 0, 0, -131078, 0, 0, -131077, 0, 0, -131076, 0, 0, -131075, 536870912, 0, -131074, 0, 0, -131073, 0, 0, -196608, 0, 0, -196607, 0, 0, -196606, 0, 0, -196605, 0, 0, -196604, 0, 0, -196603, 0, 0, -196602, 0, 0, -196601, 0, 0, -196600, 0, 0, -196599, 0, 0, -196598, 0, 0, -196597, 0, 0, -196596, 0, 0, -196595, 0, 0, -196594, 0, 0, -196593, 0, 0, -196592, 0, 0, -196591, 0, 0, -196590, 0, 0, -196589, 0, 0, -196588, 0, 0, -196587, 0, 0, -196586, 0, 0, -196585, 0, 0, -65542, 0, 0, -65541, 0, 0, -65540, 0, 0, -65539, 536870912, 0, -65538, 0, 0, -65537, 0, 0, -131072, 0, 0, -131071, 0, 0, -131070, 0, 0, -131069, 0, 0, -131068, 0, 0, -131067, 0, 0, -131066, 0, 0, -131065, 0, 0, -131064, 0, 0, -131063, 0, 0, -131062, 0, 0, -131061, 0, 0, -131060, 0, 0, -131059, 0, 0, -131058, 0, 0, -131057, 0, 0, -131056, 0, 0, -131055, 0, 0, -131054, 0, 0, -131053, 0, 0, -131052, 0, 0, -131051, 0, 0, -131050, 0, 0, -131049, 0, 0, -6, 0, 0, -5, 0, 0, -4, 536870912, 0, -3, 536870912, 0, -2, 0, 0, -1, 0, 0, -65536, 0, 0, -65535, 0, 0, -65534, 0, 0, -65533, 0, 0, -65532, 0, 0, -65531, 0, 0, -65530, 0, 0, -65529, 0, 0, -65528, 0, 0, -65527, 0, 0, -65526, 0, 0, -65525, 0, 0, -65524, 0, 0, -65523, 0, 0, -65522, 0, 0, -65521, 0, 0, -65520, 0, 0, -65519, 0, 0, -65518, 0, 0, -65517, 0, 0, -65516, 0, 0, -65515, 0, 0, -65514, 0, 0, -65513, 0, 0, 65530, 0, 0, 65531, 0, 0, 65532, 0, 0, 65533, 0, 0, 65534, 0, 0, 65535, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 0, 5, 0, 0, 6, 0, 0, 7, 0, 0, 8, 0, 0, 9, 0, 0, 10, 0, 0, 11, 0, 0, 12, 0, 0, 13, 0, 0, 14, 0, 0, 15, 0, 0, 16, 0, 0, 17, 0, 0, 18, 0, 0, 19, 0, 0, 20, 0, 0, 21, 0, 0, 22, 0, 0, 23, 0, 0, 131066, 0, 0, 131067, 0, 0, 131068, 0, 0, 131069, 0, 0, 131070, 0, 0, 131071, 0, 0, 65536, 0, 0, 65537, 0, 0, 65538, 0, 0, 65539, 0, 0, 65540, 0, 0, 65541, 0, 0, 65542, 0, 0, 65543, 0, 0, 65544, 0, 0, 65545, 0, 0, 65546, 0, 0, 65547, 0, 0, 65548, 0, 0, 65549, 0, 0, 65550, 0, 0, 65551, 0, 0, 65552, 0, 0, 65553, 0, 0, 65554, 0, 0, 65555, 0, 0, 65556, 0, 0, 65557, 0, 0, 65558, 0, 0, 65559, 0, 0, 196602, 0, 0, 196603, 0, 0, 196604, 0, 0, 196605, 0, 0, 196606, 0, 0, 196607, 0, 0, 131072, 0, 0, 131073, 0, 0, 131074, 0, 0, 131075, 0, 0, 131076, 0, 0, 131077, 0, 0, 131078, 0, 0, 131079, 0, 0, 131080, 0, 0, 131081, 0, 0, 131082, 0, 0, 131083, 0, 0, 131084, 0, 0, 131085, 0, 0, 131086, 0, 0, 131087, 0, 0, 131088, 0, 0, 131089, 0, 0, 131090, 0, 0, 131091, 0, 0, 131092, 0, 0, 131093, 0, 0, 131094, 0, 0, 131095, 0, 0, 262138, 0, 0, 262139, 0, 0, 262140, 0, 0, 262141, 0, 0, 262142, 0, 0, 262143, 0, 0, 196608, 0, 0, 196609, 0, 0, 196610, 0, 0, 196611, 0, 0, 196612, 0, 0, 196613, 0, 0, 196614, 0, 0, 196615, 0, 0, 196616, 0, 0, 196617, 0, 0, 196618, 0, 0, 196619, 0, 0, 196620, 0, 0, 196621, 0, 0, 196622, 0, 0, 196623, 0, 0, 196624, 0, 0, 196625, 0, 0, 196626, 0, 0, 196627, 0, 0, 196628, 0, 0, 196629, 0, 0, 196630, 0, 0, 196631, 0, 0, 327674, 0, 0, 327675, 0, 0, 327676, 0, 0, 327677, 0, 0, 327678, 0, 0, 327679, 0, 0, 262144, 0, 0, 262145, 0, 0, 262146, 0, 0, 262147, 0, 0, 262148, 0, 0, 262149, 0, 0, 262150, 0, 0, 262151, 0, 0, 262152, 0, 0, 262153, 0, 0, 262154, 0, 0, 262155, 0, 0, 262156, 0, 0, 262157, 0, 0, 262158, 0, 0, 262159, 0, 0, 262160, 0, 0, 262161, 0, 0, 262162, 0, 0, 262163, 0, 0, 262164, 0, 0, 262165, 0, 0, 262166, 0, 0, 262167, 0, 0, 393210, 0, 0, 393211, 0, 0, 393212, 0, 0, 393213, 0, 0, 393214, 0, 0, 393215, 0, 0, 327680, 0, 0, 327681, 0, 0, 327682, 0, 0, 327683, 0, 0, 327684, 0, 0, 327685, 0, 0, 327686, 0, 0, 327687, 0, 0, 327688, 0, 0, 327689, 0, 0, 327690, 0, 0, 327691, 0, 0, 327692, 0, 0, 327693, 0, 0, 327694, 0, 0, 327695, 0, 0, 327696, 0, 0, 327697, 0, 0, 327698, 0, 0, 327699, 0, 0, 327700, 0, 0, 327701, 0, 0, 327702, 0, 0, 327703, 0, 0, 458746, 0, 0, 458747, 0, 0, 458748, 0, 0, 458749, 0, 0, 458750, 0, 0, 458751, 0, 0, 393216, 0, 0, 393217, 0, 0, 393218, 0, 0, 393219, 0, 0, 393220, 0, 0, 393221, 0, 0, 393222, 0, 0, 393223, 0, 0, 393224, 0, 0, 393225, 0, 0, 393226, 0, 0, 393227, 0, 0, 393228, 0, 0, 393229, 0, 0, 393230, 0, 0, 393231, 0, 0, 393232, 0, 0, 393233, 0, 0, 393234, 0, 0, 393235, 0, 0, 393236, 0, 0, 393237, 0, 0, 393238, 0, 0, 393239, 0, 0, 524282, 0, 0, 524283, 0, 0, 524284, 0, 0, 524285, 0, 0, 524286, 0, 0, 524287, 0, 0, 458752, 0, 0, 458753, 0, 0, 458754, 0, 0, 458755, 0, 0, 458756, 0, 0, 458757, 0, 0, 458758, 0, 0, 458759, 0, 0, 458760, 0, 0, 458761, 0, 0, 458762, 0, 0, 458763, 0, 0, 458764, 0, 0, 458765, 0, 0, 458766, 0, 0, 458767, 0, 0, 458768, 0, 0, 458769, 0, 0, 458770, 0, 0, 458771, 0, 0, 458772, 0, 0, 458773, 0, 0, 458774, 0, 0, 458775, 0, 0, 589818, 0, 0, 589819, 0, 0, 589820, 0, 0, 589821, 0, 0, 589822, 0, 0, 589823, 0, 0, 524288, 0, 0, 524289, 0, 0, 524290, 0, 0, 524291, 0, 0, 524292, 0, 0, 524293, 0, 0, 524294, 0, 0, 524295, 0, 0, 524296, 0, 0, 524297, 0, 0, 524298, 0, 0, 524299, 0, 0, 524300, 0, 0, 524301, 0, 0, 524302, 0, 0, 524303, 0, 0, 524304, 0, 0, 524305, 0, 0, 524306, 0, 0, 524307, 0, 0, 524308, 0, 0, 524309, 0, 0, 524310, 0, 0, 524311, 0, 0, 655354, 0, 0, 655355, 0, 0, 655356, 0, 0, 655357, 0, 0, 655358, 0, 0, 655359, 0, 0, 589824, 0, 0, 589825, 0, 0, 589826, 0, 0, 589827, 0, 0, 589828, 0, 0, 589829, 0, 0, 589830, 0, 0, 589831, 0, 0, 589832, 0, 0, 589833, 0, 0, 589834, 0, 0, 589835, 0, 0, 589836, 0, 0, 589837, 0, 0, 589838, 0, 0, 589839, 0, 0, 589840, 0, 0, 589841, 0, 0, 589842, 0, 0, 589843, 0, 0, 589844, 0, 0, 589845, 0, 0, 589846, 0, 0, 589847, 0, 0 ) [node name="Ground" type="TileMap" parent="."] -position = Vector2( -1, 0 ) tile_set = ExtResource( 1 ) cell_size = Vector2( 16, 16 ) cell_quadrant_size = 8 @@ -35,7 +34,7 @@ cell_size = Vector2( 16, 16 ) cell_quadrant_size = 8 cell_custom_transform = Transform2D( 0, 0, 0, 0, 0, 0 ) format = 1 -tile_data = PoolIntArray( -327678, 11, 0, -327671, 25, 0, -262143, 8, 0, -262139, 20, 0, -262138, 10, 0, -131075, 20, 0, -196601, 10, 0, -196591, 28, 0, -65538, 8, 0, -131072, 41, 0, -131063, 15, 0, -131062, 21, 0, -131057, 19, 0, -5, 45, 0, -3, 43, 0, -1, 15, 0, -65534, 35, 0, -65531, 41, 0, -65527, 55, 0, -65524, 36, 0, 65530, 39, 0, 65532, 42, 0, 65535, 1, 0, 131071, 24, 0, 65536, 10, 0, 65538, 15, 0, 65539, 8, 0, 65541, 25, 3, 65547, 14, 0, 65552, 41, 0, 196606, 24, 0, 196607, 21, 0, 131077, 14, 0, 131082, 15, 0, 131083, 11, 0, 131084, 25, 1, 131086, 18, 0, 196609, 40, 0, 196611, 41, 0, 196612, 39, 0, 196613, 22, 0, 196614, 20, 0, 196621, 44, 0, 262149, 24, 0, 262151, 13, 0, 262153, 22, 0 ) +tile_data = PoolIntArray( -327678, 11, 0, -327671, 25, 0, -262143, 8, 0, -262139, 20, 0, -262138, 10, 0, -131075, 20, 0, -196601, 10, 0, -196591, 28, 0, -65538, 8, 0, -131072, 41, 0, -131063, 15, 0, -131062, 21, 0, -131057, 19, 0, -5, 45, 0, -3, 43, 0, -1, 15, 0, -65534, 35, 0, -65531, 41, 0, -65527, 55, 0, -65524, 36, 0, 65530, 39, 0, 65532, 42, 0, 131071, 24, 0, 65536, 10, 0, 65538, 15, 0, 65539, 8, 0, 65541, 25, 3, 65547, 14, 0, 65552, 41, 0, 196606, 24, 0, 196607, 21, 0, 131077, 14, 0, 131082, 15, 0, 131083, 11, 0, 131084, 25, 1, 131086, 18, 0, 196609, 40, 0, 196611, 41, 0, 196612, 39, 0, 196613, 22, 0, 196614, 20, 0, 196621, 44, 0, 262149, 24, 0, 262151, 13, 0, 262153, 22, 0 ) [node name="Air" type="TileMap" parent="."] z_index = 1 diff --git a/scenes/game1/Level4.tscn b/scenes/game1/Level4.tscn index 74fbb1f..1fdb52b 100644 --- a/scenes/game1/Level4.tscn +++ b/scenes/game1/Level4.tscn @@ -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 ) diff --git a/scripts/game1/Game1Script.gd b/scripts/game1/Game1Script.gd index 7491a77..691d1bb 100644 --- a/scripts/game1/Game1Script.gd +++ b/scripts/game1/Game1Script.gd @@ -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 diff --git a/scripts/game1/opening2_next_step_trigger.gd b/scripts/game1/opening2_next_step_trigger.gd index 279ec74..9f56b7e 100644 --- a/scripts/game1/opening2_next_step_trigger.gd +++ b/scripts/game1/opening2_next_step_trigger.gd @@ -9,4 +9,4 @@ func _ready(): func on_body_entered(body : Node): if body.name == 'Player': - root.launch_game() + root.start_game()