test1.nim 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # --- Test 1. Work with Window.. --- #
  2. import
  3. nodesnim,
  4. unittest
  5. suite "Work with Window":
  6. test "Create window":
  7. # Window(title, width, height)
  8. Window(title = "MyWindow",
  9. w = 720, h = 480)
  10. test "Change Window title":
  11. setTitle("My own window ^^")
  12. test "Change Window icon":
  13. setIcon("assets/sharp.jpg")
  14. test "Resize and centered window":
  15. resizeWindow(1024, 640)
  16. centeredWindow()
  17. test "Setup environment":
  18. env.color = Color(1, 0.6, 1) # window background color.
  19. env.brightness = 0.5
  20. env.delay = 1000 div 120 # 120 frames per second.
  21. test "Setup window":
  22. build: # Node builder
  23. - Scene main # Create an empty Scene node with the name "main".
  24. test "Register events":
  25. addKeyAction("forward", "w")
  26. addKeyAction("backward", "s")
  27. test "Handle events":
  28. main@onProcess(self):
  29. if isActionJustPressed("forward"):
  30. echo "forward pressed!"
  31. elif isActionJustPressed("backward"):
  32. echo "backward pressed!"
  33. addMainScene(main) # Adds scene to window and
  34. windowLaunch()