Game Development Reference
In-Depth Information
return false
end
We next use a bit of trig magic to determine whether the selected target gem is di-
agonal to the selected gem:
local touchedGem =
self.gameLayer.gridGemsColumnMap[px][py]
if (touchedGem.gem == self.gameLayer.selectedGem
or (px == self.gameLayer.selectedIndex.x and py ==
self.gameLayer.selectedIndex.y)) then
self.gameLayer.targetGem = nil
return false
end
return true
end
We finish by checking whether the target gem is not the same as the previously
selected gem.
6. Now, let's move on to the onTouchUp event handling:
function GridController:onTouchUp (touch)
if (self.gameLayer.running == false) then return
end
self.touchDown = false
if (self.enabled == false) then return end
if (self.gameLayer.selectedGem ~= nil) then
self.gameLayer:dropSelectedGem() end
end
Pretty simple! We just change the z layering of the selected gem, as we want to
make sure that the gem is shown above the others when the swap takes place. So
when we release the gem, we push it back to its original z level (which is what
the dropSelectedGem method does, and we'll see how it does this soon).
7. The onTouchMove event handles the option of dragging the selected gem until
it swaps places with another gem:
function GridController:onTouchMove (touch)
if (self.gameLayer.running == false) then return
Search WWH ::




Custom Search