-
Notifications
You must be signed in to change notification settings - Fork 0
/
ball.lua
36 lines (30 loc) · 912 Bytes
/
ball.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
require 'class'
Ball = class {}
function Ball:create(world, x, y, dir)
local obj = self:new {
graphics = love.graphics.newImage('blinky.png'),
}
obj.r = obj.graphics:getWidth()/2
obj.body = love.physics.newBody(world, x, y - obj.r*dir, 'dynamic')
obj.body:setGravityScale(dir)
obj.shape = love.physics.newCircleShape(obj.r)
obj.fixture = love.physics.newFixture(obj.body, obj.shape, 0.2)
obj.fixture:setFriction(0.1)
obj.fixture:setRestitution(0.8)
obj.collideOn = { obj.fixture }
return obj
end
function Ball:getX()
return self.body:getX() - self.r
end
function Ball:getY()
return self.body:getY() - self.r
end
function Ball:collide(fixture, contact)
-- Change gravity direction when we hit a player
if fixture:getCategory() == 2 then
self.body:setGravityScale(fixture:getUserData().dir)
end
end
function Ball:update(dt)
end