-
Notifications
You must be signed in to change notification settings - Fork 0
/
dustball.lua
39 lines (34 loc) · 1.07 KB
/
dustball.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
require("lovepunk.entity")
require("holdable")
DustBall = PhysicsObject.new(0, 0, 8, 8)
DustBall.__index = DustBall
function DustBall.new(x, y, player)
local self = setmetatable({}, DustBall)
self.x = x-self.width/2
self.y = y
self.collisionLock = false
self.player = player
self.v = {x=0, y=0}
self.type = "dustball"
self.filters = {["level"]="touch"}
self.image = love.graphics.newImage("assets/img/dustbullet.png")
self.originX = self.width/2
self.originY = self.height/2
self.layer = 5
self.isSolid = false
self.lifetime = 20
return self
end
function DustBall:update()
rotation = vectorToAngle(self.v.x, self.v.y)
PhysicsObject.update(self)
self.lifetime = self.lifetime - 1
if self.lifetime < 0 then self:die() end
if (self:collide("level", self.x+self.v.x, self.y+self.v.y)) then self:die() end
end
function DustBall:draw()
love.graphics.draw(self.image, self.x + self.width/2, self.y + self.height/2, rotation, self.scaleX, self.scaleY, self.originX, self.originY)
end
function DustBall:die()
self.scene:remove(self)
end