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

2018/6/14

Pacman Trouble

Ticker175 Ticker175

2018/6/14

#
Hey guys i am currently making a pacman remake in greenfoot but I'm having trouble with getting pacman to move like he does in the original game, moving forward and turning only when there is a path available basically i need to make the actor (pacman) only turn if there is an available path for him to turn into
danpost danpost

2018/6/14

#
You could make use of your mazeMap in your World subclass. Make it public or add a public method to get the value of a "cell". The coordinates of the "cell" that pacman would currently be in is:
int cellX = getX()/30;
int cellY = getY()/30;
You would then change Pacman object movement methods to check what is at a potential target location. For example (again, using jump method code):
if (((Frog_World)getWorld()).mazeMap[cellY-1][cellX]) == 0)
Ticker175 Ticker175

2018/6/15

#
danpost wrote...
You could make use of your mazeMap in your World subclass. Make it public or add a public method to get the value of a "cell". The coordinates of the "cell" that pacman would currently be in is:
int cellX = getX()/30;
int cellY = getY()/30;
You would then change Pacman object movement methods to check what is at a potential target location. For example (again, using jump method code):
if (((Frog_World)getWorld()).mazeMap[cellY-1][cellX]) == 0)
…… that sounds like it is a great idea but don't really understand how to use it or where to put it..... could u explain it in a simpler way
danpost danpost

2018/6/15

#
Ticker175 wrote...
…… that sounds like it is a great idea but don't really understand how to use it or where to put it..... could u explain it in a simpler way
I do not know what more I can say about it. I gave what to use as well as what to do and where.
You could make use of your mazeMap in your World subclass. Make it public or add a public method to get the value of a "cell". The coordinates of the "cell" that pacman would currently be in is:
int cellX = getX()/30;
int cellY = getY()/30;
obviously in an Actor subclass; however, this was given to show how to get the map coordinates -- not necessarily (but could be) used as is in your code (the right side is the important thing, showing a conversion to map coordinates) You would then change Pacman object movement methods to check what is at a potential target location. For example (again, using jump method code):
if (((Frog_World)getWorld()).mazeMap[cellY-1][cellX]) == 0)
Most likely "< 2" should be used instead of "== 0". or, you can explicitly name the possible values of cell that can be traversed:
if ("0 1 2".indexOf(""+((Frog_World)getWorld()).mazeMap[cellY-1][cellX]) >= 0)
You need to login to post a reply.