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.

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