Hey there, I made an Android game called “Many Jumps” (https://play.google.com/store/apps/details?id=com.joe.games.manyjumps) In that game, you control a bouncy white ball by tilting your device and you must make it land on the platform. Upon collision, the platform teleports to a place with random coordinates and you must make the ball land on the platform again. The code below represents the game logic:
local function platformCollision(self, event) if event.phase == "ended" then if event.target.type == "platform" and event.other.type == "ball" then timer.performWithDelay(1, function() self.x = math.random(0,300) self.y = math.random(50,300) self:setFillColor( math.random(0,1), math.random(0,1), math.random(0,1) ) end ) score = score + 1 scoreText.text = "Score: " .. score media.playSound( "jump.wav" ) end end end
I received negative reviews because of the fact that the platform often appears right on top of the ball, making it bounce downwards and make you lose the game. I searched online for a way I could use math.random() while excluding ball.x and some values close to it, preventing the platform from appearing on top of the ball but unfortunately I couldn’t find a solution and I hope that one of the nice folks can help me sort out this quite disturbing problem.