Line of Sight Algorithm Demo

  scripts
  sprites
See inside
Instructions

Avoid being seen by the cat! This demonstrates code that implements a "line of sight" algorithm.

- Use arrow keys to move around.
- Space key will toggle on & off the "line of sight" sprite.
- Q key will toggle on & off the cat's autopilot. When off, you can move the cat with the WASD keys.
- 1 through 6 will change the backdrop. (You can move the cat and crab with the mouse if they get stuck in a wall.)

Notes and Credits

Learn to program games with this free online Scratch course: https://inventwithscratch.com/class

The algorithm moves the red "line of sight" sprite to the cat and points towards the crab. If the crab is within plus or minus 70 degrees in front of the cat, then the line moves towards the crab. If the "line of sight" is blocked by a blue wall, it stops and goes back to the cat. If it touches the crab, then the cat can "see" the crab.

Press the space key to make the "line of sight" invisible so that the program looks more realistic. (It's only visible just to show you how it works.)

Shared: 14 Sep 2013 Modified: 4 Feb 2018
Favorite this project 14
Love this project 17
Total views 806
View the remix tree  2
  
More projects by AlSweigart