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.

188 linhas
3.6 KiB

  1. require "import"
  2. -- Debugging / Logging:
  3. debug = calc.debug
  4. calc.isDebug = true
  5. function love.load()
  6. -- Declaration:
  7. love.window.setTitle(info.name.." - v"..info.version)
  8. --love.graphics.setDefaultFilter("nearest", "nearest")
  9. width, height = love.graphics.getDimensions()
  10. -- Camera:
  11. cam = Camera()
  12. zoomlevel = settings.zoom.reset
  13. --Simulation:
  14. warpspeed = 1
  15. warpCoolDown = 0
  16. -- Loading:
  17. ships = {} --Potentially add other starships in the future?
  18. planet = {}
  19. loadPlanets()
  20. local spawnPlanet = planet[1]
  21. player = Player(spawnPlanet.x, spawnPlanet.y-spawnPlanet.r-1, "orbiter")
  22. player.xSpeed, player.ySpeed = spawnPlanet.xSpeed, spawnPlanet.ySpeed
  23. gui = Gui(1)
  24. effects = {}
  25. end
  26. -- Planets:
  27. function loadPlanets()
  28. debug("Planets in planet table: "..#planetdata)
  29. for i, p in ipairs(planetdata) do
  30. debug(p.name.." is loading")
  31. table.insert(planet, i,
  32. Planet(
  33. -- Planet Data Assignment:
  34. p.x, p.y,
  35. p.r, p.m,
  36. p.xSpeed, p.ySpeed,
  37. p.name,
  38. p.colour,
  39. p.parent
  40. )
  41. )
  42. debug(p.name.." is loaded")
  43. end
  44. debug("Planets loaded: "..#planet)
  45. end
  46. function updatePlanets()
  47. planet[1]:update()
  48. end
  49. function drawPlanets()
  50. for i=1, #planet do
  51. planet[i]:draw()
  52. --debug("Drawing planet " .. i)
  53. end
  54. end
  55. function drawEffects()
  56. for i=1, #effects do
  57. effects[i]:draw()
  58. end
  59. for i, effect in ipairs(effects) do --Separate functions because if I remove something while processing it it WILL lead to an error
  60. if effect.finished then
  61. table.remove(effects, i)
  62. end
  63. end
  64. end
  65. -- Camera
  66. function cameraControls()
  67. local step = settings.zoom.step
  68. function love.wheelmoved(x, y)
  69. if y > 0 then
  70. -- Zoom in:
  71. zoomlevel = zoomlevel + step*(zoomlevel*10)
  72. elseif y < 0 then
  73. -- Zoom out:
  74. zoomlevel = zoomlevel - step*(zoomlevel*10)
  75. end
  76. end
  77. -- Reset Zoom:
  78. if love.mouse.isDown(controls.camera.zoom.reset) then
  79. zoomlevel = settings.zoom.reset
  80. end
  81. -- Zoom Limit:
  82. local max = settings.zoom.max
  83. local min = settings.zoom.min
  84. if zoomlevel < min then
  85. zoomlevel = min
  86. end
  87. if zoomlevel > max then
  88. zoomlevel = max
  89. end
  90. --debug(zoomlevel)
  91. cam:zoomTo(zoomlevel)
  92. end
  93. function timewarpControls()
  94. -- Time Warp Toggle Cooldowns:
  95. local maxCooldown = settings.warp.cooldown
  96. -- Time Warp Steps:
  97. local step = settings.warp.step
  98. -- Time Warp Limits:
  99. local min = settings.warp.min
  100. local max = settings.warp.max
  101. -- Decrease Warp
  102. if love.keyboard.isDown(controls.flight.warp.down) and warpCoolDown <= 0 then
  103. warpspeed = warpspeed - step
  104. warpCoolDown = maxCooldown
  105. end
  106. -- Increase Warp
  107. if love.keyboard.isDown(controls.flight.warp.up) and warpCoolDown <= 0 then
  108. warpspeed = warpspeed + step
  109. warpCoolDown = maxCooldown
  110. end
  111. -- Reset Warp
  112. if love.keyboard.isDown(controls.flight.warp.reset) then
  113. warpspeed = min
  114. end
  115. -- Value Correction
  116. if warpspeed < min then
  117. warpspeed = min
  118. elseif warpspeed > max then
  119. warpspeed = max
  120. end
  121. warpCoolDown = warpCoolDown - 1
  122. return warpspeed
  123. end
  124. -- MAIN
  125. function love.update(dt)
  126. -- Game Objects:
  127. for i=1, timewarpControls() do
  128. -- Physics go in here:
  129. updatePlanets()
  130. player:update(dt)
  131. end
  132. player:throttleControls()
  133. -- Gui:
  134. gui:update(dt)
  135. -- Camera:
  136. cam:lookAt(player.x, player.y)
  137. cameraControls()
  138. --debug(player.x .. " " .. player.y)
  139. end
  140. function love.draw()
  141. cam:attach()
  142. -- Game Objects:
  143. drawPlanets()
  144. drawEffects()
  145. player:draw()
  146. -- Camera Zoom Player Location Indicator: OVERWORK SOON PLS KAY; IT UGLY
  147. if zoomlevel < 0.3 then
  148. love.graphics.setColor(1, 1, 1, 0.2)
  149. love.graphics.circle("fill", player.x, player.y, (1/zoomlevel)*10)
  150. end
  151. cam:detach()
  152. -- Gui:
  153. gui:draw()
  154. end