2021年12月27日 星期一

岩壁悲歌 Week09

 2021/12/6

----------------------------------------

小葉老師在協助同學期末作品







砍樹人



int []tree = new int[30];

int pos=0;

void setup(){

  size(300,600);

  tree[0]=0;

  for(int i=1;i<30;i++){

    tree[i]=int(random(3));

  }

}

void draw(){

  if(gameOver){

    background(255,0,0); return;

  }

  background(255,0,255);

  for(int i=0;i<30;i++){

    if(tree[i]==0){

      fill(#28C3E8);  rect(100,500-i*100,100,100);

    }else if(tree[i]==1){

      fill(#28C3E8);  rect(0,500-i*100,200,100);

    }else if(tree[i]==2){

      fill(#28C3E8);  rect(100,500-i*100,200,100);

    }

  }

  if(pos==0){

    fill(255,0,0);  ellipse(50,550,100,100);

  }else if(pos==1){

    fill(255,0,0);  ellipse(250,550,100,100);

  }

}

void keyPressed(){

  if(keyCode==RIGHT){ pos=1;  checkAndUpdate();}

  if(keyCode==LEFT){  pos=0;  checkAndUpdate();}

}

void checkAndUpdate(){

  if(tree[1]==1&&pos==0) die();

  else if(tree[1]==2&&pos==1)  die();

  else {

    //score++;

    for(int i=0;i<30-1;i++){

      tree[i] = tree[i+1];

    }

    tree[29]=int(random(3));

  }

}

void die(){

  gameOver=true;

}

boolean gameOver=false;

----------------------------------------------------







123木頭人




void setup(){

  size(600,300,P3D);  

  noStroke();

  genRandomTime();

}

void genRandomTime(){

  time = millis()+random(3000,5000);

}

float time=0;

float angle=-90;

float speed=3;

void draw(){

  background(#FFD436);

  if(time<millis()){

    //ghostMoving=true;

    angle+=speed;

    if(angle>=90){

      angle=90;

      time=millis()+3000;

      speed=-speed;

    }else if(angle<-90){

      angle=-90;

      genRandomTime();

      speed=10;

    }

  }

  ghost(angle);

}

void ghost(float angle){

  fill(237,137,63);

  rect(100,100,100,100);

  pushMatrix();      

    lights();  ortho();

    translate(150,50);

    rotateY(radians(angle));

    

    fill(190,162,95);   

    sphere(50);

    pushMatrix();

      translate(40,-10,40);

      fill(0); sphere(10);

    popMatrix();

    pushMatrix();

      translate(-40,-10,40);

      fill(0); sphere(10);

    popMatrix();

  popMatrix();

}

-----------------------------------------------------------------


小朋友下樓梯







PImage imgBrick,imgBoard01;

float []boardX=new float[9];

float []boardY=new float[9];

void setup(){

  size(600,400);

  imgBrick=loadImage("brick.png");

  imgBoard01 = loadImage("board01.png");

  for(int i=0;i<9;i++){

    boardX[i]=random(15,400-15-80);

    boardY[i]=i*40;

  }

}

float rolling=0;

float brickShift=0;

void draw(){

  rect(10,80,400,320);

  for(int i=0;i<30;i++){

    image(imgBrick,10,80+i*27-rolling);

    image(imgBrick,400+10-13,80+i*27-rolling);

  }

  for(int i=0;i<9;i++){

    image(imgBoard01,boardX[i],80+boardY[i]-rolling);

    if(boardY[i]-rolling<0){

      boardX[i]=random(15,400-15-80);

      boardY[i]=boardY[i]+360;

    }

  }

  rolling+=1.5;

}

---------------------------------------------------------


小雞過馬路








int chinkID=0;

float []chinkX=new float[10];

float []chinkY=new float[10];

float []chinkVX=new float[10];

float []chinkVY=new float[10];

boolean [] run=new boolean[10];

void setup(){

  size(400,300);

  for(int i=0;i<10;i++){

    chinkX[i]=random(10,150-10);

    chinkY[i]=random(10,300-10);

    chinkVX[i]=random(-1,1);

    chinkVY[i]=random(-1,1);

  }

}

void draw(){

  background(122,171,185);

  fill(102,166,28);

  rect(0,0,150,300);

  for(int i=0;i<10;i++){

    if(chinkID==i)  strokeWeight(3);

    else strokeWeight(1);

    fill(255); ellipse(chinkX[i],chinkY[i],20,50);

    chinkX[i]+=chinkVX[i];

    chinkY[i]+=chinkVY[i];

    if(chinkY[i]<0)  chinkVY[i]=abs(chinkVY[i]);

    if(chinkY[i]>300)  chinkVY[i]=-abs(chinkVY[i]);

    if(chinkX[i]<0)  chinkVX[i]=abs(chinkVX[i]);

    if(run[i]==false&&chinkX[i]>150)  chinkVX[i]=-abs(chinkVX[i]);

  }

}

void keyPressed(){

  int i=chinkID;

  if(keyCode==RIGHT)  {chinkVX[i]=1;  chinkVY[i]=0;}

  else if(keyCode==LEFT)  {chinkVX[i]=-1;  chinkVY[i]=0;}

  else if(keyCode==UP)  {chinkVX[i]=0;  chinkVY[i]=-1;}

  else if(keyCode==DOWN)  {chinkVX[i]=0;  chinkVY[i]=1;}

  run[i]=true;

}

void mousePressed(){

  for(int i=0;i<10;i++){

    if(dist(mouseX,mouseY,chinkX[i],chinkY[i])<20) chinkID=i;

  }

}

---------------------------------------------------------



俄羅斯方塊







int[][]grid={

  {1,1,1,1,1,1,1,1,1,1,1,1},

  {1,0,0,0,0,0,0,0,0,0,0,1},

  {1,0,0,0,0,0,0,0,0,0,0,1},

  {1,0,0,0,0,0,0,0,0,0,0,1},

  {1,0,0,0,0,0,0,0,0,0,0,1},

  {1,0,0,0,0,0,0,0,0,0,0,1},

  {1,0,0,0,0,0,0,0,0,0,0,1},

  {1,0,0,0,0,0,0,0,0,0,0,1},

  {1,0,0,0,0,0,0,0,0,0,0,1},

  {1,0,0,0,0,0,0,0,0,0,0,1},

  {1,0,0,0,0,0,0,0,0,0,0,1},

  {1,0,0,0,0,0,0,0,0,0,0,1},

  {1,0,0,0,0,0,0,0,0,0,0,1},

  {1,0,0,0,0,0,0,0,0,0,0,1},

  {1,0,0,0,0,0,0,0,0,0,0,1},

  {1,0,0,0,0,0,0,0,0,0,0,1},

  {1,0,0,0,0,0,0,0,0,0,0,1},

  {1,0,0,0,0,0,0,0,0,0,0,1},

  {1,0,0,0,0,0,0,0,0,0,0,1},

  {1,1,1,1,1,1,1,1,1,1,1,1}

};

void one(int x,int y){

  fill(255,0,0);

  if(grid[y][x]==0)  rect(x*25,y*25,25,25);  

}

boolean Lsafe(int x,int y){

  if(grid[y][x]==0&&grid[y+1][x]==0&&grid[y+2][x]==0&&grid[y+2][x+1]==0)  return true;

  return false;

}

void L(int x,int y){

  fill(255,0,0);

  if(Lsafe(x,y)){

    rect(x*25,y*25,25,25);

    rect(x*25,(y+1)*25,25,25);

    rect(x*25,(y+2)*25,25,25);

    rect((x+1)*25,(y+2)*25,25,25);

  }

}

void setup(){

  size(300,500);

}

void draw(){

  background(0);

  for(int x=0;x<12;x++){

    for(int y=0;y<20;y++){

      if(grid[y][x]==1)  fill(128);

      else if(grid[y][x]==2)  fill(250,128,124);

      else if(grid[y][x]==3)  fill(255,0,0);

      else  fill(0);

      rect(x*25,y*25,25,25);

    }

  }

  L(nowX,nowY);

  if(frameCount%20==0){

    if(Lsafe(nowX,nowY+1))  nowY++;

    else{

      grid[nowY][nowX]=3;

      grid[nowY+1][nowX]=3;

      grid[nowY+2][nowX]=3;

      grid[nowY+2][nowX+1]=3;

      nowX=6; nowY=1;

    }

    /*if(grid[nowY+1][nowX]==0)  nowY++;

    else{

      grid[nowY][nowX]=2;

      nowX=6; nowY=1;

    }*/

  }

}

int nowX=6,nowY=1;

沒有留言:

張貼留言