Game Development Reference
In-Depth Information
tilePos = [self ensureTilePosIsWithinBounds:tilePos];
if ([self isTilePosBlocked:tilePos tileMap:tileMap] == NO)
[self centerTileMapOnTileCoord:tilePos tileMap:tileMap];
Before moving the tilemap, the isTilePosBlocked method is called to see wheth-
er the player can actually move there. If the destination tile coordinate is not blocked,
he will move; otherwise, he won't.
Adding More Content to the Game
So far, we have a game where you guide a character through an isometric tilemap
world. Hiding behind trees and avoiding collisions are just the foundation for a game
set in this world. What if you want to add more actors to the world, whether enemies or
nonplayer characters (NPCs)?
In principle, you animate them just as you'd move the player, except that the player is
centered onscreen whereas NPCs can be anywhere on the tilemap. Still, you only need
to determine which direction the NPC should walk toward and then move him like the
layer is moved in the centerTileMapOnTileCoord method. The only difference
is that the actions are run on the NPC, and the directions need to be reversed, because
you aren't moving the layer; the NPC is moving on the layer.
As soon as you have NPCs wandering around, the next step is to ask how you can get
them to move from A to B while avoiding obstacles and finding the shortest route. The
answer to that is the A* pathfinding algorithm, which is an industry standard and has
been adapted and tweaked for many situations. Tile-based games are ideal candidates
for this particular pathfinding algorithm, because actor positions are usually restricted
to the tile coordinates. For an in-depth introduction to the A* pathfinding algorithm
and, honestly, to a lot of game programming topics in general, you must visit Amit's
Search Nedrilad ::

Custom Search