Files
Hugo Locurcio bac1e69164 Use static typing in all demos (#1063)
This leads to code that is easier to understand and runs
faster thanks to GDScript's typed instructions.

The untyped declaration warning is now enabled on all projects
where type hints were added. All projects currently run without
any untyped declration warnings.

Dodge the Creeps and Squash the Creeps demos intentionally don't
use type hints to match the documentation, where type hints haven't
been adopted yet (given its beginner focus).
2024-06-01 12:12:18 +02:00

38 lines
881 B
GDScript

extends Test
@export var height := 10
@export var width := 1
@export var box_size := Vector2(40.0, 40.0)
@export var box_spacing := Vector2(0.0, 0.0)
func _ready() -> void:
_create_stack()
func _create_stack() -> void:
var root_node := $Stack
var template_body := create_rigidbody_box(box_size, true)
var pos_y := -0.5 * box_size.y - box_spacing.y
for level: int in height:
var row_node := Node2D.new()
row_node.position = Vector2(0.0, pos_y)
row_node.name = "Row%02d" % (level + 1)
root_node.add_child(row_node)
var pos_x := -0.5 * (width - 1) * (box_size.x + box_spacing.x)
for box_index in width:
var box := template_body.duplicate()
box.position = Vector2(pos_x, 0.0)
box.name = "Box%02d" % (box_index + 1)
row_node.add_child(box)
pos_x += box_size.x + box_spacing.x
pos_y -= box_size.y + box_spacing.y
template_body.queue_free()