Skip to content

Instantly share code, notes, and snippets.

@bashbaugh
Last active March 4, 2019 03:12
Show Gist options
  • Save bashbaugh/9d144c47008553fccc2564e4633995bd to your computer and use it in GitHub Desktop.
Save bashbaugh/9d144c47008553fccc2564e4633995bd to your computer and use it in GitHub Desktop.
// If y distance is greater than dot_distance_apart
if (dots_y[dots_y.length - 1] > dot_distance_apart)
{
// Choose random new color:
let new_color = dot_color_options[Math.floor(Math.random()*dot_color_options.length)];
// Choose random new lane:
let lane_number = Math.floor(Math.random() * (canvas_element.width / player_move_increment + 1));
// Convert to new x position:
let new_x_position = lane_number * player_move_increment;
// Create new dots by pushing the new x, y, and color to the arrays:
dots_x.push(new_x_position);
dots_y.push(0); // all dots start with a y position of 0
dots_color.push(new_color);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment