test32.nim 974 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. # --- Test 32. use CollisionShape2D. --- #
  2. # Please, compile with `--define:debug` or with `-d:debug` for see collision shapes.
  3. import nodesnim
  4. Window("hello world")
  5. var
  6. mainobj: SceneObj
  7. main = Scene("Main", mainobj)
  8. shape1_obj: CollisionShape2DObj
  9. shape1 = CollisionShape2D(shape1_obj)
  10. shape2_obj: CollisionShape2DObj
  11. shape2 = CollisionShape2D(shape2_obj)
  12. shape3_obj: CollisionShape2DObj
  13. shape3 = CollisionShape2D(shape3_obj)
  14. shape1.move(100, 100)
  15. shape2.move(125, 125)
  16. shape3.move(170, 125)
  17. shape3.setShapeTypeCircle(0, 0, 35) # by default shape type is a rect, but you can change it at any time.
  18. shape2.disable = true # by default shape enabled, but you can change it at any time.
  19. echo shape1.isCollide(shape2) # if one of two shapes is disabled - return false.
  20. echo shape1.isCollide(shape3)
  21. echo shape2.isCollide(shape3)
  22. main.addChild(shape1)
  23. main.addChild(shape2)
  24. main.addChild(shape3)
  25. addScene(main)
  26. setMainScene("Main")
  27. windowLaunch()