-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplanets.lua
More file actions
37 lines (33 loc) · 1 KB
/
planets.lua
File metadata and controls
37 lines (33 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
local Planets = {}
-- Create and save a planet
function Planets.create(x, y, scale, img, miniGameIndex)
local planet = {
x = x,
y = y,
img = img,
scale = scale,
radius = img:getWidth() * scale,
miniGameIndex = miniGameIndex
}
table.insert(Planets, planet)
end
-- Return the miniGameIndex of the planet being collided with
-- Returns nil if no collision
function Planets.checkCollision(player)
for _, planet in ipairs(Planets) do
local dx = player.x - planet.x
local dy = player.y - planet.y
local distance = math.sqrt(dx * dx + dy * dy)
if distance < (player.radius + planet.radius) then
return planet.miniGameIndex
end
end
return 1
end
-- Draw all Planets
function Planets.draw()
for _, planet in ipairs(Planets) do
love.graphics.draw(planet.img, planet.x, planet.y, 0, planet.scale * 2, planet.scale * 2, planet.img:getWidth()/2, planet.img:getHeight()/2)
end
end
return Planets