Game Development Reference
In-Depth Information
This game only allows us to shoot down planes and balloons, so in our moveBullets function, we check if
the bullet has collided with any object; if it hits the angryCloud or the tallHouse they are absorbed.
local function moveBullets()
local blt
for i=#bullets,1,-1 do
blt = bullets[i]
blt.x = blt.x + FAST
position(blt.sprite, blt.x, blt.y)
tRect = {
x=blt.x,
y=blt.y,
wd=blt.wd,
ht=blt.ht,
}
for j = #scenery, 1, -1 do
local nme = scenery[j]
if nme.objType == objects.plane or nme.objType == objects.balloon then
hx, hy = getPosition(nme.sprite)
nRect = {
x = hx,
y = hy,
wd = nme.sprite.width,
ht = nme.sprite.height,
}
if collides(nRect, tRect) == true then
-- increment score
if nme.objType == objects.plane then score = score + 50 end
if nme.objType == objects.balloon then score = score + 30 end
updateText(txtScore, score)
destroyObject(blt.sprite)
table.remove(bullets,i)
blt = nil
destroyObject(nme.sprite)
table.remove(scenery,j)
nme=nil
return
end
elseif nme.objType == objects.angryCloud or
nme.objType == objects.tallHouse then
hx, hy = getPosition(nme.sprite)
nRect = {
x = hx,
y = hy,
wd = nme.sprite.width,
ht = nme.sprite.height,
}
 
Search WWH ::




Custom Search