Skip to content

Instantly share code, notes, and snippets.

@gabrielflorit
Last active March 1, 2020 06:08
Show Gist options
  • Save gabrielflorit/31051d77904a3379e8bd58e3c83647d1 to your computer and use it in GitHub Desktop.
Save gabrielflorit/31051d77904a3379e8bd58e3c83647d1 to your computer and use it in GitHub Desktop.
SCRIPT-8
// title: Break
const ball = {
x: 30,
y: 60,
dx: 1,
dy: 1,
r: 3
}
const moveBall = ball => {
ball.x += ball.dx
ball.y += ball.dy
}
const bounceBall = ball => {
if (ball.x < 0 || ball.x > 128) {
ball.dx *= -1
}
if (ball.y < 0 || ball.y > 128) {
ball.dy *= -1
}
}
const drawBall = ball => {
circFill(ball.x, ball.y, ball.r, 4)
}
init = state => {
state.ball = ball
}
update = (state, input, elapsed) => {
bounceBall(state.ball)
moveBall(state.ball)
}
draw = state => {
clear()
rectStroke(0, 0, 128, 128, 5)
drawBall(state.ball)
}
{
"iframeVersion": "0.1.280",
"lines": [
43,
0,
0,
0,
0,
0,
0,
0
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment