diff options
author | Indrajith K L | 2022-03-05 05:44:05 +0530 |
---|---|---|
committer | Indrajith K L | 2022-03-05 05:44:05 +0530 |
commit | 37bf7eab28727f428cf456c61f698e0a3be55bb0 (patch) | |
tree | a7015077b87f334821887020d2f6f70f4a5f9f28 /entities/pickable.lua | |
parent | 7683830ed25213c4e444c5587559fe803b480ea7 (diff) | |
download | YEAD-37bf7eab28727f428cf456c61f698e0a3be55bb0.tar.gz YEAD-37bf7eab28727f428cf456c61f698e0a3be55bb0.tar.bz2 YEAD-37bf7eab28727f428cf456c61f698e0a3be55bb0.zip |
* Player/ Enemy Chase
* Pickable Entity
* Enemies
Diffstat (limited to 'entities/pickable.lua')
-rw-r--r-- | entities/pickable.lua | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/entities/pickable.lua b/entities/pickable.lua new file mode 100644 index 0000000..00dc174 --- /dev/null +++ b/entities/pickable.lua @@ -0,0 +1,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
\ No newline at end of file |