Skip to content

Commit 68618f6

Browse files
committed
map creation
1 parent 8d07dfc commit 68618f6

7 files changed

Lines changed: 249 additions & 57 deletions

File tree

game/area/area.gd

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,75 @@ extends Node2D
33

44
@onready var player_detector: Area2D = $PlayerDetector
55

6+
@onready var west_creation_area: Area2D = $AreaCreation/WestCreationArea
7+
@onready var west_transport_area: Area2D = $Transport/WestTransportArea
8+
@onready var west_marker: Marker2D = $Markers/WestMarker
9+
10+
@onready var east_creation_area: Area2D = $AreaCreation/EastCreationArea
11+
@onready var east_transport_area: Area2D = $Transport/EastTransportArea
12+
@onready var east_marker: Marker2D = $Markers/EastMarker
13+
14+
@onready var north_creation_area: Area2D = $AreaCreation/NorthCreationArea
15+
@onready var north_transport_area: Area2D = $Transport/NorthTransportArea
16+
@onready var north_marker: Marker2D = $Markers/NorthMarker
17+
18+
@onready var south_creation_area: Area2D = $AreaCreation/SouthCreationArea
19+
@onready var south_transport_area: Area2D = $Transport/SouthTransportArea
20+
@onready var south_marker: Marker2D = $Markers/SouthMarker
21+
22+
signal new_area_requested(area: ArenaArea, side: StringName)
23+
signal transport_requested(area: ArenaArea, side: StringName)
24+
25+
var grid_position := Vector2i.ZERO
26+
27+
628
func _ready() -> void:
7-
player_detector.body_entered.connect(_on_player_detector_body_entered)
29+
west_creation_area.body_entered.connect(_on_creation_area_body_entered.bind(&"west", west_creation_area))
30+
west_transport_area.body_entered.connect(_on_transport_area_body_entered.bind(&"west"))
31+
32+
east_creation_area.body_entered.connect(_on_creation_area_body_entered.bind(&"east", east_creation_area))
33+
east_transport_area.body_entered.connect(_on_transport_area_body_entered.bind(&"east"))
34+
35+
north_creation_area.body_entered.connect(_on_creation_area_body_entered.bind(&"north", north_creation_area))
36+
north_transport_area.body_entered.connect(_on_transport_area_body_entered.bind(&"north"))
37+
38+
south_creation_area.body_entered.connect(_on_creation_area_body_entered.bind(&"south", south_creation_area))
39+
south_transport_area.body_entered.connect(_on_transport_area_body_entered.bind(&"south"))
40+
41+
42+
func _on_transport_area_body_entered(_body: Node2D, side: StringName) -> void:
43+
transport_requested.emit(self, side)
44+
45+
46+
func get_marker_for_side(side: StringName) -> Vector2:
47+
match side:
48+
&"north":
49+
return north_marker.global_position
50+
&"south":
51+
return south_marker.global_position
52+
&"east":
53+
return east_marker.global_position
54+
&"west":
55+
return west_marker.global_position
56+
57+
return Vector2.ZERO
58+
859

60+
# Once created, we don't need to monitor the area anymore.
61+
func _on_creation_area_body_entered(_body: Node2D, side: StringName, area: Area2D) -> void:
62+
area.set_deferred(&"monitoring", false)
63+
new_area_requested.emit(self, side)
964

10-
func _on_player_detector_body_entered(body: Node2D) -> void:
11-
var player := body as Player
12-
if player == null:
13-
return
1465

15-
player.current_area = self
66+
# When this area is created beside another one, disable the creation trigger that points back to the
67+
# already-existing neighbor.
68+
func disable_area_creation_on_side(side: StringName) -> void:
69+
match side:
70+
&"north":
71+
south_creation_area.set_deferred(&"monitoring", false)
72+
&"south":
73+
north_creation_area.set_deferred(&"monitoring", false)
74+
&"east":
75+
west_creation_area.set_deferred(&"monitoring", false)
76+
&"west":
77+
east_creation_area.set_deferred(&"monitoring", false)

game/area/area.tscn

Lines changed: 86 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
[ext_resource type="Script" uid="uid://cqniipdu8ep4p" path="res://game/area/area.gd" id="1_fafbg"]
44
[ext_resource type="Texture2D" uid="uid://hnfs0sg4cppf" path="res://game/area/arena_bubble.svg" id="2_fafbg"]
5-
[ext_resource type="PackedScene" uid="uid://c67rqhkt2da3c" path="res://game/arena_bridge/arena_bridge.tscn" id="3_ea661"]
65

76
[sub_resource type="RectangleShape2D" id="RectangleShape2D_7iivh"]
87
size = Vector2(1359, 1326)
98

9+
[sub_resource type="RectangleShape2D" id="RectangleShape2D_fafbg"]
10+
size = Vector2(52, 937.5)
11+
1012
[node name="Area" type="Node2D" unique_id=495972852 groups=["areas"]]
1113
script = ExtResource("1_fafbg")
1214

@@ -43,16 +45,91 @@ collision_mask = 2
4345
position = Vector2(-4.5, 4)
4446
shape = SubResource("RectangleShape2D_7iivh")
4547

46-
[node name="ArenaTransition2" parent="." unique_id=1750952575 instance=ExtResource("3_ea661")]
47-
position = Vector2(-2832, 3)
48+
[node name="AreaCreation" type="Node2D" parent="." unique_id=1977424729]
49+
50+
[node name="WestCreationArea" type="Area2D" parent="AreaCreation" unique_id=801396723]
51+
position = Vector2(-1130, 0)
52+
collision_layer = 0
53+
collision_mask = 2
54+
55+
[node name="CollisionShape2D" type="CollisionShape2D" parent="AreaCreation/WestCreationArea" unique_id=1298957306]
56+
shape = SubResource("RectangleShape2D_fafbg")
57+
58+
[node name="NorthCreationArea" type="Area2D" parent="AreaCreation" unique_id=706701655]
59+
position = Vector2(0, -1133)
60+
collision_layer = 0
61+
collision_mask = 2
62+
63+
[node name="CollisionShape2D" type="CollisionShape2D" parent="AreaCreation/NorthCreationArea" unique_id=1542153924]
64+
rotation = 1.5707964
65+
shape = SubResource("RectangleShape2D_fafbg")
66+
67+
[node name="SouthCreationArea" type="Area2D" parent="AreaCreation" unique_id=1817102077]
68+
position = Vector2(0, 1130)
69+
collision_layer = 0
70+
collision_mask = 2
71+
72+
[node name="CollisionShape2D" type="CollisionShape2D" parent="AreaCreation/SouthCreationArea" unique_id=1028679490]
73+
rotation = 1.5707964
74+
shape = SubResource("RectangleShape2D_fafbg")
75+
76+
[node name="EastCreationArea" type="Area2D" parent="AreaCreation" unique_id=1284079051]
77+
position = Vector2(1126, 0)
78+
collision_layer = 0
79+
collision_mask = 2
80+
81+
[node name="CollisionShape2D" type="CollisionShape2D" parent="AreaCreation/EastCreationArea" unique_id=1599647433]
82+
shape = SubResource("RectangleShape2D_fafbg")
4883

49-
[node name="ArenaTransition" parent="." unique_id=2109252777 instance=ExtResource("3_ea661")]
50-
position = Vector2(1143, 2)
84+
[node name="Transport" type="Node2D" parent="." unique_id=719304312]
5185

52-
[node name="ArenaTransition3" parent="." unique_id=438253375 instance=ExtResource("3_ea661")]
53-
position = Vector2(0, 1144)
86+
[node name="WestTransportArea" type="Area2D" parent="Transport" unique_id=605026687]
87+
position = Vector2(-1218, 0)
88+
collision_layer = 0
89+
collision_mask = 2
90+
91+
[node name="CollisionShape2D" type="CollisionShape2D" parent="Transport/WestTransportArea" unique_id=2039810326]
92+
shape = SubResource("RectangleShape2D_fafbg")
93+
94+
[node name="EastTransportArea" type="Area2D" parent="Transport" unique_id=1470922658]
95+
position = Vector2(1232, 0)
96+
collision_layer = 0
97+
collision_mask = 2
98+
99+
[node name="CollisionShape2D" type="CollisionShape2D" parent="Transport/EastTransportArea" unique_id=1089216346]
100+
position = Vector2(-18, 1.25)
101+
shape = SubResource("RectangleShape2D_fafbg")
102+
103+
[node name="NorthTransportArea" type="Area2D" parent="Transport" unique_id=308157465]
104+
position = Vector2(0, -1239)
54105
rotation = 1.5707964
106+
collision_layer = 0
107+
collision_mask = 2
55108

56-
[node name="ArenaTransition4" parent="." unique_id=1171611887 instance=ExtResource("3_ea661")]
57-
position = Vector2(0, -2831)
109+
[node name="CollisionShape2D" type="CollisionShape2D" parent="Transport/NorthTransportArea" unique_id=1844721722]
110+
position = Vector2(25, 1.25)
111+
shape = SubResource("RectangleShape2D_fafbg")
112+
113+
[node name="SouthTransportArea" type="Area2D" parent="Transport" unique_id=613335447]
114+
position = Vector2(1, 1213)
58115
rotation = 1.5707964
116+
collision_layer = 0
117+
collision_mask = 2
118+
119+
[node name="CollisionShape2D" type="CollisionShape2D" parent="Transport/SouthTransportArea" unique_id=1119681408]
120+
position = Vector2(1, 1.25)
121+
shape = SubResource("RectangleShape2D_fafbg")
122+
123+
[node name="Markers" type="Node2D" parent="." unique_id=1863105897]
124+
125+
[node name="WestMarker" type="Marker2D" parent="Markers" unique_id=1119824998]
126+
position = Vector2(-1008, 0)
127+
128+
[node name="NorthMarker" type="Marker2D" parent="Markers" unique_id=537814493]
129+
position = Vector2(0, -1022)
130+
131+
[node name="SouthMarker" type="Marker2D" parent="Markers" unique_id=1937527924]
132+
position = Vector2(1, 1019)
133+
134+
[node name="EastMarker" type="Marker2D" parent="Markers" unique_id=487803607]
135+
position = Vector2(1008, 0)

game/game_area/game_area.gd

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,83 @@
11
class_name GameArea
22
extends Node2D
3+
4+
const ROOM_SPACING = 3000
5+
const AREA = preload("uid://b8s7r2s04sqw3")
6+
7+
@onready var area: ArenaArea = $Area
8+
@onready var player: Player = $Player
9+
10+
var areas: Dictionary[Vector2i, ArenaArea] = {}
11+
12+
13+
func _ready() -> void:
14+
player.current_area = area
15+
_register_area(area)
16+
17+
18+
func _on_area_transport_requested(source_area: ArenaArea, side: StringName) -> void:
19+
if player.is_auto_moving:
20+
return
21+
22+
var target_grid_position := source_area.grid_position + _get_direction(side)
23+
var target_area: ArenaArea = areas.get(target_grid_position)
24+
25+
if target_area == null:
26+
return
27+
28+
var marker := target_area.get_marker_for_side(_get_opposite_side(side))
29+
player.current_area = target_area
30+
player.auto_move_to(marker)
31+
32+
33+
func _get_opposite_side(side: StringName) -> StringName:
34+
match side:
35+
&"west":
36+
return &"east"
37+
&"east":
38+
return &"west"
39+
&"north":
40+
return &"south"
41+
&"south":
42+
return &"north"
43+
44+
return &""
45+
46+
47+
func _deferred_new_area(source_area: ArenaArea, side: StringName) -> void:
48+
_on_new_area_requested.call_deferred(source_area, side)
49+
50+
51+
func _register_area(area_to_register: ArenaArea) -> void:
52+
areas[area_to_register.grid_position] = area_to_register
53+
area_to_register.transport_requested.connect(_on_area_transport_requested)
54+
area_to_register.new_area_requested.connect(_deferred_new_area)
55+
56+
57+
func _on_new_area_requested(source_area: ArenaArea, side: StringName) -> void:
58+
var target_grid_position := source_area.grid_position + _get_direction(side)
59+
if areas.has(target_grid_position):
60+
return
61+
62+
var new_area: ArenaArea = AREA.instantiate()
63+
new_area.grid_position = target_grid_position
64+
new_area.position = Vector2(target_grid_position) * ROOM_SPACING
65+
66+
add_child(new_area)
67+
68+
new_area.disable_area_creation_on_side(side)
69+
_register_area(new_area)
70+
71+
72+
func _get_direction(side: StringName) -> Vector2i:
73+
match side:
74+
&"north":
75+
return Vector2i.UP
76+
&"south":
77+
return Vector2i.DOWN
78+
&"east":
79+
return Vector2i.RIGHT
80+
&"west":
81+
return Vector2i.LEFT
82+
83+
return Vector2i.ZERO

game/game_area/game_area.tscn

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,11 @@
33
[ext_resource type="Script" uid="uid://biw1lu5iws1o4" path="res://game/game_area/game_area.gd" id="1_wu7i3"]
44
[ext_resource type="PackedScene" uid="uid://dedoe7ai17311" path="res://game/player/player.tscn" id="2_hbsx8"]
55
[ext_resource type="PackedScene" uid="uid://b8s7r2s04sqw3" path="res://game/area/area.tscn" id="4_p0s4x"]
6-
[ext_resource type="PackedScene" uid="uid://ctcysahbtl4wg" path="res://game/enemies/enemy_test/enemy.tscn" id="4_ybvrr"]
76

87
[node name="GameArea" type="Node2D" unique_id=1471830763]
98
script = ExtResource("1_wu7i3")
109

1110
[node name="Area" parent="." unique_id=495972852 instance=ExtResource("4_p0s4x")]
1211

13-
[node name="Enemy" parent="Area" unique_id=175218643 instance=ExtResource("4_ybvrr")]
14-
position = Vector2(467, -428)
15-
16-
[node name="Enemy2" parent="Area" unique_id=738581634 instance=ExtResource("4_ybvrr")]
17-
position = Vector2(-497, 455)
18-
19-
[node name="Area4" parent="." unique_id=1941673352 instance=ExtResource("4_p0s4x")]
20-
position = Vector2(3972, 3)
21-
22-
[node name="ArenaTransition2" parent="Area4" index="3" unique_id=1750952575]
23-
visible = false
24-
25-
[node name="Enemy" parent="Area4" unique_id=264839039 instance=ExtResource("4_ybvrr")]
26-
position = Vector2(467, -428)
27-
28-
[node name="Enemy2" parent="Area4" unique_id=330188202 instance=ExtResource("4_ybvrr")]
29-
position = Vector2(-497, 455)
30-
31-
[node name="Area2" parent="." unique_id=427362067 instance=ExtResource("4_p0s4x")]
32-
position = Vector2(0, -3968)
33-
34-
[node name="ArenaTransition3" parent="Area2" index="5" unique_id=438253375]
35-
visible = false
36-
37-
[node name="Enemy3" parent="Area2" unique_id=935148652 instance=ExtResource("4_ybvrr")]
38-
position = Vector2(-369, 114)
39-
40-
[node name="Area3" parent="." unique_id=307216731 instance=ExtResource("4_p0s4x")]
41-
position = Vector2(3972, -3968)
42-
43-
[node name="ArenaTransition2" parent="Area3" index="3" unique_id=1750952575]
44-
visible = false
45-
46-
[node name="ArenaTransition3" parent="Area3" index="5" unique_id=438253375]
47-
visible = false
48-
4912
[node name="Player" parent="." unique_id=956162283 instance=ExtResource("2_hbsx8")]
50-
51-
[editable path="Area4"]
52-
[editable path="Area2"]
53-
[editable path="Area3"]
13+
position = Vector2(-940, 0)

game/player/player.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class_name Player
22
extends CharacterBody2D
33

4-
const SPEED = 300.0
4+
const SPEED = 700.0
55

66
const TRANSPORTING_SPEED = 1000.0
77
const AUTO_MOVE_STOP_DISTANCE = 4.0

game/signals.gd

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
extends Node
2+
3+
4+
# Called when the node enters the scene tree for the first time.
5+
func _ready() -> void:
6+
pass # Replace with function body.
7+
8+
9+
# Called every frame. 'delta' is the elapsed time since the previous frame.
10+
func _process(delta: float) -> void:
11+
pass

game/signals.gd.uid

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://bdhjhn3ylj8d1

0 commit comments

Comments
 (0)