From the course: Coding for Visual Learners: Learning JavaScript from Scratch

Unlock this course with a free trial

Join today to access over 24,400 courses taught by industry experts.

Player interaction

Player interaction

- [Instructor] So far we only completed two items from our to-do list. Which are displaying a number on the screen by using a given interval, and having that number animated on the screen to add dynamism to our game. Next off, we will handle the player interaction. We still have the outstanding task of fetching the user inputs and comparing it to the number on the screen. Let's implement that. To be able to do so, I'm going to be implementing a key pressed function. Remember that the key pressed function is a P5.js function that gets called every time a key is pressed. So here I'm going to declare a function called key pressed, which is a P5.js function that gets called every time a key is pressed. And to make sure that it's working I'm going to console log something inside it. Let's console log the P5.js variable key alongside with a half full message. And now if I'm to execute my program and press a key with the…

Contents