-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhealthBar.lua
More file actions
33 lines (27 loc) · 998 Bytes
/
healthBar.lua
File metadata and controls
33 lines (27 loc) · 998 Bytes
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
local healthBar = {}
setmetatable(healthBar,healthBar)
function healthBar:__call(c1,x,y,side)
local nt = {c1 = c1,x = x,y = y,maxHealth = c1.health,side = side}
setmetatable(nt,{__index = healthBar})
registerObserver(nt,"damageReceived")
nt.scaleFactor = 220/nt.c1.health
return nt
end
function healthBar:update()
end
function healthBar:draw(scaleX,scaleY)
love.graphics.setColor(0,255,0)
if self.c1.health > 0 then
if self.side == "left" then
local effectiveX = (self.x+(self.maxHealth-self.c1.health)*self.scaleFactor)*scaleX
love.graphics.rectangle("fill",effectiveX,self.y*scaleY,self.c1.health*scaleX*self.scaleFactor,25*scaleY)
else
love.graphics.rectangle("fill",self.x*scaleX,self.y*scaleY,self.c1.health*scaleX*self.scaleFactor,25*scaleY)
end
end
love.graphics.setColor(0,0,0)
love.graphics.rectangle("line",self.x*scaleX-1,(self.y*scaleY)-1,self.maxHealth*self.scaleFactor*scaleX+2,25*scaleY+2)
end
function healthBar:notify(event,a,b)
end
return healthBar