bunnymark.script 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. local BUNNY_IMAGES = {
  2. hash("rabbitv3_batman"),
  3. hash("rabbitv3_bb8"),
  4. hash("rabbitv3"),
  5. hash("rabbitv3_ash"),
  6. hash("rabbitv3_frankenstein"),
  7. hash("rabbitv3_neo"),
  8. hash("rabbitv3_sonic"),
  9. hash("rabbitv3_spidey"),
  10. hash("rabbitv3_stormtrooper"),
  11. hash("rabbitv3_superman"),
  12. hash("rabbitv3_tron"),
  13. hash("rabbitv3_wolverine"),
  14. }
  15. local DISPLAY_WIDTH = sys.get_config_int("display.width")
  16. local DISPLAY_HEIGHT = sys.get_config_int("display.height")
  17. local SPAWN_COUNT = 1000
  18. local function spawn(self, amount)
  19. for i=1,amount do
  20. local bunny = factory.create("#factory")
  21. if bunny then
  22. local img = BUNNY_IMAGES[math.random(1, #BUNNY_IMAGES)]
  23. sprite.play_flipbook(msg.url(nil, bunny, "sprite"), img)
  24. go.set_position(vmath.vector3(math.random(DISPLAY_WIDTH), DISPLAY_HEIGHT, 0), bunny)
  25. go.animate(bunny, "position.y", go.PLAYBACK_LOOP_PINGPONG, 40, go.EASING_INQUAD, 2, math.random())
  26. self.bunnies = self.bunnies + 1
  27. else
  28. print("Unable to create more bunnies")
  29. break
  30. end
  31. end
  32. end
  33. function init(self)
  34. msg.post(".", "acquire_input_focus")
  35. self.frames = {}
  36. self.bunnies = 0
  37. spawn(self, SPAWN_COUNT)
  38. end
  39. function update(self, dt)
  40. self.frames[#self.frames + 1] = socket.gettime()
  41. local fps = 0
  42. if #self.frames == 61 then
  43. table.remove(self.frames, 1)
  44. fps = 1 / ((self.frames[#self.frames] - self.frames[1]) / (#self.frames - 1))
  45. end
  46. label.set_text("#label", ("Bunnies: %d FPS: %.2f. Click to add more"):format(self.bunnies, fps))
  47. end
  48. function on_input(self, action_id, action)
  49. if action_id == hash("touch") and action.released and action.y < 1030 then
  50. spawn(self, SPAWN_COUNT)
  51. end
  52. end