-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircle.lua
More file actions
64 lines (51 loc) · 1.6 KB
/
Copy pathcircle.lua
File metadata and controls
64 lines (51 loc) · 1.6 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
circle = {}
circle.shape = nil
circle.body = nil
circle.img = nil
circle.world = nil
circle.radius = 20 -- For graphics only
function circle:load(world, x, y, rad, imgPath)
self.world = world
self.radius = rad
if imgPath then
self.img = love.graphics.newImage(imgPath);
end
self.shape = love.physics.newCircleShape(rad);
self.body = love.physics.newBody(world, x, y, "dynamic")
self.fixture = love.physics.newFixture(self.body, self.shape, 1)
end
function circle:draw()
if self.img ~= nil then
local radius = self.radius
local scale = 2*radius / self.img:getWidth()
love.graphics.push()
love.graphics.translate(self.body:getX(), (self.body:getY()))
love.graphics.rotate(self.body:getAngle())
love.graphics.translate(-self.body:getX(), -self.body:getY())
love.graphics.draw(self.img, self.body:getX() - radius,
self.body:getY() - radius, 0, scale)
love.graphics.pop()
end
if physicsDebug and self.body:isActive() then
love.graphics.setColor(0, 0, 255, 255)
love.graphics.circle("line", self.body:getX(), self.body:getY(),
self.shape:getRadius())
love.graphics.setColor(255, 255, 255, 255)
end
end
function circle:setEnabled(enabled)
self.body:setActive(enabled)
end
function circle:getEnabled()
return self.body:isActive()
end
function circle:getX()
return self.body:getX()
end
function circle:getY()
return self.body:getY()
end
function circle:getRadius()
return self.shape:getRadius()
end
return circle