main.nim 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import nodesnim
  2. import random
  3. randomize()
  4. Window("ScreenSaver", 720, 480)
  5. var
  6. direction = Vector2()
  7. speed = 3f
  8. build:
  9. - Scene main:
  10. - Sprite sprite:
  11. centered: false
  12. call setTexture(load("img.png", GL_RGBA))
  13. sprite@on_process(self):
  14. let rect = Rect2(sprite.global_position, sprite.rect_size)
  15. if rect.x <= 0:
  16. direction = sprite.global_position.directionTo(Vector2(main.rect_size.x, rand(main.rect_size.y.int).float))
  17. sprite.filter = Color(rand(1f) + 0.5, rand(1f) + 0.5, rand(1f) + 0.5)
  18. elif rect.x+rect.w >= main.rect_size.x:
  19. direction = sprite.global_position.directionTo(Vector2(0, rand(main.rect_size.y.int).float))
  20. sprite.filter = Color(rand(1f) + 0.5, rand(1f) + 0.5, rand(1f) + 0.5)
  21. elif rect.y <= 0:
  22. direction = sprite.global_position.directionTo(Vector2(rand(main.rect_size.x.int).float, main.rect_size.y))
  23. sprite.filter = Color(rand(1f) + 0.5, rand(1f) + 0.5, rand(1f) + 0.5)
  24. elif rect.y+rect.h >= main.rect_size.y:
  25. direction = sprite.global_position.directionTo(Vector2(rand(main.rect_size.x.int).float, 0))
  26. sprite.filter = Color(rand(1f) + 0.5, rand(1f) + 0.5, rand(1f) + 0.5)
  27. sprite.move(direction*speed)
  28. addMainScene(main)
  29. windowLaunch()