2014年6月29日 星期日

期末影片展示

PImage imgbackground;
float ballx=245, bally=350, ballvx=10, ballvy=-2,ball2x=245, ball2y=350, ball2vx=10, ball2vy=-2,ball3x=245, ball3y=350, ball3vx=10, ball3vy=-2;
float stick1x=150, stick2x=150;
float move;
int score_computer=0;
int score_user=0;
void setup() {
size(480, 800, P3D);
imgbackground = loadImage("background.jpg");
}
void draw() {
background(imgbackground);
move=int(random(30));
fill(255);
textFont(createFont("calibri",40));
textSize(30);
text(score_computer+":"+score_user, 230, 300);
if(move==0){
stick1x=40+int(random(320));
}
if(bally<=800 && bally>=0){
fill(255);
ellipse(ballx, bally, 40, 40);
}
else if(ball2y<=800 && ball2y>=0){
fill(255);
ellipse(ball2x, ball2y, 40, 40);
if(score_computer+score_user==0){
if(bally<=0) score_user++;
if(bally>=800) score_computer++;
}
}
else if(ball3y<=800 && ball3y>=0){
fill(255);
ellipse(ball3x, ball3y, 40, 40);
if(score_computer+score_user==1){
if(ball2y<=0) score_user++;
if(ball2y>=800) score_computer++;
}
}
else if(ball3y>=800 || ball3y<=0){
if(score_computer+score_user==2){
if(ball3y<=0) score_user++;
if(ball3y>=800) score_computer++;
}
if(score_user>score_computer){
fill(255);
textFont(createFont("calibri",40));
textSize(30);
text("you win!!", 200, 350);
}
else if(score_user<score_computer){
fill(255);
textFont(createFont("calibri",40));
textSize(30);
text("you lose!!", 230, 300);
}
}
fill(255, 0, 0);
rect(stick1x, 85, 100, 15);
rect(stick2x, 715, 100, 15);
update();
}
void update() {
if(bally<=800 && bally>=0){
ballx+=ballvx;
bally+=ballvy;
if (ballx<55||ballx>425) ballvx=-ballvx;
if (ballx>stick1x && ballx<stick1x+110 && bally<=120 && bally>=100 || bally<=120 && ballx>55 && ballx<90 || bally<=120 && ballx>395 && ballx<425)
ballvy=-ballvy;
if (ballx>stick2x && ballx<stick2x+110 && bally>=710 && bally<=720 || bally>=710 && ballx>55 && ballx<90 || bally>=680 && ballx>395 && ballx<425)
ballvy=-ballvy;
}
else if(bally>=800 && bally<=0 || ball2y<=800 && ball2y>=0){
ball2x+=ball2vx;
ball2y+=ball2vy;
if (ball2x<55||ball2x>425) ball2vx=-ball2vx;
if (ball2x>stick1x && ball2x<stick1x+110 && ball2y<=120 && ball2y>=100 || ball2y<=120 && ball2x>55 && ball2x<90 || ball2y<=120 && ball2x>395 && ball2x<425)
ball2vy=-ball2vy;
if (ball2x>stick2x && ball2x<stick2x+110 && ball2y>=710 && ball2y<=720 || ball2y>=710 && ball2x>55 && ball2x<90 || ball2y>=680 && ball2x>395 && ball2x<425)
ball2vy=-ball2vy;
}
else if(ball2y>=800 && ball2y<=0 || ball3y<=800 && ball3y>=0){
ball3x+=ball3vx;
ball3y+=ball3vy;
if (ball3x<55||ball3x>425) ball3vx=-ball3vx;
if (ball3x>stick1x && ball3x<stick1x+110 && ball3y<=120 && ball3y>=100 || ball3y<=120 && ball3x>55 && ball3x<90 || ball3y<=120 && ball3x>395 && ball3x<425)
ball3vy=-ball3vy;
if (ball3x>stick2x && ball3x<stick2x+110 && ball3y>=710 && ball3y<=720 || ball3y>=710 && ball3x>55 && ball3x<90 || ball3y>=680 && ball3x>395 && ball3x<425)
ball3vy=-ball3vy;
}
}
void mouseMoved() {
stick2x=mouseX-90;
}

沒有留言:

張貼留言