220103 week15
💛🔔
期末作業的下半場
加入人物圖案
👉程式碼(主要更改部分為豆沙粉色 )
PShape obj;
PImage img;
PImage img2;
PImage img3;
void setup(){
size(600,500,P3D);///場景為3D
obj=loadShape("hand1.obj");
camera(0,-70,120,0,0,0,0,1,0);
img=loadImage("vs.png");
img2=loadImage("me.png");
img3=loadImage("no.png");
}
float boardX,boardY;
float x=0,y=0,z=0;
float vx=0,vy=0,vz=-0.2;
void draw(){
lights();//打光
background(112,146,190);
fill(34,177,76);//綠色
box(100,5,120);//綠色球桌
pushMatrix();
translate(0,-10,0);
fill(255,0,0);//紅色
box(98,20,5);//紅色網子
popMatrix();
pushMatrix();
translate(-40,35,50);
fill(#502C0F);//桌腳的顏色
box(10,70,10);//咖色桌腳
popMatrix();
pushMatrix();
translate(40,35,50);
fill(#502C0F);//桌腳的顏色
box(10,70,10);//咖色桌腳
popMatrix();
pushMatrix();
translate(-40,35,-50);
fill(#502C0F);//桌腳的顏色
box(10,70,10);//咖色桌腳
popMatrix();
pushMatrix();
translate(40,35,-50);
fill(#502C0F);//桌腳的顏色
box(10,70,10);//咖色桌腳
popMatrix();
lights();
fill(255);//球的顏色
float dx=(mouseX-width/2.0)/8.0-10 ,dy=(mouseY-height*0.9)/5.0+100;
pushMatrix();
translate(x,y,z);
lights();noStroke();sphere(5);
popMatrix();
//dx=mouseX-width/2;//mouseX;
//dy=mouseY-height/2;
pushMatrix();
//translate(boardX,-10,boardY);
translate(dx,-10,dy);
rotate(radians(180));
shape(obj,0,0);
stroke(0);//line(-50,0,+50,0);
popMatrix();
if(z<dy && z+vz>dy && dx-50<x && x<dx+50){
stroke(255,0,0);
vy=-vy;
}else stroke(0);
x+=vx; y+=vy; z+=vz;
vy+=0.98;
if(y>400){
vy=-vy;
}
if(z<-20) vz=-vz;
image(img,-70,-60,width/20,height/20);
image(img2,45,-60,width/20,height/20);
image(img3,60,-50,width/30,height/30);
}
己方的部分
己方的糯米糰子
對方的部分
宣傳圖的部分
對方自動偵測球的位置
👉程式碼
float pcX=150,pcVX=0;
void setup(){
size(300,400);
}
void draw(){
background(255);
pcVX=(mouseX-pcX);
if(pcVX>0 && pcVX>2)pcVX=2;
if(pcVX<0 && pcVX<-2)pcVX=-2;
pcX=pcX+pcVX;
ellipse(pcX,50,30,30);
ellipse(mouseX,mouseY,20,20);
}
放入對手球拍
👉程式碼(主要更改部分為豆沙粉色 )
PShape obj;
PShape obj2;
PImage img;
PImage img2;
PImage img3;
void setup(){
size(600,500,P3D);///場景為3D
obj=loadShape("hand1.obj");
obj2=loadShape("hand2.obj");
camera(0,-70,120,0,0,0,0,1,0);
img=loadImage("vs.png");
img2=loadImage("me.png");
img3=loadImage("no.png");
}
float boardX,boardY;
float x=0,y=0,z=0;
float vx=0,vy=0,vz=-0.2;
void draw(){
lights();//打光
background(112,146,190);
fill(34,177,76);//綠色
box(100,5,120);//綠色球桌
pushMatrix();
translate(0,-10,0);
fill(255,0,0);//紅色
box(98,20,5);//紅色網子
popMatrix();
pushMatrix();
translate(-40,35,50);
fill(#502C0F);//桌腳的顏色
box(10,70,10);//咖色桌腳
popMatrix();
pushMatrix();
translate(40,35,50);
fill(#502C0F);//桌腳的顏色
box(10,70,10);//咖色桌腳
popMatrix();
pushMatrix();
translate(-40,35,-50);
fill(#502C0F);//桌腳的顏色
box(10,70,10);//咖色桌腳
popMatrix();
pushMatrix();
translate(40,35,-50);
fill(#502C0F);//桌腳的顏色
box(10,70,10);//咖色桌腳
popMatrix();
lights();
fill(255);//球的顏色
float dx=(mouseX-width/2.0)/8.0-10 ,dy=(mouseY-height*0.9)/5.0+100;
pushMatrix();
translate(x,y,z);
lights();noStroke();sphere(5);
popMatrix();
//dx=mouseX-width/2;//mouseX;
//dy=mouseY-height/2;
pushMatrix();//正電paipai
//translate(boardX,-10,boardY);
translate(dx,-10,dy);
rotate(radians(180));
shape(obj,0,0);
stroke(0);//line(-50,0,+50,0);
popMatrix();
pushMatrix();//負電paipai
//translate(boardX,-10,boardY);
translate(10,-10,-50);
rotate(radians(180));
shape(obj2,0,0);
stroke(0);//line(-50,0,+50,0);
popMatrix();
if(z<dy && z+vz>dy && dx-50<x && x<dx+50){
stroke(255,0,0);
vy=-vy;
}else stroke(0);
x+=vx; y+=vy; z+=vz;
vy+=0.98;
if(y>2){
vy=-vy;
}
if(z<-20) vz=-vz;
image(img,-70,-60,width/20,height/20);
image(img2,45,-60,width/20,height/20);
image(img3,60,-50,width/30,height/30);
}
桌球對打
👉程式碼(主要更改部分為豆沙粉色 )
PShape obj;
PShape obj2;
PImage img;
PImage img2;
PImage img3;
void setup(){
size(600,500,P3D);///場景為3D
obj=loadShape("hand1.obj");
obj2=loadShape("hand2.obj");
camera(0,-70,120,0,0,0,0,1,0);
img=loadImage("vs.png");
img2=loadImage("me.png");
img3=loadImage("no.png");
}
float x=0,y=-25,z=0;//y為球上下高度
float vx=0,vy=0,vz=+0.2;///vz為前後
void draw(){
lights();//打光
background(112,146,190);
fill(34,177,76);//綠色
box(100,5,120);//綠色球桌
pushMatrix();
translate(0,-10,0);
fill(255,0,0);//紅色
box(98,20,5);//紅色網子
popMatrix();
pushMatrix();
translate(-40,35,50);
fill(#502C0F);//桌腳的顏色
box(10,70,10);//咖色桌腳
popMatrix();
pushMatrix();
translate(40,35,50);
fill(#502C0F);//桌腳的顏色
box(10,70,10);//咖色桌腳
popMatrix();
pushMatrix();
translate(-40,35,-50);
fill(#502C0F);//桌腳的顏色
box(10,70,10);//咖色桌腳
popMatrix();
pushMatrix();
translate(40,35,-50);
fill(#502C0F);//桌腳的顏色
box(10,70,10);//咖色桌腳
popMatrix();
lights();
fill(255);//球的顏色
float dx=(mouseX-width/2.5)/8.0-10 ,dy=(mouseY-height*0.9)/5.0+100;
pushMatrix();
translate(x,y,z);
lights();noStroke();sphere(3);
popMatrix();
pushMatrix();//正電paipai
//translate(boardX,-10,boardY);
translate(dx,-20,dy);//球拍高度//-20等於z軸
//box(10);
rotate(radians(180));
shape(obj,0,0);
stroke(0);
popMatrix();
pushMatrix();//負電paipai
translate(0,-20,-60);
rotate(radians(180));
shape(obj2,0,0);
stroke(0);//line(-50,0,+50,0);
popMatrix();
//if(z<dy && z+vz>dy && dx-50<x && x<dx+50 ){
if( dist( x,y,z, dx, -20, dy)<10 ){
//background(255,0,0);
vz = -vz;
}//else stroke(0);
x+=vx;
y+=vy; //上下
z+=vz;//前後
vy+=0.98;
//if(y>-10){
//vy=-vy;
//}
if(y>-10) vy=-vy*0.9;
if(x<0) vx=-vx;///反彈!
if(z<-20) vz=-vz;///對方的回彈
image(img,-70,-60,width/20,height/20);
image(img2,45,-60,width/20,height/20);
image(img3,60,-50,width/30,height/30);
}
程式碼可以參考2020程式設計2B-孤獨月宮的花園💁第七週-主題三:彈跳
https://2020cceb.blogspot.com/2020/04/blog-post_10.html
那麼這週先停在這裡
這週未完
1:對方球拍未能跟著球移動
下次進度安排
1:對手球拍自動偵測到球且跟著移動
2:讓球合乎反彈方向前進
3:其他進階功能
如果喜歡我的部落格的話
請幫我按右上角的愛心(根本按不下去)
也可以按右上角的小鈴鐺(這也按不下去)
才不會錯過我的更新哦!😉
沒有留言:
張貼留言