Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

main.lua 3.5 KiB

2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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