From the course: Python Practice: Real-World Coding Challenges

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Challenge: Hitting a wall

Challenge: Hitting a wall

(pleasant electronic music) - In the previous challenge, we dynamically generated some structures that would do things like move our scribe forward multiple times. Turns out this concept of distance might be really handy to pass into the forward function. Modify your forward function to take in a distance which will move the scribe forward that number of times. But wait, there's more. If the scribe hits a wall while moving forward, it should bounce. If the wall is a vertical wall where the future position of the scribe would interfere with the x-axis boundaries, it should flip the direction of the x component of the direction vector. It bounces off while the Y component keeps going in the same direction. If the wall is a horizontal wall, it flips the direction to the Y component of the direction vector. Hint, you might want to modify the hitsWall function in the canvas to return information about the horizontal or vertical…

Contents