I have a 10x10 grid. On this grid I spawn a ball (play piece) at grid position grid[1][10]. I have a tap event listener function that checks the position of the ball, spawns two new balls at the same position, removes the original ball and then based on the original position transitions each of the new balls to a new grid position. Here’s my question: Is there a simple way to set up a series of if - then statements to check the grid position of the ball in the tap event listener? What I don’t want is 100 different if-then statements, one for each grid position. Here’s the tap event listener function to handle one grid position:
local function ballTapped(event)
local t = event.target
xNew= t.x
yNew = t.y
if t.x == grid[1][10].x and t.y == grid[1][10].y then
print(tracker)
t:removeSelf()
t = nil
blueBallSpawn()
blueBallSpawn()
transition.to(spawnTable[tracker-1],{time = 50, x = grid[1][9].x} )
transition.to(spawnTable[tracker], {time = 50, x = grid[2][10].x})
audio.play(miteSound)
end
end
In this example, the ball is in the bottom left corner of the grid. The basis of the game play is that tapping a ball divides it in two, the two new balls transitioning to new grid positions. There will be various grid positions to handle - corners, sides, and two separate interiors. Like I said above, I don’t want 100 different if-then statements to handle the transitions. Any help would be greatly appreciated. Thanks.