Skip to content

Instantly share code, notes, and snippets.

@janeoa
Created February 23, 2021 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janeoa/9180f27d61c8f8db31ad956a36c68627 to your computer and use it in GitHub Desktop.
Save janeoa/9180f27d61c8f8db31ad956a36c68627 to your computer and use it in GitHub Desktop.
asdf
var ball = {
x : 150, y : 200,
dir : {
x: 1, y:1
}
}
var wall = {x: 400, y:400}
var score = 0;
function setup() {
createCanvas(400, 400);
background(220);
ball.dir.x = random(2)-1;
ball.dir.y = random(2)-1;
}
function draw() {
background(220);
textSize(32);
text('Score: ' + score, 10, 30);
rect(10, mouseY-30, 10, 60);
circle(ball.x, ball.y, 10);
if(ball.x > wall.x) ball.dir.x = -ball.dir.x
if(ball.y > wall.y) ball.dir.y = -ball.dir.y
if(ball.y < 0) ball.dir.y = -ball.dir.y
if(ball.x < 10){
ball.x = random(wall.x)
ball.y = random(wall.y)
ball.dir.x = random(2)-1;
ball.dir.y = random(2)-1;
}
if(ball.x<20 && ball.y < mouseY+30 && ball.y > mouseY-30) {
ball.dir.x = -ball.dir.x;
score = score +1 ;
}
ball.x = ball.x+5*ball.dir.x;
ball.y = ball.y+5*ball.dir.y;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment