Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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 y > 0 then
  101. -- Zoom in:
  102. zoomlevel = zoomlevel + step*(zoomlevel*10)
  103. elseif y < 0 then
  104. -- Zoom out:
  105. zoomlevel = zoomlevel - step*(zoomlevel*10)
  106. end
  107. end
  108. -- Reset Zoom:
  109. if love.mouse.isDown(controls.camera.zoom.reset) then
  110. zoomlevel = settings.zoom.reset
  111. end
  112. -- Zoom Limit:
  113. local max, min = settings.zoom.max, settings.zoom.min
  114. if zoomlevel < min then
  115. zoomlevel = min
  116. end
  117. if zoomlevel > max then
  118. zoomlevel = max
  119. end
  120. --debug(zoomlevel)
  121. cam:zoomTo(zoomlevel)
  122. end
  123. -- Time Warp
  124. function timewarpControls()
  125. -- Time Warp Toggle Cooldowns:
  126. local maxCooldown = settings.warp.cooldown
  127. -- Time Warp Steps:
  128. local step = settings.warp.step
  129. -- Time Warp Limits:
  130. local min = settings.warp.min
  131. local max = settings.warp.max
  132. -- Decrease Warp
  133. if love.keyboard.isDown(controls.flight.warp.down) and warpCoolDown <= 0 then
  134. warpspeed = warpspeed - step
  135. warpCoolDown = maxCooldown
  136. end
  137. -- Increase Warp
  138. if love.keyboard.isDown(controls.flight.warp.up) and warpCoolDown <= 0 then
  139. warpspeed = warpspeed + step
  140. warpCoolDown = maxCooldown
  141. end
  142. -- Reset Warp
  143. if love.keyboard.isDown(controls.flight.warp.reset) then
  144. warpspeed = min
  145. end
  146. -- Value Correction
  147. if warpspeed < min then
  148. warpspeed = min
  149. elseif warpspeed > max then
  150. warpspeed = max
  151. end
  152. warpCoolDown = warpCoolDown - 1
  153. return warpspeed
  154. end
  155. -- Menubuttons
  156. function menubuttonUpdate()
  157. if GAMESTATE == gamestate.menu then
  158. for i, button in ipairs(menubutton.menu) do
  159. button:update()
  160. end
  161. elseif GAMESTATE == gamestate.game then
  162. for i, button in ipairs(menubutton.game) do
  163. button:update()
  164. end
  165. end
  166. end
  167. function menubuttonDraw()
  168. if GAMESTATE == gamestate.menu then
  169. for i, button in ipairs(menubutton.menu) do
  170. button:draw()
  171. end
  172. elseif GAMESTATE == gamestate.game then
  173. for i, button in ipairs(menubutton.game) do
  174. button:draw()
  175. end
  176. end
  177. end
  178. -- MAIN
  179. function love.update(dt)
  180. if GAMESTATE == gamestate.quit then
  181. debug("Game has been quit, goodbye :)")
  182. love.event.quit(0)
  183. elseif GAMESTATE == gamestate.menu then
  184. elseif GAMESTATE == gamestate.game then
  185. button.pause:update()
  186. if (button.pause.isActive) then
  187. for i, butt in ipairs(pausebutton) do
  188. butt:update()
  189. end
  190. return
  191. end
  192. -- Game Objects:
  193. for i=1, timewarpControls() do
  194. -- Physics go in here:
  195. updatePlanets()
  196. player:update(dt)
  197. end
  198. player:throttleControls()
  199. -- Gui:
  200. gui:update(dt)
  201. button.tutorial:update()
  202. -- Camera:
  203. cam:lookAt(player.x, player.y)
  204. cameraControls()
  205. end
  206. menubuttonUpdate()
  207. end
  208. function love.draw()
  209. if GAMESTATE == gamestate.menu then
  210. -- Game Title:
  211. love.graphics.setColor(1, 1, 0.6)
  212. love.graphics.setFont(font.gametitle)
  213. love.graphics.printf(info.title, 20, 20, width, "left")
  214. elseif GAMESTATE == gamestate.game then
  215. cam:attach()
  216. -- Game Objects:
  217. drawPlanets()
  218. drawEffects()
  219. player:draw()
  220. cam:detach()
  221. -- Gui:
  222. player:drawPositionIndicator()
  223. gui:draw()
  224. button.tutorial:draw()
  225. if button.tutorial.isActive then
  226. textbox.tutorial:draw()
  227. else
  228. button.pause:draw()
  229. if (button.pause.isActive) then
  230. for i, butt in ipairs(pausebutton) do
  231. butt:draw()
  232. end
  233. end
  234. end
  235. end
  236. menubuttonDraw()
  237. end
  238. function restartGame()
  239. button.pause.isActive = false
  240. button.tutorial.isActive = false
  241. player:reset()
  242. end