2014年5月19日 星期一

第十四週上課內容

PImage imgbackground;
float ballx=200, bally=300, ballvx=10, ballvy=-2;
float stick1x=150, stick2x=150;
void setup() {
size(480, 800, P3D);
imgbackground = loadImage("background.png");
}
void draw() {
background(imgbackground);
fill(255);
ellipse(ballx, bally, 40, 40);
fill(255, 0, 0);
rect(stick1x, 90, 150, 15);
rect(stick2x, 710, 150, 15);
update();
}
void update() {
ballx+=ballvx;
bally+=ballvy;
if (ballx<50||ballx>415) ballvx=-ballvx;
if (ballx>stick1x && ballx<stick1x+150 && bally<=90)
ballvy=-ballvy;
if (ballx>stick2x && ballx<stick2x+150 && bally>=710)
ballvy=-ballvy;
}
void mouseMoved() {
stick1x=mouseX-90;
stick2x=mouseX-90;
}


沒有留言:

張貼留言