I'm trying to create an app with a sprite that chases me when I enter a certain range around it. When the screen initializes, the sprite is given a random heading of [random from 0 to 3] * 90.
It is then supposed to move straight forward until it reaches a wall (indicated by a different canvas color). When it touches the wall it shall calculate a random heading that is different from the current one so as not to cross the wall.
However when I run the app, the sprite sometimes crosses the wall or turns when there is no wall in front of it.
Any help would be appreciated.