2023年11月23日 星期四

Doing Nothing Losing Life Week11

 Week11

今天要做一個用亂數隨機抽取座位的程式


用左手i(Y)右手j(X)的方式先劃出座位格子


填充顏色並加入文字,同時調整文字的位置


現在要把原本的Hello改為隨機變數
用一個for迴圈新增一個value,但目前的亂數還有個問題是數字有可能會重複


再來先不要做亂數,並且數字不重複,再來做兩數交換(用for迴圈來決定交換幾次)


再來要練習轉場,先準備好程式碼框架




新增文字,並按下滑鼠左鍵的時候state從0變成1


先在state==1的時候畫出兩個方塊


並設置過關條件(當灰色的方塊在按方向鍵右時x座標增加)當x座標達到300(白色方塊位置重合)時進到下一關state=2


設置t=100並在到state=2時開始t--,當t=0的時候回到state=0,讓這個程式能夠一直循環




練習拋物線的程式,先將圖片放入程式速寫本(還沒找到適合的圖片),並劃出一個圓形並填入橘色,並用line畫出線



滑鼠按下時設定籃球新的值,放開時開始飛行


設定新的boolean變數,放開時gameOver暫停

---------------------------------------------------------------------------------------------
void setup(){
  size(600,400);
  for(int i=0;i<4;i++){
    for(int j=0;j<6;j++){
      value[i][j] = i*6+j + 10;//先不做亂數,數字不重複
    }
  }
  for(int k=0;k<2;k++){
    int i=int(random(4)),j=int(random(6));
    int i2=int(random(4)),j2=int(random(6));
    int temp =value[i][j];
    value[i][j] = value[i2][j2];
    value[i2][j2] = temp;
   }
}
int [][] value = new int[4][6];
void draw(){
  background(255);
  for(int i=0;i<4;i++){//y
    for(int j=0;j<6;j++){//x
      fill(#F5B4B4) ;rect(j*100,i*100, 100,100);
      fill(0); text(value[i][j],j*100+25,i*100+50);
    }
  }
}

-----------------------------------------------------------------------------------------------------------------------------
int state = 0; //0; white, 1; red,2 blue
void setup(){
  size(400,400);
  textSize(50);
}
int x = 50, y = 50, t = 100;
void draw(){
  if(state==0){
    background(255);
    fill(0); text("Click to Start",70,200);
    x = 50;
  }else if(state==1){
    background(255,0,0);
    fill(255); rect(300,50,50,50);
    fill(128); rect(x,y,50,50);
    t = 100;
  }else if(state==2){
    background(0,0,255);
    fill(255,255,0); text("Wait " +t,90,200);
    t--;
    if(t==0) state =0;
  }
}
void mousePressed(){
  if(state==0) state=1;
}
void keyPressed(){
  if(state == 1 && keyCode == RIGHT){
    x+=10;
    if(x==300) state=2;
  }
}

-----------------------------------------------------------------------------------------------------------------------------
籃球機
PImage imgRack;
void setup(){
  size(800,800);
  imgRack = loadImage("rack.jpg");
}
void draw(){
  background(255);
  image(imgRack,0,0);
  if(flying){
    x += vx;
    y += vy;
    vy += 0.98;
  }else{
    x = mouseX;
    y = mouseY;
    if(mousePressed){
    fill(255); ellipse(posX,posY,20,20);
    line(posX,posY,x,y);
    }
  }
  fill(#FFA652); ellipse(x,y,20,20);
}
boolean flying = false;
float x,y,vx,vy;
float posX = -100, posY = -100;
void mousePressed(){
  x=posX = mouseX;
  y=posY = mouseY;
  flying = false;
}
void mouseReleased(){
  vx = posX-mouseX;
  vy = posY-mouseY;
  flying = true;
}













沒有留言:

張貼留言