Hello , recently I started to deal with the object of Canvas and make the game a series of Atari . I have a question on how to use the methods or Canvas object is best done to my character stopped from touching the walls and move around certain tracks ? I tried to conditions such as:
if (pozX > 180 && pozX < 190) {
pozX = 185
}
Instead doing collision testing...
Map out the acceptable paths for your game characters
For example, here is part of your game board.
Here is a corresponding map of the acceptable paths. "1" represents an allowed move while "0" represents a disallowed move (a game wall). Edit: Ouch! I messed up the map in the lower right -- pardons!
Now you can refer to your acceptable move map when the player presses the arrow keys to move.
For example, if the player starts in the upper left (they start at the "blue 1"). They can move right and down because those moves map to "1"s. But they cannot move up or left because those moves map to "0"s.