Fix Seek/Flee demo boundaries not drawn correctly

Closes #27
This commit is contained in:
Francois Belair 2020-02-08 18:16:49 -05:00
parent 6132a0aa25
commit 809b0c53df
4 changed files with 43 additions and 38 deletions

View File

@ -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()

View File

@ -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)

View File

@ -1,6 +1,5 @@
[gd_scene load_steps=12 format=2] [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/Player.gd" type="Script" id=2]
[ext_resource path="res://demos/SeekFlee/SeekFleeDemo.gd" type="Script" id=3] [ext_resource path="res://demos/SeekFlee/SeekFleeDemo.gd" type="Script" id=3]
[ext_resource path="res://demos/SeekFlee/Spawner.gd" type="Script" id=4] [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/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/CircleDraw.gd" type="Script" id=7]
[ext_resource path="res://demos/Utils/BackgroudLayer.tscn" type="PackedScene" id=8] [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] [sub_resource type="CircleShape2D" id=1]
radius = 32.0 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 ) outer_color = Color( 0.560784, 0.870588, 0.364706, 1 )
stroke = 4.0 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 ) position = Vector2( 0, 300 )
collision_layer = 2 collision_layer = 2
collision_mask = 5 collision_mask = 5
script = ExtResource( 1 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="LeftBoundary"] [node name="CollisionShape2D" type="CollisionShape2D" parent="Boundaries/LeftBoundary"]
position = Vector2( 0, 246 )
shape = SubResource( 2 ) shape = SubResource( 2 )
[node name="RightBoundary" type="StaticBody2D" parent="."] [node name="RightBoundary" type="StaticBody2D" parent="Boundaries"]
position = Vector2( 1024, 300 ) position = Vector2( 1024, 300 )
collision_layer = 2 collision_layer = 2
collision_mask = 5 collision_mask = 5
script = ExtResource( 1 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="RightBoundary"] [node name="CollisionShape2D" type="CollisionShape2D" parent="Boundaries/RightBoundary"]
position = Vector2( 898, 242 )
shape = SubResource( 2 ) shape = SubResource( 2 )
[node name="TopBoundary" type="StaticBody2D" parent="."] [node name="TopBoundary" type="StaticBody2D" parent="Boundaries"]
position = Vector2( 512, 2.00002 ) position = Vector2( 512, 2.00002 )
collision_layer = 2 collision_layer = 2
collision_mask = 5 collision_mask = 5
script = ExtResource( 1 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="TopBoundary"] [node name="CollisionShape2D" type="CollisionShape2D" parent="Boundaries/TopBoundary"]
position = Vector2( 472.348, 0 )
shape = SubResource( 3 ) shape = SubResource( 3 )
[node name="BottomBoundary" type="StaticBody2D" parent="."] [node name="BottomBoundary" type="StaticBody2D" parent="Boundaries"]
position = Vector2( 512, 600 ) position = Vector2( 512, 600 )
collision_layer = 2 collision_layer = 2
collision_mask = 5 collision_mask = 5
script = ExtResource( 1 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="BottomBoundary"] [node name="CollisionShape2D" type="CollisionShape2D" parent="Boundaries/BottomBoundary"]
position = Vector2( 436.348, 472.348 )
shape = SubResource( 3 ) shape = SubResource( 3 )
[node name="Spawner" type="Node2D" parent="."] [node name="Spawner" type="Node2D" parent="."]

View File

@ -9,7 +9,7 @@
config_version=4 config_version=4
_global_script_classes=[ { _global_script_classes=[ {
"base": "Control", "base": "CenterContainer",
"class": "DemoPickerUI", "class": "DemoPickerUI",
"language": "GDScript", "language": "GDScript",
"path": "res://demos/DemoPickerUI.gd" "path": "res://demos/DemoPickerUI.gd"
@ -200,11 +200,7 @@ config/icon="res://icon.png"
[display] [display]
window/size/width=1920
window/size/height=1080
window/size/always_on_top=true window/size/always_on_top=true
window/stretch/mode="2d"
window/stretch/aspect="expand"
[input] [input]