Game Development Reference
In-Depth Information
function moveBall()
local newX, newY = point.x + speed.x, point.y + speed.y
if newX > dimensions[3] or newX < dimensions[1] then speed.x = - speed.x end
if newY > dimensions[4] or newY < dimensions[2] then speed.y = - speed.y end
point.x = point.x + speed.x
point.y = point.y + speed.y
end
function loop_it_all(event)
positionBall(point)
moveBall()
end
Runtime:addEventListener ( "enterFrame", loop_it_all )
will correspondingly get shorter. The bar will also change color from green to orange to red, indicating
the severity of the situation.
local barSize = 200
local barHeight = 30
local healthBar = display.newRect ( 10, 100, barSize, barHeight)
healthBar:setFillColor ( 0, 255, 0 ) -- make this green
healthBar.health = 10 -- a dynamic var for the healthBar
--
function updateHealth()
local theHealth = healthBar.health - 1
if theHealth <0 then return end
healthBar.health = theHealth
--
if theHealth > 6 then --GREEN
healthBar:setFillColor ( 0, 255, 0 )
elseif theHealth > 4 then --ORANGE
healthBar:setFillColor ( 180, 180, 0 )
elseif theHealth > 0 then --RED
healthBar:setFillColor ( 255, 0, 0 )
elseif theHealth == 0 then --BLACK
healthBar:setFillColor ( 0, 0, 0 )
end
 
Search WWH ::




Custom Search