Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

main.lua 6.2 KiB

il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. function love.load()
  2. require "import"
  3. -- Debugging / Logging:
  4. debug = calc.debug
  5. calc.isDebug = true
  6. -- Declaration:
  7. love.window.setTitle(info.name.." - v"..info.version)
  8. width, height = love.graphics.getDimensions()
  9. -- Gamestate:
  10. gamestate = {
  11. quit = "stateQUIT",
  12. menu = "stateMENU",
  13. game = "stateGAME"
  14. }
  15. GAMESTATE = gamestate.menu
  16. -- Menubuttons:
  17. menubutton = {
  18. menu = {
  19. Menubutton(20, 100, 200, 50, gamestate.game, nil, "Start Game", {255, 255, 255}, {57, 45, 66}),
  20. Menubutton(30, 170, 180, 40, gamestate.quit, nil, "Quit Game", {255, 255, 255}, {57, 45, 66})
  21. },
  22. game = {
  23. -- Pause button or something here in future?
  24. }
  25. }
  26. -- Buttons:
  27. button = {
  28. tutorial = Button(width - 70, 20, 50, 30, "help", {255, 255, 255}, {40, 40, 40}, false),
  29. pause = Button(width - 70, 60, 80, 30, "pause", {255, 255, 255}, {40, 40, 40}, false)
  30. }
  31. pausebutton = {
  32. }
  33. table.insert(pausebutton, Button(width/2-250, height/2-25, 500, 50, "Continue", {255, 255, 255}, {40, 40, 40}, false, function() button.pause.isActive = false end))
  34. table.insert(pausebutton, Button(width/2-250, height/2+35, 500, 50, "Main Menu", {255, 255, 255}, {40, 40, 40}, false, function() restartGame() GAMESTATE = gamestate.menu end))
  35. table.insert(pausebutton, Button(width/2-250, height/2+95, 500, 50, "Quit", {255, 255, 255}, {40, 40, 40}, false, function() love.event.quit() end))
  36. -- Textboxes:
  37. textbox = {
  38. tutorial = Textbox(40, 40, width-80, height-80, calc.getText(text.tutorial), "center", {255, 255, 255}, {0, 0, 0})
  39. }
  40. -- Camera:
  41. cam = Camera()
  42. zoomlevel = settings.zoom.reset
  43. --Simulation:
  44. warpspeed = 1
  45. warpCoolDown = 0
  46. -- Loading:
  47. ships = {} --Potentially add other starships in the future?
  48. planet = {}
  49. loadPlanets()
  50. local spawnPlanet = planet[1]
  51. player = Player(spawnPlanet.x, spawnPlanet.y-spawnPlanet.r-1, "orbiter")
  52. player.xSpeed, player.ySpeed = spawnPlanet.xSpeed, spawnPlanet.ySpeed
  53. gui = Gui(1)
  54. effects = {}
  55. end
  56. -- Planets:
  57. function loadPlanets()
  58. debug("Planets in planet table: "..#planetdata)
  59. for i, p in ipairs(planetdata) do
  60. debug(p.name.." is loading")
  61. table.insert(planet, i,
  62. Planet(
  63. -- Planet Data Assignment:
  64. p.x, p.y,
  65. p.r, p.m,
  66. p.xSpeed, p.ySpeed,
  67. p.name,
  68. p.colour,
  69. p.parent
  70. )
  71. )
  72. debug(p.name.." is loaded")
  73. end
  74. debug("Planets loaded: "..#planet)
  75. end
  76. function updatePlanets()
  77. planet[1]:update()
  78. end
  79. function drawPlanets()
  80. for i=1, #planet do
  81. planet[i]:draw()
  82. --debug("Drawing planet " .. i)
  83. end
  84. end
  85. -- Effects
  86. function drawEffects()
  87. for i=1, #effects do
  88. effects[i]:draw()
  89. end
  90. for i, effect in ipairs(effects) do --Separate functions because if I remove something while processing it it WILL lead to an error
  91. if effect.finished then
  92. table.remove(effects, i)
  93. end
  94. end
  95. end
  96. -- Camera
  97. function cameraControls()
  98. local step = settings.zoom.step
  99. function love.wheelmoved(x, y)
  100. if not button.pause.isActive then
  101. if y > 0 then
  102. -- Zoom in:
  103. zoomlevel = zoomlevel + step*(zoomlevel*10)
  104. elseif y < 0 then
  105. -- Zoom out:
  106. zoomlevel = zoomlevel - step*(zoomlevel*10)
  107. end
  108. end
  109. end
  110. -- Reset Zoom:
  111. if love.mouse.isDown(controls.camera.zoom.reset) then
  112. zoomlevel = settings.zoom.reset
  113. end
  114. -- Zoom Limit:
  115. local max, min = settings.zoom.max, settings.zoom.min
  116. if zoomlevel < min then
  117. zoomlevel = min
  118. end
  119. if zoomlevel > max then
  120. zoomlevel = max
  121. end
  122. --debug(zoomlevel)
  123. cam:zoomTo(zoomlevel)
  124. end
  125. -- Time Warp
  126. function timewarpControls()
  127. -- Time Warp Toggle Cooldowns:
  128. local maxCooldown = settings.warp.cooldown
  129. -- Time Warp Steps:
  130. local step = settings.warp.step
  131. -- Time Warp Limits:
  132. local min = settings.warp.min
  133. local max = settings.warp.max
  134. -- Decrease Warp
  135. if love.keyboard.isDown(controls.flight.warp.down) and warpCoolDown <= 0 then
  136. warpspeed = warpspeed - step
  137. warpCoolDown = maxCooldown
  138. end
  139. -- Increase Warp
  140. if love.keyboard.isDown(controls.flight.warp.up) and warpCoolDown <= 0 then
  141. warpspeed = warpspeed + step
  142. warpCoolDown = maxCooldown
  143. end
  144. -- Reset Warp
  145. if love.keyboard.isDown(controls.flight.warp.reset) then
  146. warpspeed = min
  147. end
  148. -- Value Correction
  149. if warpspeed < min then
  150. warpspeed = min
  151. elseif warpspeed > max then
  152. warpspeed = max
  153. end
  154. warpCoolDown = warpCoolDown - 1
  155. return warpspeed
  156. end
  157. -- Menubuttons
  158. function menubuttonUpdate()
  159. if GAMESTATE == gamestate.menu then
  160. for i, button in ipairs(menubutton.menu) do
  161. button:update()
  162. end
  163. elseif GAMESTATE == gamestate.game then
  164. for i, button in ipairs(menubutton.game) do
  165. button:update()
  166. end
  167. end
  168. end
  169. function menubuttonDraw()
  170. if GAMESTATE == gamestate.menu then
  171. for i, button in ipairs(menubutton.menu) do
  172. button:draw()
  173. end
  174. elseif GAMESTATE == gamestate.game then
  175. for i, button in ipairs(menubutton.game) do
  176. button:draw()
  177. end
  178. end
  179. end
  180. -- MAIN
  181. function love.update(dt)
  182. if GAMESTATE == gamestate.quit then
  183. debug("Game has been quit, goodbye :)")
  184. love.event.quit(0)
  185. elseif GAMESTATE == gamestate.menu then
  186. elseif GAMESTATE == gamestate.game then
  187. button.pause:update()
  188. if (button.pause.isActive) then
  189. for i, butt in ipairs(pausebutton) do
  190. butt:update()
  191. end
  192. return
  193. end
  194. -- Game Objects:
  195. for i=1, timewarpControls() do
  196. -- Physics go in here:
  197. updatePlanets()
  198. player:update(dt)
  199. end
  200. player:throttleControls()
  201. -- Gui:
  202. gui:update(dt)
  203. button.tutorial:update()
  204. -- Camera:
  205. cam:lookAt(player.x, player.y)
  206. cameraControls()
  207. end
  208. menubuttonUpdate()
  209. end
  210. function love.draw()
  211. if GAMESTATE == gamestate.menu then
  212. -- Game Title:
  213. love.graphics.setColor(1, 1, 0.6)
  214. love.graphics.setFont(font.gametitle)
  215. love.graphics.printf(info.title, 20, 20, width, "left")
  216. elseif GAMESTATE == gamestate.game then
  217. cam:attach()
  218. -- Game Objects:
  219. drawPlanets()
  220. drawEffects()
  221. player:draw()
  222. cam:detach()
  223. -- Gui:
  224. player:drawPositionIndicator()
  225. gui:draw()
  226. button.tutorial:draw()
  227. if button.tutorial.isActive then
  228. textbox.tutorial:draw()
  229. else
  230. button.pause:draw()
  231. if (button.pause.isActive) then
  232. for i, butt in ipairs(pausebutton) do
  233. butt:draw()
  234. end
  235. end
  236. end
  237. end
  238. menubuttonDraw()
  239. end
  240. function restartGame()
  241. button.pause.isActive = false
  242. button.tutorial.isActive = false
  243. player:reset()
  244. end