test_rigidbody_ground_check.gd 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. extends Test
  2. const OPTION_BIG = "Floor options/Big"
  3. const OPTION_SMALL = "Floor options/Small"
  4. const SHAPE_CONCAVE = "Collision shapes/Concave"
  5. const SHAPE_CONVEX = "Collision shapes/Convex"
  6. const SHAPE_BOX = "Collision shapes/Box"
  7. var _dynamic_shapes_scene
  8. var _floor_shapes = {}
  9. var _floor_size = "Small"
  10. var _current_floor_name = SHAPE_CONCAVE
  11. var _current_bodies
  12. var _current_floor
  13. func _ready():
  14. var options = $Options
  15. _dynamic_shapes_scene = get_packed_scene($DynamicShapes/Bodies)
  16. _floor_shapes[SHAPE_CONVEX + "Small"] = get_packed_scene($"Floors/ConvexSmall")
  17. _floor_shapes[SHAPE_CONVEX + "Big"] = get_packed_scene($"Floors/ConvexBig")
  18. _floor_shapes[SHAPE_CONCAVE + "Big"] = get_packed_scene($"Floors/ConcaveBig")
  19. _floor_shapes[SHAPE_CONCAVE + "Small"] = get_packed_scene($"Floors/ConcaveSmall")
  20. _floor_shapes[SHAPE_BOX + "Big"] = get_packed_scene($"Floors/BoxBig")
  21. _floor_shapes[SHAPE_BOX + "Small"] = get_packed_scene($"Floors/BoxSmall")
  22. $DynamicShapes/Bodies.queue_free()
  23. for floorNode in $Floors.get_children():
  24. floorNode.queue_free()
  25. options.add_menu_item(OPTION_SMALL)
  26. options.add_menu_item(OPTION_BIG)
  27. options.add_menu_item(SHAPE_CONCAVE)
  28. options.add_menu_item(SHAPE_CONVEX)
  29. options.add_menu_item(SHAPE_BOX)
  30. options.option_selected.connect(self._on_option_selected)
  31. restart_scene()
  32. func _on_option_selected(option):
  33. match option:
  34. OPTION_BIG:
  35. _floor_size = "Big"
  36. OPTION_SMALL:
  37. _floor_size = "Small"
  38. _:
  39. _current_floor_name = option
  40. restart_scene()
  41. func restart_scene():
  42. if _current_bodies:
  43. _current_bodies.queue_free()
  44. if _current_floor:
  45. _current_floor.queue_free()
  46. var dynamic_bodies = _dynamic_shapes_scene.instantiate()
  47. _current_bodies = dynamic_bodies
  48. add_child(dynamic_bodies)
  49. var floor_inst = _floor_shapes[_current_floor_name + _floor_size].instantiate()
  50. _current_floor = floor_inst
  51. $Floors.add_child(floor_inst)
  52. $LabelBodyType.text = "Floor Type: " + _current_floor_name.rsplit("/", true, 1)[1] + "\nSize: " + _floor_size
  53. func get_packed_scene(node):
  54. for child in node.get_children():
  55. child.owner = node
  56. for child1 in child.get_children():
  57. child1.owner = node
  58. for child2 in child1.get_children():
  59. child2.owner = node
  60. var packed_scene = PackedScene.new()
  61. packed_scene.pack(node)
  62. return packed_scene