Last active
February 27, 2019 02:18
-
-
Save bashbaugh/6c39c59b92b4a8ebd337b3ecf68b05ab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function update() | |
{ | |
// Set current time (milliseconds): | |
let time_right_now = new Date().getTime() | |
if (time_right_now - start_time < game_duration) | |
{ | |
// Compare player coordinates to dot coordinates to see whether the player is above a dot. Increment score if so. | |
// Check distance from highest dot to top of screen. If greater than dot_distance_apart, create a new dot at top. | |
} | |
else | |
{ | |
// Set game_over to true. | |
} | |
// Clear the canvas and draw background: | |
draw_background(); | |
// Draw the dots and move them down the canvas: | |
for (i = 0; i < dots_x.length; i++) | |
{ | |
// Move dot down canvas a little: | |
dots_y[i] += dot_pixels_per_frame; | |
canvas.beginPath(); // Start drawing | |
canvas.arc(dots_x[i], dots_y[i], dot_radius, 0, 2*Math.PI); // Draw 360 degree arc (full circle) | |
canvas.fillStyle = dots_color[i]; // Set color | |
canvas.fill(); // Fill in circle | |
canvas.closePath(); // End drawing | |
} | |
// Ensure that player is within canvas: | |
player_x = Math.max(0, Math.min(player_x, canvas_element.width)) | |
// Draw player: | |
canvas.beginPath(); | |
canvas.arc(player_x, player_y, player_radius, 0, 2*Math.PI); | |
canvas.fillStyle = player_color; | |
canvas.fill(); | |
canvas.closePath(); | |
// Draw score: | |
canvas.fillStyle = text_color; | |
canvas.font = "20px Arial"; | |
canvas.fillText(score, 20, 20); | |
// IF game_over: | |
// Draw game over screen | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment