main.nim 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import nodesnim
  2. import random
  3. randomize()
  4. Window("ScreenSaver", 720, 480)
  5. var
  6. main = Scene("Main")
  7. img = load("img.png", GL_RGBA)
  8. sprite = Sprite()
  9. direction = Vector2()
  10. speed = 3f
  11. sprite.centered = false
  12. sprite.setTexture(img)
  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. main.addChild(sprite )
  29. addScene(main)
  30. setMainScene("Main")
  31. windowLaunch()