Skip to content

Instantly share code, notes, and snippets.

@CodeDraken
Last active December 6, 2019 09:56
Show Gist options
  • Save CodeDraken/053085fc5ace145d0e0836d6982e4ee6 to your computer and use it in GitHub Desktop.
Save CodeDraken/053085fc5ace145d0e0836d6982e4ee6 to your computer and use it in GitHub Desktop.
// global variables that will be loaded/initialized later
let canvas, ctx, gravity, ball, friction
function init () {
// our canvas variables
// ...
// set the canvas size
// ...
// world/scene settings
// ...
// starting objects
ball = {
bounce: 0.75, // energy lost on bounce (25%)
radius: 30,
x: canvas.width / 2,
y: canvas.height / 2,
velX: (Math.random() * 15 + 5) * (Math.floor(Math.random() * 2) || -1),
velY: (Math.random() * 15 + 5) * (Math.floor(Math.random() * 2) || -1)
}
// begin update loop
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment