We are about to switch to a new forum software. Until then we have removed the registration on this forum.
So I as I understand how to load a grid file from a text file I come about to ask how do I make the player stop against these barriers properly ?
Answers
You want the player to ignore the barriers? Well, okay.
Each frame, Pacman tries to move. He does this by saving his current position, using his direction of movement to update his current position, then checking to see if this new position - after having applies the movement - is not inside a square that is a barrier. If he is now in a barrier, his position reverts back to the saved position. If he's not in a barrier, the new position persists.
You just need to remove the check for being in the barrier. That way he will always move.
... Just reread your question and I totally misunderstood you. You want the Pacman to OBEY the barriers. Okay.
Each frame, Pacman tries to move. He does this by saving his current position, using his direction of movement to update his current position, then checking to see if this new position - after having applies the movement - is not inside a square that is a barrier. If he is now in a barrier, his position reverts back to the saved position. If he's not in a barrier, the new position persists.
This way a barrier stops Pacman from moving.
The code will look like this:
From here: https://forum.processing.org/two/discussion/26345/best-way-to-make-world-borders-for-a-game
This really didn't need to be a new Question. Try to keep things together - it gets confusing otherwise
@koogs Will do from now on.
Alright so I played around with the stuff you said @TfGuy44 but can't get around it here's some code which I did out. I know I am wrong but I can't pinpoint it myself so any possible solution ?
(Sorry for so much code but it gives a good idea of what I am trying to do)
You should describe what happens falsely now and what you want to happen instead.
Which line numbers are involved and are potential suspects?
Your onBarrier() function doesn't do what you want. And you are calling it in several places where its result is just not used. You should also put the variables for the Pacman class inside the class. Here's a fixed version:
See also:
https://forum.processing.org/two/discussion/11156/pac-man-game-not-completed-asking-for-assistance
An online rogue-like sample: http://Studio.ProcessingTogether.com/sp/pad/export/ro.9Ql2E8JBC54LJ