Game Development Reference
In-Depth Information
local x = math.ceil ((mx - constants.TILE_SIZE * 0.5)
/ (constants.TILE_SIZE + constants.GRID_SPACE))
local y = math.ceil ((my - constants.TILE_SIZE *
0.5) / (constants.TILE_SIZE + constants.GRID_SPACE))
if (x < 1) then x = 1 end
if (y < 1) then y = 1 end
if (x > constants.GRID_SIZE_X) then x =
constants.GRID_SIZE_X end
if (y > constants.GRID_SIZE_Y) then y =
constants.GRID_SIZE_Y end
return {x = x, y = y, gem =
self.gameLayer.gridGemsColumnMap[x][y]}
end
We finish by checking whether the touch is out of array bounds.
5. And now let's see the logic to determine whether the target gem is a valid target:
function GridController:isValidTarget (px, py, touch)
local offbounds = false
if (px > self.gameLayer.selectedIndex.x + 1) then
offbounds = true end
if (px < self.gameLayer.selectedIndex.x - 1) then
offbounds = true end
if (py > self.gameLayer.selectedIndex.y + 1) then
offbounds = true end
if (py < self.gameLayer.selectedIndex.y - 1) then
offbounds = true end
We first check to see whether the target gem is at the top, bottom, left, or right of
the selected gem:
local cell = math.sin (math.atan2 (math.pow(
self.gameLayer.selectedIndex.x - px, 2), math.pow(
self.gameLayer.selectedIndex.y- py, 2) ) )
if (cell ~= 0 and cell ~= 1) then
offbounds = true
end
if (offbounds == true) then
Search WWH ::




Custom Search