For players who can move, how can they tell if they touch an obstacle when they move?

suppose the black square is the player and the white background is the wall. How to tell the black square touches the wall and tell him to stop moving.

clipboard.png

Dec.14,2021

every time it is inefficient to judge traversal, especially when there are many walls
save the data of each location of the map into a two-dimensional array in advance
for example

map[0][0] = 'blank'
map[2][1] = 'wall'
map[7][6] = 'red'
When

moves, you can directly judge whether map [x] [y] is wall or something else

.

each square is a coordinate, and when the square moves, determine whether the coordinates are equal

.
Menu