With the code that we have covered so far, our hero will walk around without any awareness of the special tiles that we have placed, so he will walk right through walls. We need to fix this. Now that we have added methods to make it fairly simple to determine where our special triggers are, we can revisit the
setHeroPos
method, which we started earlier. This is a complete replacement of the earlier method.
Filename: TDPlayfieldLayer.m
-(void) setHeroPos:(CGPoint)pos { // Get the tile coordinates CGPoint tileCoord = [self tileCoordForPos:pos]; // Check if the new tile is blocked if ([self isWallAtTileCoord:tileCoord]) { // Return without allowing the move return; } // Check if the hero picked up health if ([self isHealthAtTileCoord:tileCoord]) { // Remove it from the map [_triggers removeTileAt:tileCoord]; [_pickups removeTileAt:tileCoord]; // Add health to the player [self heroGetsHealth...