Advertisement
Guest User

Untitled

a guest
Mar 9th, 2015
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.66 KB | None | 0 0
  1. function love.load()
  2.     love.window.setMode(0, 0, {fullscreen = true})
  3.     love.mouse.setVisible(true)
  4.     width, height = love.window.getDimensions()
  5.     state = 0
  6.     ms = 0
  7.     avg = 0
  8.     takes = 0
  9.     total = 0
  10.     errors = 0
  11.     math.randomseed(os.time())
  12.     timer = math.random(2, 5)
  13. end
  14.  
  15. function love.draw()
  16.     if state == 0 then
  17.         love.graphics.setBackgroundColor(100, 100, 100)
  18.         love.graphics.print("Current FPS: "..tostring(love.timer.getFPS( )), 10, 10)
  19.         local delta = love.timer.getAverageDelta()
  20.         love.graphics.print(string.format("Average frame time: %.3f ms", 1000 * delta), 10, 20)
  21.         love.graphics.print("Timer: "..ms, 10, 30)
  22.         love.graphics.print("Avg: "..avg, 10, 40)
  23.         love.graphics.print("Takes: "..takes, 10, 50)
  24.         love.graphics.print("Errors: "..errors, 10, 60)
  25.         return
  26.     end
  27.     if state == 1 then
  28.         love.graphics.setBackgroundColor(0, 255, 0)
  29.     end
  30.     if state == 2 then
  31.         love.graphics.setBackgroundColor(255, 0, 0)
  32.         love.graphics.print("Timer: "..ms, 10, 10)
  33.     end
  34. end
  35.  
  36. function love.keypressed(key)
  37.     if key == 'escape' then
  38.         love.event.quit()
  39.     end
  40.     if key == 'delete' then
  41.         total = 0
  42.         avg = 0
  43.         takes = 0
  44.         errors = 0
  45.     end
  46. end
  47.  
  48. function love.mousepressed(x, y)
  49.     if state == 0 then
  50.         state = 1
  51.         timer = math.random(2, 5)
  52.     return
  53.     elseif state == 1 then
  54.         state = 0
  55.         timer = math.random(2, 5)
  56.         errors = errors + 1;
  57.     return
  58.     elseif state == 2 then
  59.         state = 0
  60.         timer = math.random(2, 5)
  61.         takes = takes + 1;
  62.         total = total + ms;
  63.         avg = total / takes;
  64.     end
  65. end
  66.  
  67. function love.update(dt)
  68.     if state == 1 then
  69.         timer = timer - dt;
  70.         ms = 0
  71.         if timer <= 0 then
  72.             state = 2
  73.         end
  74.     end
  75.     if state == 2 then
  76.         ms = ms + dt;
  77.     end
  78. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement