Bounding Box se refere ao menor retângulo possível para conter todos os elementos possíveis de um conjunto. Nesse caso, cada conjunto vai ser apenas um elemento. O código resultante será:
int bastaoX=250;
int bolaX=10;
int dx=5;
int bolaY=10;
int dy=5;
int bx=150, by=300, tx=100, ty=10;
int fx=250, zy=500;
void setup() {
size(600, 800);
}
void draw() {
background(0);
rect(bastaoX, 580, 100, 10);
rect(bx, by, tx, ty);
rect(fx, zy, tx, ty);
if (keyPressed ==true && keyCode == RIGHT && bastaoX+100<width) {
bastaoX=bastaoX+5;
}
if (keyPressed ==true && keyCode == LEFT && bastaoX>=0) {
bastaoX=bastaoX-5;
}
ellipse(bolaX, bolaY, 20, 20);
bolaX+=dx;
bolaY+=dy;
if (bolaX+10>=590 || bolaX-10<=10) {
dx=-dx;
}
if (bolaY-10<=0) {
dy=-dy;
}
if (bolaY+10>=height) {// || bolaY<=10){
dy=-0;
dx=0;
text("Você perdeu", 300, 400);
}
if ((bolaX+10>=bx && bolaX-10<=bx+tx)) {
if ((bolaY+10>=by && bolaY-10<=by+ty)) {
text("Você venceu", 300, 400);
dx=0;
dy=0;
}
}
if ((bolaX+10>=fx && bolaX-10<=fx+tx)) {
if ((bolaY+10>=zy && bolaY-10<=zy+ty)) {
text("Você venceu", 300, 400);
dx=0;
dy=0;
}
}
if (bolaX-10>=bastaoX && bolaX+10<= bastaoX+100) {
if (bolaY+10>=580 && bolaY-2100<=600) {
dy=-dy;
}
}
}
No comments:
Post a Comment