2021年12月20日 星期一

我出一百萬

 Week15---期末作品___123木頭人👈











主角小雞出現🐤🐥🐥🐥🐤(紅色是新加的程式碼)

///一二三木頭人, 3D

PImage img;

PImage img1;

void setup(){

  img = loadImage("1.jpeg");

  //background(img);

  size(1600,400,P3D);//OpenGL

  noStroke();

  genRandomTime();

  imageMode(CORNER);

}

void genRandomTime(){

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

}

float time=0;

float angle=-90;

float speed=3;

float vx=0;

int a=0, b=0, x=1450, y=200;

void draw(){

  background(img);

  img1=loadImage("G.png");

  x+=vx;

  if(time < millis() ){//animation鬼要動了!!!

    //ghostMoving=true;

    angle+=speed;

    if(angle>=90){//鬼在看你

      angle=90;

      time = millis()+3000;//rest

      speed = -speed;

    }else if(angle<-90){

      angle=-90;

      genRandomTime();

      speed=3;

    }

  }

  ghost(angle);//鬼要看的角度:-90背對沒看,90看到你 

  image( img1.get(80*a, 100*b, 80,100), x, y);

  if(frameCount%30==0) a = (a+1)%3;

}

void ghost(float angle){

  fill(237,137,63);

  rect(100,200,100,100);//吊帶褲

  fill(252,254,4);

  rect(100,200,100,30);//衣服

  fill(237,137,63);

  rect(120,200,20,30);//吊帶

  fill(235,218,171);

  rect(150,220,18,50);//手

  fill(243,233,185);

  circle(159, 273, 25);//拳頭

  fill(243,233,185);

  rect(153,300,25,50);//左腿

  fill(243,249,230);

  rect(152,330,27,50);//襪子

  fill(0);

  rect(150,370,30,20);//鞋子

  fill(243,233,185);

  rect(120,300,25,50);//右腿

  fill(243,249,230);

  rect(118,330,27,50);//襪子

  fill(0);

  rect(116,370,30,20);//鞋子

  fill(108,54,0);

  rect(0,80,60,300);//樹

  fill(122,143,58);

  circle(20, 50, 180);//葉子

  pushMatrix();

    lights(); ortho();

    translate(150,150);//把整個會轉的頭,移到身體上

    rotateY(radians(angle));

    fill(246,224,154);//head

    sphere(50);//大頭

    pushMatrix();

      translate(40,-10,50);

      fill(0); sphere(10);//黑色的右眼👀

    popMatrix();

    pushMatrix();

      translate(-40,-10,50);

      fill(0); sphere(10);//黑色的左眼👀

      popMatrix();  

  popMatrix();

}

void keyPressed(){

  if(keyCode==LEFT) vx=-1;

  if(keyCode==UP) { b=1; y--; }

  if(keyCode==DOWN){ b=0; y++; }

}

void keyReleased(){

  if(keyCode==LEFT) vx=0;

}




///一二三木頭人, 3D

PImage img;

PImage img1;

void setup(){

  img = loadImage("1.jpeg");

  size(1600,400,P3D);//OpenGL

  noStroke();

  genRandomTime();

  imageMode(CORNER);

}

void genRandomTime(){

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

}

float time=0;

float angle=-90;

float speed=3;

float vx=0;

int a=0, b=0, x=1450, y=200;

//int T=0;

boolean Die=false;

void draw(){

  background(img);

  if(Die) 

  {

    background(255,0,0);

    textSize(80);//(4)放大字

    text("GameOver", 800, 200);//(1)一開始字的fill填充色彩 白

    rotate(90);

  }

  img1=loadImage("G.png");

  x+=vx;

  //if(T>0){

    //T--;

    //angle-=90/60.0;

    //if(T==0){

     // if(testMoving()) Die=true;

   // }

//}

  if(time < millis() ){//animation鬼要動了!!!

    //ghostMoving=true;

    angle+=speed;

    if(angle>=90){//鬼在看你

      angle=90;

      if(testMoving()) Die=true;

      time = millis()+3000;//rest

      speed = -speed;

    }else if(angle<-90){

      angle=-90;

      genRandomTime();

      speed=3;

    }

  }

  ghost(angle);//鬼要看的角度:-90背對沒看,90看到你 

  image( img1.get(80*a, 100*b, 80,100), x, y);

  if(frameCount%30==0) a = (a+1)%3;

}

void ghost(float angle){

  fill(237,137,63);

  rect(100,200,100,100);//吊帶褲

  fill(252,254,4);

  rect(100,200,100,30);//衣服

  fill(237,137,63);

  rect(120,200,20,30);//吊帶

  fill(235,218,171);

  rect(150,220,18,50);//手

  fill(243,233,185);

  circle(159, 273, 25);//拳頭

  fill(243,233,185);

  rect(153,300,25,50);//左腿

  fill(243,249,230);

  rect(152,330,27,50);//襪子

  fill(0);

  rect(150,370,30,20);//鞋子

  fill(243,233,185);

  rect(120,300,25,50);//右腿

  fill(243,249,230);

  rect(118,330,27,50);//襪子

  fill(0);

  rect(116,370,30,20);//鞋子

  fill(108,54,0);

  rect(0,80,60,300);//樹

  fill(122,143,58);

  circle(20, 50, 180);//葉子

  pushMatrix();

    lights(); ortho();

    translate(150,150);//把整個會轉的頭,移到身體上

    rotateY(radians(angle));

    fill(246,224,154);//head

    sphere(50);//大頭

    pushMatrix();

      translate(40,-10,50);

      fill(0); sphere(10);//黑色的右眼👀

    popMatrix();

    pushMatrix();

      translate(-40,-10,50);

      fill(0); sphere(10);//黑色的左眼👀

      popMatrix();  

  popMatrix();

}

boolean testMoving(){

  if(vx==0) return false;

  else return true;

}

void keyPressed(){

  if(keyCode==LEFT) vx=-1;

  if(keyCode==UP) { b=1; y--; }///向上飛

  if(keyCode==DOWN){ b=0; y++; }///向下走

}

void keyReleased(){

  if(keyCode==LEFT) vx=0;

}


沒有留言:

張貼留言