Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

57 linhas
1.7 KiB

  1. VIRTUAL_WIDTH = 1280
  2. VIRTUAL_HEIGHT = 720
  3. WINDOW_WIDTH = 1280
  4. WINDOW_HEIGHT = 720
  5. Class = require 'class'
  6. require 'simpleScale'
  7. require 'life'
  8. require 'edible'
  9. bugs = {}
  10. edibles = {}
  11. rules = {}
  12. function love.load()
  13. math.randomseed(os.time())
  14. smallfont = love.graphics.newFont("font.ttf", 15)
  15. smallestfont = love.graphics.newFont("font.ttf", 5)
  16. love.keyboard.setKeyRepeat(true)
  17. simpleScale.setWindow(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT)
  18. table.insert(bugs, life(VIRTUAL_HEIGHT/2, VIRTUAL_WIDTH/2, 10, 159))
  19. table.insert(edibles, edible(20, VIRTUAL_WIDTH/2+5, 4))
  20. rules["abundantFood"] = false
  21. end
  22. function love.update(dt)
  23. love.window.setTitle(#bugs)
  24. for i, bug in ipairs(bugs) do
  25. bug:update(dt)
  26. end
  27. regulator()
  28. end
  29. function regulator()
  30. for i, bug in ipairs(bugs) do
  31. if bug.dead then
  32. table.insert(edibles, edible(bug.y, bug.x, bug.fat))
  33. table.remove(bugs, i)
  34. end
  35. end
  36. if #bugs == 0 then
  37. table.insert(bugs, life(VIRTUAL_HEIGHT/2, VIRTUAL_WIDTH/2, 10, 159))
  38. end
  39. if #edibles < #bugs/3 and rules["abundantFood"] then
  40. table.insert(edibles, edible(math.random(0, VIRTUAL_HEIGHT), math.random(0, VIRTUAL_WIDTH), 10))
  41. elseif #edibles <= 3 then
  42. table.insert(edibles, edible(math.random(0, VIRTUAL_HEIGHT), math.random(0, VIRTUAL_WIDTH), 10))
  43. end
  44. end
  45. function love.draw()
  46. simpleScale.set()
  47. love.graphics.clear(0,0,0,1)
  48. for i, bug in ipairs(bugs) do
  49. bug:render(dt)
  50. end
  51. for i, edible in ipairs(edibles) do
  52. edible:render(dt)
  53. end
  54. love.graphics.setColor(1,1,1,1)
  55. love.graphics.setFont(smallfont)
  56. simpleScale.unSet()
  57. end