- HI:
- THE PROJECT:
- THE PROBLEM:
So I wrote a class for the power up, which is an object that move downwards and player tries to capture it, ( I used Class.lua to add class feature to lua that you can see in /lib/class.lua ) and added a collision function to the power up class,
Code: Select all
function Powerup:collide(target)
-- if not target then return end
-- first, check to see if the left edge of either is farther to the right
-- than the right edge of the other
if self.x > pup.x + pup.width or pup.x > self.x + self.width then
return false
end
-- then check to see if the bottom edge of either is higher than the top
-- edge of the other
if self.y > pup.y + pup.height or pup.y > self.y + self.height then
return false
end
-- if the above aren't true, they're overlapping
return true
end
here is the part where to call collide function in the PlayState.lua
Code: Select all
if pup then
-- pup is is the power up object
if pup.collide(self.paddle) then
pup.display = false
end
end
- WHAT I DID:
i tried debugging but no thing solved, the only thing that solved it is to use pup (the power up object as global variable) ,
i think the problem in passing the table or the object paddle to the function
- THE END: