This site requires JavaScript, please enable it in your browser!
Greenfoot back
Imtrying
Imtrying wrote ...

2016/1/8

Let actor move a certain route(maze)

Imtrying Imtrying

2016/1/8

#
Hello! So I'm trying to create some kind of maze game. The problem is that I don't get the enemy I created to move the way I want him to. I want him to move up and down, from one wall to the other, but I have absolutely no idea how to make him do that. At the moment he can even walk through walls. Can someone help?
Super_Hippo Super_Hippo

2016/1/8

#
Save the current direction. See in which directions the enemy can go. If there is only one direction, choose it,. If there are two, choose the direction it doesn't come from. If there are more than two, choose one of the directions it doesn't come from. (In one of my scenarios, the enemies have then a double chance of walking straight rather than turn to another direction. This works pretty well.) Update the current direction.
Imtrying Imtrying

2016/1/9

#
Thanks for your reply! I'm quite a noob at all this greenfoot stuff so while I understand what you are saying I don't quite know what the code has to look like. Maybe you could link the scenario you were talking about so I can take a look at it?
Super_Hippo Super_Hippo

2016/1/9

#
http://www.greenfoot.org/scenarios/7434 It is this one. The source isn't published. But you can take a look so you see if the enemies are doing what you want yours to do.
danpost danpost

2016/1/9

#
If the enemies are only allowed to move along the aisles of the maze (not side to side between the walls of an aisle) and if all intersections occur at regular intervals horizontally and vertically, then it would not be too difficult to code. First check for intersection:
if ((getX()- [< xOffset >])%[< interval >] == 0 && (getY()-[< yOffset >])%[< interval >] == 0)
Then determine number of possible routes (you can add an extra one if the forward direction is available so that you can double its chances of being chosen). Next pick a random number within the range of possible directions. Finally, using same system in determining possible routes, count out the routes to that number and procede in that direction. This is close to what I did for my ghosts in my Pakman scenario (see the 'getDirection' method of the Ghost class).
Imtrying Imtrying

2016/1/10

#
Thank you ! That really helped, it works now
You need to login to post a reply.