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.

131 lines
2.1 KiB

  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. cam = Camera()
  10. zoomlevel = 0.5
  11. -- Loading:
  12. ships = {} --Potentially add other starships in the future?
  13. planet = {}
  14. loadPlanets()
  15. local spawnPlanet = planet[1]
  16. player = Player(spawnPlanet.x, spawnPlanet.y-spawnPlanet.r-1)
  17. gui = Gui(1)
  18. end
  19. -- Planets:
  20. function loadPlanets()
  21. debug("Planets in planet table: "..#planetdata)
  22. for i=1, #planetdata do
  23. local p = planetdata[i]
  24. debug(p.name.." is loading")
  25. table.insert(planet, i,
  26. Planet(
  27. -- Planet Data Assignment:
  28. p.x, p.y,
  29. p.r, p.m,
  30. p.name,
  31. p.colour,
  32. p.parent
  33. )
  34. )
  35. debug(p.name.." is loaded")
  36. end
  37. debug("Planets loaded: "..#planet)
  38. end
  39. function updatePlanets()
  40. planet[1]:update()
  41. end
  42. function drawPlanets()
  43. for i=1, #planet do
  44. planet[i]:draw()
  45. --debug("Drawing planet " .. i)
  46. end
  47. end
  48. -- Camera
  49. function cameraControls()
  50. local zooming = 0.01
  51. function love.wheelmoved(x, y)
  52. if y > 0 then
  53. -- Zoom in:
  54. zoomlevel = zoomlevel + zooming
  55. elseif y < 0 then
  56. -- Zoom out:
  57. zoomlevel = zoomlevel - zooming
  58. end
  59. end
  60. -- Reset Zoom:
  61. if love.mouse.isDown(3) then
  62. zoomlevel = 1
  63. end
  64. -- Zoom Limit:
  65. local max = 4
  66. local min = 0.001
  67. if zoomlevel < min then
  68. zoomlevel = min
  69. end
  70. if zoomlevel > max then
  71. zoomlevel = max
  72. end
  73. --debug(zoomlevel)
  74. cam:zoomTo(zoomlevel)
  75. end
  76. -- MAIN
  77. function love.update(dt)
  78. -- Game Objects:
  79. updatePlanets()
  80. player:update(dt)
  81. -- Gui:
  82. gui:update(dt)
  83. -- Camera:
  84. cam:lookAt(player.x, player.y)
  85. cameraControls()
  86. --debug(player.x .. " " .. player.y)
  87. end
  88. function love.draw()
  89. cam:attach()
  90. -- Game Objects:
  91. drawPlanets()
  92. player:draw()
  93. -- Camera Zoom Player Location Indicator: OVERWORK SOON PLS KAY; IT UGLY
  94. if zoomlevel < 0.3 then
  95. love.graphics.setColor(1, 1, 1, 0.2)
  96. love.graphics.circle("fill", player.x, player.y, (1/zoomlevel)*10)
  97. end
  98. cam:detach()
  99. -- Gui:
  100. gui:draw()
  101. end