If you keep track of which tiles are passible in an list, you only
need to consider the tiles surrounding a given monster, which
should not be a problem performance-wise. In fact, you only need to
consider the tiles that the monster wants to move into, and if the
first one is passible then that's all you need to test.
Let's say you have a map that is 100 x 100 tiles. You can
initialize a list for it like so:
passible_at = [[True] * 100] * 100 # Create a 2 dimensional list
with an element for each tile
(then populate it however you create your map, setting the elements
that are not passable to some True value). So if there's a big
boulder at x=25, y=30 you would do:
passible_at[25, 30] = False
let's say you want to see if you can pass through a given x, y
coordinate on the map, just do this:
if passible_at[x, y]:
# can go there, tally ho!
else:
# can't go there, maybe consider another direction
You could even get fancy and have varying degrees of passibility,
like mountains or swamp or debris that can be passed through, but
takes longer to do so. This would be done by assigning a
passibility "score" to each map location that tells how many turns
it takes to get through. The value None could mean "impassible".
Another question is are we talking about navigating around small
obstacles (relative to the map) or through a more complex system of
rooms with long walls or other large obstructions with only small
pathways through? If it's the latter you'll probably want to use a
path finding algorithm so the monster can figure out how to
navigate through the rooms from point a to point b (an example
implementation of this was posted a week or so ago). If you do have
"rooms", but the monsters don't ever leave the room they start in
on their own, this might not be necessary, however.
-Casey
On Apr 30, 2007, at 6:56 AM, Samuel Mankins wrote:
Now that my AI is chasing the Ninja around, I'd like to make it so
that when they bump into a block, they "slide" around it. I
figured I'd do this by having it find out where the block is in
relation to the monster, and then stop moving in the direction
that was causing it to bump into the block. But I don't want to
say "for block in block_group" because that eats up too much CPU,
so my question is, how can I figure out where the block is without
using that? Is there an easier way to solve the problem?
I tried just using ifs to do it (It looked something like: If
self.x_dir == 1 and self.y_dir == 1, self.x_dir = 1 and self.y_dir
= 0) but then the monsters just floated over the blocks.
Thanks!