-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyama_physics.lua
53 lines (44 loc) · 1.27 KB
/
yama_physics.lua
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
local physics = {}
function physics.draw(world)
if world then
for i, body in ipairs(world:getBodyList()) do
--fixtures = body:getFixtureList()
for i, fixture in ipairs(body:getFixtureList()) do
physics.drawFixture(fixture)
end
end
end
end
function physics.drawFixture(fixture)
local r, g, b, a = 0, 0, 0, 0
if fixture:getBody():getType() == "static" then
r, g = 255, 0
else
r, g = 0, 255
end
if fixture:isSensor() then
b = 255
else
b = 0
end
if fixture:getBody():isActive() then
a = 102
else
a = 51
end
if not fixture:getUserData() then
a = 255
end
love.graphics.setColor(r, g, b, a)
if fixture:getShape():getType() == "circle" then
love.graphics.circle("fill", fixture:getBody():getX(), fixture:getBody():getY(), fixture:getShape():getRadius())
elseif fixture:getShape():getType() == "polygon" then
love.graphics.polygon("fill", fixture:getBody():getWorldPoints(fixture:getShape():getPoints()))
elseif fixture:getShape():getType() == "edge" then
love.graphics.line(fixture:getBody():getWorldPoints(fixture:getShape():getPoints()))
elseif fixture:getShape():getType() == "chain" then
love.graphics.line(fixture:getBody():getWorldPoints(fixture:getShape():getPoints()))
end
love.graphics.setColor(255, 255, 255, 255)
end
return physics