Game Development Reference
In-Depth Information
if collides(nRect, tRect) == true then
destroyObject(blt.sprite)
table.remove(bullets,i)
blt = nil
end
end
if blt and blt.x > _W then
-- remove it if it is beyond the right-hand side of the screen
destroyObject(blt.sprite)
table.remove(bullets, i)
blt = nil
end
end
15-6 illustrates this. There are ways to perform more precise collision checking, but they're
Figure 15-6. Collisions occur when the helicopter's rectangle overlaps with one of the scenery objects' rectangles
Saving Survivors and Refueling
We also need to test for the condition when the helicopter comes in contact with a survivor or the
fuel tanker. In the case of these two objects, rather than spawn tankers and survivors every so often,
as we do with the scenery objects, we simply hide the objects and display them as needed. In this
way, it becomes important to check for the visibility of the object, as this will be key in our collision
calculations.
Here's how we check the visibility in Corona SDK:
function isVisible(theObject)
if theObject == nil then return false end
return theObject.isVisible
end
 
Search WWH ::




Custom Search