From fc37670deb85681ca40f53e008132fbcd7c38ce9 Mon Sep 17 00:00:00 2001 From: Harmony Honey Date: Sat, 4 Sep 2021 00:35:15 -0400 Subject: [PATCH] rooms! --- project.godot | 4 +- src/actor/Actor.gd | 9 +++-- src/actor/Box.tscn | 1 - src/actor/Player.gd | 6 +-- src/map/A01.tscn | 81 +++++++++++++++++++++++++++++++++++++++++ src/map/Room.gd | 15 ++++++++ src/map/RoomManager.gd | 45 +++++++++++++++++++++++ src/stage/GameCamera.gd | 1 + 8 files changed, 153 insertions(+), 9 deletions(-) create mode 100644 src/map/A01.tscn create mode 100644 src/map/Room.gd create mode 100644 src/map/RoomManager.gd diff --git a/project.godot b/project.godot index 467533e..8135241 100644 --- a/project.godot +++ b/project.godot @@ -87,7 +87,7 @@ _global_script_class_icons={ [application] config/name="gdBox" -run/main_scene="res://src/map/05.tscn" +run/main_scene="res://src/map/A01.tscn" config/icon="res://icon.png" [autoload] @@ -100,7 +100,7 @@ Pause="*res://src/autoload/Pause.tscn" [display] -window/size/width=228 +window/size/width=224 window/size/height=128 window/size/test_width=1368 window/size/test_height=768 diff --git a/src/actor/Actor.gd b/src/actor/Actor.gd index 46c3723..aa82980 100644 --- a/src/actor/Actor.gd +++ b/src/actor/Actor.gd @@ -60,9 +60,9 @@ func _process(delta): time_since_floor += 1 # if outside map - if position.y < -999 or position.y > 999: - dev.out(name + " fell out of world") - queue_free() +# if position.y < -999 or position.y > 999: +# dev.out(name + " fell out of world") +# queue_free() # update() the _draw() when hitbox values are changed (in the editor) func _set_hit_x(value): @@ -97,6 +97,9 @@ func _draw(): func aabb(x1 : int, y1 : int, w1 : int, h1 : int, x2 : int, y2 : int, w2 : int, h2 : int): return x1 < x2 + w2 and x2 < x1 + w1 and y1 < y2 + h2 and y2 < y1 + h1 +func aabb_other(x2 : int, y2 : int, w2 : int, h2 : int): + return position.x < x2 + w2 and x2 < position.x + hitbox_x and position.y < y2 + h2 and y2 < position.y + hitbox_y + func is_overlapping(a : Actor): return aabb(position.x, position.y, hitbox_x, hitbox_y, a.position.x, a.position.y, a.hitbox_x, a.hitbox_y) diff --git a/src/actor/Box.tscn b/src/actor/Box.tscn index a576ad8..0a21aa3 100644 --- a/src/actor/Box.tscn +++ b/src/actor/Box.tscn @@ -4,7 +4,6 @@ [ext_resource path="res://media/audio/sfx/hit10.wav" type="AudioStream" id=2] [ext_resource path="res://src/actor/Box.gd" type="Script" id=3] - [sub_resource type="Animation" id=1] resource_name = "hit" length = 0.4 diff --git a/src/actor/Player.gd b/src/actor/Player.gd index 4ad1ac5..d30a4e4 100644 --- a/src/actor/Player.gd +++ b/src/actor/Player.gd @@ -101,9 +101,9 @@ func _process(delta): return # fall out of stage - if position.y > 100: - death() - return +# if position.y > 100: +# death() +# return # hit spike if speed.y > -1: diff --git a/src/map/A01.tscn b/src/map/A01.tscn new file mode 100644 index 0000000..39878de --- /dev/null +++ b/src/map/A01.tscn @@ -0,0 +1,81 @@ +[gd_scene load_steps=10 format=2] + +[ext_resource path="res://src/stage/Stage.gd" type="Script" id=1] +[ext_resource path="res://src/actor/Player.tscn" type="PackedScene" id=2] +[ext_resource path="res://src/stage/SolidTileMap.tscn" type="PackedScene" id=3] +[ext_resource path="res://src/stage/SpikeTileMap.tscn" type="PackedScene" id=4] +[ext_resource path="res://src/stage/DetailTileMap.tscn" type="PackedScene" id=5] +[ext_resource path="res://src/stage/GameCamera.tscn" type="PackedScene" id=6] +[ext_resource path="res://src/actor/Box.tscn" type="PackedScene" id=7] +[ext_resource path="res://src/map/Room.gd" type="Script" id=8] +[ext_resource path="res://src/map/RoomManager.gd" type="Script" id=9] + +[node name="Stage" type="Node2D"] +script = ExtResource( 1 ) +stage_name = "1-1" + +[node name="SolidTileMap" parent="." instance=ExtResource( 3 )] +tile_data = PoolIntArray( -1048604, 0, 0, -1048603, 0, 0, -1048602, 0, 0, -1048601, 0, 0, -1048600, 0, 0, -1048599, 0, 0, -1048598, 0, 0, -1048597, 0, 0, -1048596, 0, 0, -1048595, 0, 0, -1048594, 0, 0, -1048593, 0, 0, -1048592, 0, 0, -1048591, 0, 0, -1048590, 0, 0, -1048589, 0, 0, -1048588, 0, 0, -1048587, 0, 0, -1048586, 0, 0, -1048585, 0, 0, -1048584, 0, 0, -1048583, 0, 0, -1048582, 0, 0, -1048581, 0, 0, -1048580, 0, 0, -1048579, 0, 0, -1048578, 0, 0, -1048577, 0, 0, -983068, 0, 0, -983041, 0, 0, -917532, 0, 0, -917505, 0, 0, -851996, 0, 0, -851969, 0, 0, -786460, 0, 0, -786433, 0, 0, -720924, 0, 0, -720897, 0, 0, -655388, 0, 0, -655361, 0, 0, -589852, 0, 0, -589825, 0, 0, -524316, 0, 0, -524289, 0, 0, -458780, 0, 0, -458779, 0, 0, -458778, 0, 0, -458753, 0, 0, -393244, 0, 0, -393217, 0, 0, -327708, 0, 0, -327681, 0, 0, -262172, 0, 0, -262169, 0, 0, -262168, 0, 0, -262145, 0, 0, -196636, 0, 0, -196629, 0, 0, -196628, 0, 0, -196609, 0, 0, -131100, 0, 0, -131073, 0, 0, -65564, 0, 0, -65559, 0, 0, -65558, 0, 0, -65538, 0, 0, -65537, 0, 0, -28, 0, 0, -3, 0, 0, -2, 0, 0, -1, 0, 0, 65508, 0, 0, 65511, 0, 0, 65512, 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, 24, 0, 0, 25, 0, 0, 26, 0, 0, 27, 0, 0, 28, 0, 0, 29, 0, 0, 30, 0, 0, 31, 0, 0, 32, 0, 0, 33, 0, 0, 34, 0, 0, 35, 0, 0, 36, 0, 0, 37, 0, 0, 38, 0, 0, 39, 0, 0, 40, 0, 0, 41, 0, 0, 42, 0, 0, 43, 0, 0, 44, 0, 0, 45, 0, 0, 46, 0, 0, 47, 0, 0, 48, 0, 0, 49, 0, 0, 50, 0, 0, 51, 0, 0, 52, 0, 0, 53, 0, 0, 54, 0, 0, 55, 0, 0, 56, 0, 0, 57, 0, 0, 58, 0, 0, 59, 0, 0, 60, 0, 0, 61, 0, 0, 62, 0, 0, 63, 0, 0, 64, 0, 0, 65, 0, 0, 66, 0, 0, 67, 0, 0, 68, 0, 0, 69, 0, 0, 70, 0, 0, 131044, 0, 0, 65563, 0, 0, 65564, 0, 0, 65606, 0, 0, 196580, 0, 0, 196581, 0, 0, 131099, 0, 0, 131100, 0, 0, 131142, 0, 0, 262116, 0, 0, 196635, 0, 0, 196636, 0, 0, 196678, 0, 0, 327652, 0, 0, 262171, 0, 0, 262172, 0, 0, 262214, 0, 0, 393188, 0, 0, 393189, 0, 0, 393190, 0, 0, 393191, 0, 0, 393194, 0, 0, 393195, 0, 0, 393196, 0, 0, 393197, 0, 0, 393200, 0, 0, 393201, 0, 0, 393202, 0, 0, 393205, 0, 0, 393206, 0, 0, 393207, 0, 0, 393208, 0, 0, 393212, 0, 0, 393213, 0, 0, 393214, 0, 0, 393215, 0, 0, 327680, 0, 0, 327681, 0, 0, 327682, 0, 0, 327707, 0, 0, 327708, 0, 0, 327750, 0, 0, 458724, 0, 0, 458749, 0, 0, 458750, 0, 0, 458751, 0, 0, 393216, 0, 0, 393217, 0, 0, 393218, 0, 0, 393243, 0, 0, 393244, 0, 0, 393286, 0, 0, 524260, 0, 0, 524286, 0, 0, 524287, 0, 0, 458752, 0, 0, 458753, 0, 0, 458754, 0, 0, 458755, 0, 0, 458756, 0, 0, 458779, 0, 0, 458780, 0, 0, 458822, 0, 0, 589796, 0, 0, 589823, 0, 0, 524288, 0, 0, 524289, 0, 0, 524290, 0, 0, 524291, 0, 0, 524292, 0, 0, 524315, 0, 0, 524316, 0, 0, 524358, 0, 0, 655332, 0, 0, 655359, 0, 0, 589824, 0, 0, 589825, 0, 0, 589826, 0, 0, 589827, 0, 0, 589828, 0, 0, 589851, 0, 0, 589852, 0, 0, 589894, 0, 0, 720868, 0, 0, 720895, 0, 0, 655360, 0, 0, 655361, 0, 0, 655362, 0, 0, 655363, 0, 0, 655364, 0, 0, 655365, 0, 0, 655366, 0, 0, 655430, 0, 0, 786404, 0, 0, 786431, 0, 0, 720896, 0, 0, 720897, 0, 0, 720898, 0, 0, 720899, 0, 0, 720900, 0, 0, 720901, 0, 0, 720902, 0, 0, 720966, 0, 0, 851940, 0, 0, 851967, 0, 0, 786432, 0, 0, 786433, 0, 0, 786434, 0, 0, 786435, 0, 0, 786436, 0, 0, 786437, 0, 0, 786438, 0, 0, 786439, 0, 0, 786440, 0, 0, 786441, 0, 0, 786442, 0, 0, 786443, 0, 0, 786444, 0, 0, 786445, 0, 0, 786446, 0, 0, 786447, 0, 0, 786448, 0, 0, 786449, 0, 0, 786450, 0, 0, 786451, 0, 0, 786452, 0, 0, 786453, 0, 0, 786454, 0, 0, 786502, 0, 0, 917476, 0, 0, 917503, 0, 0, 851968, 0, 0, 852038, 0, 0, 983012, 0, 0, 983039, 0, 0, 917504, 0, 0, 917574, 0, 0, 1048548, 0, 0, 1048575, 0, 0, 983040, 0, 0, 983041, 0, 0, 983042, 0, 0, 983043, 0, 0, 983044, 0, 0, 983045, 0, 0, 983046, 0, 0, 983047, 0, 0, 983048, 0, 0, 983049, 0, 0, 983050, 0, 0, 983051, 0, 0, 983052, 0, 0, 983053, 0, 0, 983054, 0, 0, 983055, 0, 0, 983056, 0, 0, 983057, 0, 0, 983058, 0, 0, 983059, 0, 0, 983060, 0, 0, 983061, 0, 0, 983062, 0, 0, 983063, 0, 0, 983064, 0, 0, 983065, 0, 0, 983066, 0, 0, 983067, 0, 0, 983068, 0, 0, 983069, 0, 0, 983070, 0, 0, 983071, 0, 0, 983072, 0, 0, 983073, 0, 0, 983074, 0, 0, 983075, 0, 0, 983076, 0, 0, 983077, 0, 0, 983078, 0, 0, 983079, 0, 0, 983080, 0, 0, 983085, 0, 0, 983086, 0, 0, 983087, 0, 0, 983088, 0, 0, 983089, 0, 0, 983090, 0, 0, 983091, 0, 0, 983092, 0, 0, 983093, 0, 0, 983094, 0, 0, 983095, 0, 0, 983096, 0, 0, 983097, 0, 0, 983098, 0, 0, 983099, 0, 0, 983100, 0, 0, 983101, 0, 0, 983102, 0, 0, 983103, 0, 0, 983104, 0, 0, 983105, 0, 0, 983106, 0, 0, 983107, 0, 0, 983108, 0, 0, 983109, 0, 0, 983110, 0, 0, 1114084, 0, 0, 1114111, 0, 0, 1048605, 0, 0, 1048606, 0, 0, 1048607, 0, 0, 1048608, 0, 0, 1048609, 0, 0, 1048610, 0, 0, 1048611, 0, 0, 1048612, 0, 0, 1048613, 0, 0, 1048614, 0, 0, 1048615, 0, 0, 1048616, 0, 0, 1048621, 0, 0, 1048622, 0, 0, 1048623, 0, 0, 1048624, 0, 0, 1048625, 0, 0, 1048626, 0, 0, 1048627, 0, 0, 1048628, 0, 0, 1048629, 0, 0, 1048630, 0, 0, 1048631, 0, 0, 1048632, 0, 0, 1179620, 0, 0, 1179647, 0, 0, 1114141, 0, 0, 1114168, 0, 0, 1245156, 0, 0, 1245183, 0, 0, 1179677, 0, 0, 1179690, 0, 0, 1179691, 0, 0, 1179704, 0, 0, 1310692, 0, 0, 1310719, 0, 0, 1245213, 0, 0, 1245222, 0, 0, 1245223, 0, 0, 1245224, 0, 0, 1245225, 0, 0, 1245226, 0, 0, 1245227, 0, 0, 1245228, 0, 0, 1245229, 0, 0, 1245230, 0, 0, 1245231, 0, 0, 1245240, 0, 0, 1376228, 0, 0, 1376255, 0, 0, 1310749, 0, 0, 1310751, 0, 0, 1310753, 0, 0, 1310755, 0, 0, 1310758, 0, 0, 1310767, 0, 0, 1310770, 0, 0, 1310772, 0, 0, 1310774, 0, 0, 1310776, 0, 0, 1441764, 0, 0, 1441791, 0, 0, 1376285, 0, 0, 1376294, 0, 0, 1376303, 0, 0, 1376312, 0, 0, 1507300, 0, 0, 1507327, 0, 0, 1441821, 0, 0, 1441822, 0, 0, 1441823, 0, 0, 1441824, 0, 0, 1441825, 0, 0, 1441826, 0, 0, 1441827, 0, 0, 1441828, 0, 0, 1441829, 0, 0, 1441830, 0, 0, 1441839, 0, 0, 1441840, 0, 0, 1441841, 0, 0, 1441842, 0, 0, 1441843, 0, 0, 1441844, 0, 0, 1441845, 0, 0, 1441846, 0, 0, 1441847, 0, 0, 1441848, 0, 0, 1572836, 0, 0, 1572863, 0, 0, 1507357, 0, 0, 1507384, 0, 0, 1638372, 0, 0, 1638399, 0, 0, 1572893, 0, 0, 1572920, 0, 0, 1703908, 0, 0, 1703935, 0, 0, 1638429, 0, 0, 1638456, 0, 0, 1769444, 0, 0, 1769471, 0, 0, 1703965, 0, 0, 1703992, 0, 0, 1834980, 0, 0, 1835007, 0, 0, 1769501, 0, 0, 1769528, 0, 0, 1900516, 0, 0, 1900517, 0, 0, 1900518, 0, 0, 1900519, 0, 0, 1900520, 0, 0, 1900521, 0, 0, 1900522, 0, 0, 1900523, 0, 0, 1900524, 0, 0, 1900525, 0, 0, 1900526, 0, 0, 1900527, 0, 0, 1900528, 0, 0, 1900529, 0, 0, 1900530, 0, 0, 1900531, 0, 0, 1900532, 0, 0, 1900533, 0, 0, 1900534, 0, 0, 1900535, 0, 0, 1900536, 0, 0, 1900537, 0, 0, 1900538, 0, 0, 1900539, 0, 0, 1900540, 0, 0, 1900541, 0, 0, 1900542, 0, 0, 1900543, 0, 0, 1835037, 0, 0, 1835064, 0, 0, 1900573, 0, 0, 1900600, 0, 0, 1966109, 0, 0, 1966136, 0, 0, 2031645, 0, 0, 2031646, 0, 0, 2031647, 0, 0, 2031648, 0, 0, 2031649, 0, 0, 2031650, 0, 0, 2031651, 0, 0, 2031652, 0, 0, 2031653, 0, 0, 2031654, 0, 0, 2031655, 0, 0, 2031656, 0, 0, 2031657, 0, 0, 2031658, 0, 0, 2031659, 0, 0, 2031660, 0, 0, 2031661, 0, 0, 2031662, 0, 0, 2031663, 0, 0, 2031664, 0, 0, 2031665, 0, 0, 2031666, 0, 0, 2031667, 0, 0, 2031668, 0, 0, 2031669, 0, 0, 2031670, 0, 0, 2031671, 0, 0, 2031672, 0, 0 ) + +[node name="SpikeTileMap" parent="." instance=ExtResource( 4 )] +z_as_relative = false + +[node name="DetailTileMap" parent="." instance=ExtResource( 5 )] +z_index = -11 + +[node name="GameCamera" parent="." instance=ExtResource( 6 )] +position = Vector2( 112, 64 ) +editor_draw_drag_margin = false +is_moving = true +is_focal_point = false +target_influence = 0.3 + +[node name="Rooms" type="Node2D" parent="."] +script = ExtResource( 9 ) + +[node name="Room1" type="ColorRect" parent="Rooms"] +margin_right = 224.0 +margin_bottom = 128.0 +color = Color( 1, 0, 1, 0.298039 ) +script = ExtResource( 8 ) +__meta__ = { +"_edit_use_anchors_": false +} +cam_pos = Vector2( 112, 64 ) +draw_color = Color( 1, 1, 1, 0.501961 ) + +[node name="Room2" type="ColorRect" parent="Rooms"] +margin_left = 224.0 +margin_right = 568.0 +margin_bottom = 128.0 +color = Color( 1, 1, 0, 0.298039 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Room3" type="ColorRect" parent="Rooms"] +margin_left = 232.0 +margin_top = 128.0 +margin_right = 456.0 +margin_bottom = 256.0 +color = Color( 1, 0, 1, 0.298039 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Room4" type="ColorRect" parent="Rooms"] +margin_left = -224.0 +margin_top = -136.0 +margin_bottom = 232.0 +color = Color( 1, 1, 0, 0.298039 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Actors" type="Node2D" parent="."] + +[node name="Player" parent="Actors" instance=ExtResource( 2 )] +position = Vector2( 61, 79 ) + +[node name="Box" parent="Actors" instance=ExtResource( 7 )] +position = Vector2( 148, 62 ) diff --git a/src/map/Room.gd b/src/map/Room.gd new file mode 100644 index 0000000..22f754a --- /dev/null +++ b/src/map/Room.gd @@ -0,0 +1,15 @@ +tool +extends ColorRect + +export var cam_pos := Vector2.ZERO setget _set_cam_pos +export var draw_color := Color(1, 1, 1, 0.5) +var cam_size := Vector2(228, 128) + +func _set_cam_pos(arg): + cam_pos = arg + update() + + +func _draw(): + draw_circle(cam_pos, 3, draw_color) + #draw_rect(Rect2(cam_pos - cam_size / 2, cam_size), draw_color) diff --git a/src/map/RoomManager.gd b/src/map/RoomManager.gd new file mode 100644 index 0000000..9ce3691 --- /dev/null +++ b/src/map/RoomManager.gd @@ -0,0 +1,45 @@ +extends Node2D + +var rooms = [] +var player +var active +var cam + +func _ready(): + visible = false + + cam = get_parent().get_node("GameCamera") + + rooms = get_children() + for i in get_tree().get_nodes_in_group("player"): + player = i + break + + find_room() + +func _process(delta): + if !is_player_inside(active): + find_room() + +func aabb(x1 : int, y1 : int, w1 : int, h1 : int, x2 : int, y2 : int, w2 : int, h2 : int) -> bool: + return x1 < x2 + w2 and x2 < x1 + w1 and y1 < y2 + h2 and y2 < y1 + h1 + +func is_player_inside(room) -> bool: + return aabb(player.center().x, player.center().y, 0, 0, room.rect_position.x, room.rect_position.y, room.rect_size.x, room.rect_size.y) + +func set_active(arg): + active = arg + + cam.limit_left = active.rect_position.x + cam.limit_top = active.rect_position.y + cam.limit_right = active.rect_position.x + active.rect_size.x + cam.limit_bottom = active.rect_position.y + active.rect_size.y + #cam.position = active.rect_position + active.rect_size / 2 + + print("active room: ", active.name, " left: ", cam.limit_left, " right: ", cam.limit_right, " top: ", cam.limit_top, " bottom: ", cam.limit_bottom) + +func find_room(): + for i in rooms: + if i != active and is_player_inside(i): + set_active(i) + break diff --git a/src/stage/GameCamera.gd b/src/stage/GameCamera.gd index 3d32afc..bd43537 100644 --- a/src/stage/GameCamera.gd +++ b/src/stage/GameCamera.gd @@ -34,6 +34,7 @@ func _process(delta): pos_target = pos_start.linear_interpolate(node_target.position + pos_offset, target_influence) else: pos_target = node_target.position + pos_offset + # smoothing lerp_pos = lerp_pos.linear_interpolate(pos_target, lerp_step) position = lerp_pos.round()