Random enemy movement....

richcoyrichcoy Member Posts: 211
edited April 2012 in Working with GS (Mac)
I'm trying to think through how to code a maze game, an example would be something a little like Pac Man.

I'm particularly trying to figure out how to code random moving enemies. I was thinking I could have invisible actors in the maze intersections and when the enemy touched it it would generate a random number that would cause it to maybe change direction.

What has me stumped is the enemy would hit the invisible actor before it gets in the middle of the intersection, causing it to potentially turn to soon. I know I could delay the turn with a timer but that seems like a nightmare to program just right. The other issue is the actor may turn directly into a wall.

I know a slightly easier way would be to just have the enemy roll a random number when it hits a wall but that would mean that an enemy would never change direction at a four-way intersection. I think this solution would also lead to enemies mostly moving around the outside edges of the maze.

Am I at all thinking about this the right way? Am I missing an obvious solution?

Thanks for any tips/advise you have.

Rich

Best Answer

  • EatingMyHatEatingMyHat Posts: 1,246
    Accepted Answer
    You can do either with identifying that the actor hit a wall or with waypoints (transparent actors). In any case you can always "fix" the turn position in the code to make sure it takes the turn correctly.

    A better solution will be using tables to describe the grid of your level. There should be a sample for that on the forum or either in gshelper or deepblue websites.



    Follow Eating My Hat on Facebook, Twitter and our Blog
    Check out my templates in the GS Marketplace or at the store
Sign In or Register to comment.