You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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