ScratchData LogoScratchData
Back to AlSweigart's profile

Line of Sight Algorithm Demo

ALAlSweigart•Created September 14, 2013
Line of Sight Algorithm Demo
26
24
1348 views
View on Scratch

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.)

Description

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.)

Project Details

Project ID12397800
CreatedSeptember 14, 2013
Last ModifiedFebruary 4, 2018
SharedSeptember 14, 2013
Visibilityvisible
CommentsAllowed