Code
void setup(){
size(300,300);
smooth();
noStroke();
}
float px;
float py;
float vx;
float vy;
float startx;
float starty;
int lives = 5;
void draw(){
background(0);
px = px+vx;
py = py+vy;
startx = px+width/2;
starty = py+height/2;
bounce();
ellipse(startx,starty,15,15); //I did this so you have to click to make the puck move
rect(5,mouseY-30,12,60);
if((startx < 0) && (lives > 0)){
reset();
lives = lives - 1;
}
for(int i = 0; i<lives; i++){
ellipse(25+i*12,10,8,8);
}
if (lives <= 0){
background(255,0,0);
}
}
void mousePressed(){
if(lives > 0){
reset();
} else{
noLoop();
}
}
void reset(){
px = 0;
py = 0;
vx = random(-4,4);
vy = random(-4,4);
}
void bounce(){
if (((startx <= 23) && (starty <= mouseY+30) && (starty >+mouseY-30))
|| (startx >= width - 7)){
vx = -vx;
}
if ((starty <= 7) || (starty >= height - 7)){
vy = -vy;
}
}
0405 - Pong IV: Towards a simple game
Statement:
hide statement