diff --git a/project/demos/SeekFlee/Boundaries.gd b/project/demos/SeekFlee/Boundaries.gd new file mode 100644 index 0000000..83cbce5 --- /dev/null +++ b/project/demos/SeekFlee/Boundaries.gd @@ -0,0 +1,30 @@ +extends Node2D + + +const COLOR := Color("8fde5d") + + +func _ready() -> void: + get_tree().root.connect("size_changed", self, "_on_SceneTree_size_changed") + + +func _draw() -> void: + for b in get_children(): + var extents: Vector2 = b.get_node("CollisionShape2D").shape.extents + draw_rect(Rect2(b.global_position-extents, extents*2), COLOR) + + +func _on_SceneTree_size_changed() -> void: + var size := get_tree().root.size + for b in get_children(): + var boundary: String = b.name.rsplit("Boundary")[0] + match boundary: + "Left": + b.global_position = Vector2(0, size.y/2) + "Right": + b.global_position = Vector2(size.x, size.y/2) + "Top": + b.global_position = Vector2(size.x/2, 0) + "Bottom": + b.global_position = Vector2(size.x/2, size.y) + update() diff --git a/project/demos/SeekFlee/Boundary.gd b/project/demos/SeekFlee/Boundary.gd deleted file mode 100644 index c986800..0000000 --- a/project/demos/SeekFlee/Boundary.gd +++ /dev/null @@ -1,16 +0,0 @@ -extends StaticBody2D -# Draws the bounding box of the static body wall. - - -const COLOR := Color("8fde5d") - -var rect: Rect2 - - -func _ready() -> void: - var extents: Vector2 = $CollisionShape2D.shape.extents - rect = Rect2(-extents, extents*2) - - -func _draw() -> void: - draw_rect(rect, COLOR) diff --git a/project/demos/SeekFlee/SeekFleeDemo.tscn b/project/demos/SeekFlee/SeekFleeDemo.tscn index 2d17c56..56d529f 100644 --- a/project/demos/SeekFlee/SeekFleeDemo.tscn +++ b/project/demos/SeekFlee/SeekFleeDemo.tscn @@ -1,6 +1,5 @@ [gd_scene load_steps=12 format=2] -[ext_resource path="res://demos/SeekFlee/Boundary.gd" type="Script" id=1] [ext_resource path="res://demos/SeekFlee/Player.gd" type="Script" id=2] [ext_resource path="res://demos/SeekFlee/SeekFleeDemo.gd" type="Script" id=3] [ext_resource path="res://demos/SeekFlee/Spawner.gd" type="Script" id=4] @@ -8,6 +7,7 @@ [ext_resource path="res://demos/SeekFlee/Seeker.tscn" type="PackedScene" id=6] [ext_resource path="res://demos/Utils/CircleDraw.gd" type="Script" id=7] [ext_resource path="res://demos/Utils/BackgroudLayer.tscn" type="PackedScene" id=8] +[ext_resource path="res://demos/SeekFlee/Boundaries.gd" type="Script" id=9] [sub_resource type="CircleShape2D" id=1] radius = 32.0 @@ -35,44 +35,39 @@ inner_color = Color( 0.235294, 0.639216, 0.439216, 1 ) outer_color = Color( 0.560784, 0.870588, 0.364706, 1 ) stroke = 4.0 -[node name="LeftBoundary" type="StaticBody2D" parent="."] +[node name="Boundaries" type="Node2D" parent="."] +script = ExtResource( 9 ) + +[node name="LeftBoundary" type="StaticBody2D" parent="Boundaries"] position = Vector2( 0, 300 ) collision_layer = 2 collision_mask = 5 -script = ExtResource( 1 ) -[node name="CollisionShape2D" type="CollisionShape2D" parent="LeftBoundary"] -position = Vector2( 0, 246 ) +[node name="CollisionShape2D" type="CollisionShape2D" parent="Boundaries/LeftBoundary"] shape = SubResource( 2 ) -[node name="RightBoundary" type="StaticBody2D" parent="."] +[node name="RightBoundary" type="StaticBody2D" parent="Boundaries"] position = Vector2( 1024, 300 ) collision_layer = 2 collision_mask = 5 -script = ExtResource( 1 ) -[node name="CollisionShape2D" type="CollisionShape2D" parent="RightBoundary"] -position = Vector2( 898, 242 ) +[node name="CollisionShape2D" type="CollisionShape2D" parent="Boundaries/RightBoundary"] shape = SubResource( 2 ) -[node name="TopBoundary" type="StaticBody2D" parent="."] +[node name="TopBoundary" type="StaticBody2D" parent="Boundaries"] position = Vector2( 512, 2.00002 ) collision_layer = 2 collision_mask = 5 -script = ExtResource( 1 ) -[node name="CollisionShape2D" type="CollisionShape2D" parent="TopBoundary"] -position = Vector2( 472.348, 0 ) +[node name="CollisionShape2D" type="CollisionShape2D" parent="Boundaries/TopBoundary"] shape = SubResource( 3 ) -[node name="BottomBoundary" type="StaticBody2D" parent="."] +[node name="BottomBoundary" type="StaticBody2D" parent="Boundaries"] position = Vector2( 512, 600 ) collision_layer = 2 collision_mask = 5 -script = ExtResource( 1 ) -[node name="CollisionShape2D" type="CollisionShape2D" parent="BottomBoundary"] -position = Vector2( 436.348, 472.348 ) +[node name="CollisionShape2D" type="CollisionShape2D" parent="Boundaries/BottomBoundary"] shape = SubResource( 3 ) [node name="Spawner" type="Node2D" parent="."] diff --git a/project/project.godot b/project/project.godot index bab7ed3..9179fbd 100644 --- a/project/project.godot +++ b/project/project.godot @@ -9,7 +9,7 @@ config_version=4 _global_script_classes=[ { -"base": "Control", +"base": "CenterContainer", "class": "DemoPickerUI", "language": "GDScript", "path": "res://demos/DemoPickerUI.gd" @@ -200,11 +200,7 @@ config/icon="res://icon.png" [display] -window/size/width=1920 -window/size/height=1080 window/size/always_on_top=true -window/stretch/mode="2d" -window/stretch/aspect="expand" [input]