您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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