Using the canvas element also allowed me to create an area in which the player can never leave. This was done by setting the canvas width and height to the screen’s maximum width and height as well creating if statements to prevent the player’s position from going negative or beyond the canvas width and height.
Whenever the player character touches the coin, the coin relocates to another position on the game area and the player’s score increases by one. I accomplished this by creating a variable that calculates the distance between player and the coin. If the distance is less then the combined value of the player’s radius and the coin’s radius, a function will activate causing the coin to relocate to another position within the game area.
Whenever the player beats the high score, it will be stored locally within the user’s browser. Every time the user visits the application or ends a play session, the high score will be displayed on the screen.