Challenge: Start/Stop Animation

Remember the is_cartwheeling and is_flipping values from when we built the avatar in Chapter 3, Project: Making an Avatar? Let’s add two more if statements to the keyboard event listener. If the C key, which the computer thinks is the number 67, is pressed, then the avatar should either start or stop cartwheeling. If the F key, which the computer thinks is 70, is pressed, then the flip routine should start or stop.

Hint: switch between true and false with the not operator. In JavaScript, the not operator is an exclamation point, !. You can use this not operator to assign the value of is_cartwheeling to the opposite of its original value with something like is_cartwheeling = !is_cartwheeling. We’ll see this ...

Get 3D Game Programming for Kids now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.