2020/6/18 Week17
(1)part1:C/C++
複習、回顧、作業、分數
老師先介紹很多遊戲(都在moodle上)
game1:彈簧
nostroke為"沒有邊框"
多了line那行,兩顆球球連成一條線
右邊的球球可以隨意拉
新增5行程式碼,可讓右邊球球回彈
牛頓定理(甚麼微積分的...)
程式碼:
void setup(){size(300,300);
}
float x=200,y=150;
float vx=0,vy=0;
void draw(){
background(#002966);
stroke(#b7efff);
line(100,150,x,y);
fill(#b7efff);
noStroke();
ellipse(100,150,13,13);
ellipse(x,y,13,13);
if(!mousePressed){
float dx=x-100, dy=y-150;
float len=sqrt(dx*dx+dy*dy);
vx -= dx*(len-100)/len*0.001;
vy -= dy*(len-100)/len*0.001;
x += vx;//x -= dx*(len-100)/len*0.1;
y += vy;//y -= dy*(len-100)/len*0.1;
}
}
void mouseDragged(){
x=mouseX; y=mouseY;
}
game2:魚魚

程式碼
void setup(){
size(400,300);
}
float x=200,y=150;
void draw(){
background(#002966);
fill(255);
rect(x,y,80,20);
float dx=x-mouseX,dy=y-mouseY;
float len=sqrt(dx*dx+dy*dy);
x -= dx*0.1;
y -= dy*0.1;
}
-----------------------------學期結束------------------------------
沒有留言:
張貼留言