2019年10月31日 星期四

week08

這週練習函式可以自己加個class,
開始前先打出變數移動的圓形,再把物件加進去,
用的是猜杯子的遊戲














新增Cup自定class
class Cup{
  PVector pos;
  PVector v;
  boolean coin=false;
  Cup(float x,float y){
  pos =new PVector(x,y);
  v= new PVector(random(4),random(3));
  }
  void draw(){
    pos.add(v);
    if(pos.x<0 || pos.x>400) v.x*=-1;
    if(pos.y<0 || pos.y>300) v.y*=-1;
    fill(255);
    ellipse(pos.x,pos.y,90,60);
  }
}
畫硬幣
void draw(){
  background(255);
  for(int i=0;i<3;i++){
    cup[i].draw();
    if(mousePressed && cup[i].coin==true){
    fill(255,255,0);
    ellipse(cup[i].pos.x,cup[i].pos.y,30,30);
  }
  }
}
顯示3個杯子並加上布林判斷金幣的顯示
Cup[] cup=new Cup[3];
int guess;
void setup(){
  size(400,300);
  for(int i=0;i<3;i++)
  {
    cup[i]=new Cup(100+i*100,100);
  }
  guess=int(random(3));
  cup[guess].coin=true;
}


沒有留言:

張貼留言

alanhc 互動技術-week17 [final]

回顧這學期的作品:  期中作業:LANDING:PLANET 賣點&特點: 炫麗的特效 物理(星球重力及降落)及粒子系統(噴射) 世界地圖可根據視角縮放 困難點: 重寫3次最終改寫成物件導向的CLASS寫法...