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
|
Class = require("libs.hump.class")
Pickable = Class{
init = function(self, x, y, w, h, name, gameWorld)
self.x = x
self.y = y
self.width = w
self.height = h
self.image = name
self.world = gameWorld
self.image = love.graphics.newImage("assets/images/"..name..".png")
self.sfx = love.audio.newSource("assets/sfx/"..name..".wav", "static")
end,
x=0,
y=0,
width=0,
height=0,
image=nil,
world=nil,
collider=nil,
acquired=false,
sfx=nil
}
function Pickable:setCollider(colliderData)
self.collider = self.world:newRectangleCollider(self.x, self.y, self.width, self.height)
self.collider:setFixedRotation(true)
self.collider:setType('static')
self.collider:setCollisionClass('pickable')
self.collider:setObject(colliderData)
end
function Pickable:draw()
love.graphics.draw(self.image,self.x, self.y)
end
function Pickable:update(dt)
if self.collider then
if self.collider:enter('player') then
self.acquired = true
self.sfx:play()
self.collider:destroy()
end
end
end
return Pickable
|