test_stack.gd 881 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. extends Test
  2. @export var height := 10
  3. @export var width := 1
  4. @export var box_size := Vector2(40.0, 40.0)
  5. @export var box_spacing := Vector2(0.0, 0.0)
  6. func _ready() -> void:
  7. _create_stack()
  8. func _create_stack() -> void:
  9. var root_node := $Stack
  10. var template_body := create_rigidbody_box(box_size, true)
  11. var pos_y := -0.5 * box_size.y - box_spacing.y
  12. for level: int in height:
  13. var row_node := Node2D.new()
  14. row_node.position = Vector2(0.0, pos_y)
  15. row_node.name = "Row%02d" % (level + 1)
  16. root_node.add_child(row_node)
  17. var pos_x := -0.5 * (width - 1) * (box_size.x + box_spacing.x)
  18. for box_index in width:
  19. var box := template_body.duplicate()
  20. box.position = Vector2(pos_x, 0.0)
  21. box.name = "Box%02d" % (box_index + 1)
  22. row_node.add_child(box)
  23. pos_x += box_size.x + box_spacing.x
  24. pos_y -= box_size.y + box_spacing.y
  25. template_body.queue_free()