2025年5月8日 星期四

week12 12750591

//week12_1_gundam_head_body_uparm1_upuparm_hand

//修改week09_2_gundam_head_body_push_trt_pop

//再加上week09_5_gundam_uparm1_upuparm_hand_keyboard_mouse_angle

PShape body, head;

PShape uparm1, upuparm1, hand1; //week09_5

void setup() {

  size(400, 400, P3D);

  body = loadShape("body.obj");

  head = loadShape("head.obj");

  uparm1 = loadShape("uparm1.obj"); //week09_5

  upuparm1 = loadShape("upuparm1.obj"); //week09_5

  hand1 = loadShape("hand1.obj"); //week09_5

}

void draw() {

  background(204);

  translate(200, 300);

  sphere(10); // 原點的球


  scale(10, -10, 10);

  

  shape(body, 0, 0);

  pushMatrix();

    translate(0, 22.5);

    rotateY(radians(mouseX-200));

    rotateX(radians(mouseY-60));

    translate(0, -22.5);

    shape(head, 0, 0);

  popMatrix();

  

  pushMatrix(); //左邊的手臂系列

      shape(upuparm1, 0, 0); // 上上手臂

  pushMatrix();

    translate(-4.1, 19.9); // 再掛回去原本的位置

    rotateZ(radians(mouseX));

    translate(4.1, -19.9); // 把物體的旋轉中心, 放到座標中心

    shape(uparm1, 0, 0); // 上手臂

    pushMatrix();

      translate(-4.5, +16.9);

      rotateX(radians(mouseY));

      translate(4.5, -16.9); // 剛剛把手移到座標中心的移動量

      //translate(mouseX/10.0, -mouseY/10.0); // 一邊移動、一邊找到數值

      //println(mouseX/10.0, -mouseY/10.0); // 印出適合的數值 ex. 4.5, -16.9

      shape(hand1, 0, 0);

    popMatrix();

  popMatrix();

  popMatrix();

}


//week12_2_gundam_head_body_uparm1_upuparm_hand
//修改week12_1_gundam_head_body_uparm1_upuparm_hand
//要加上float [] angleX = new float
PShape body, head;
PShape uparm1, upuparm1, hand1; //week09_5
void setup() {
  size(400, 400, P3D);
  body = loadShape("body.obj");
  head = loadShape("head.obj");
  uparm1 = loadShape("uparm1.obj"); //week09_5
  upuparm1 = loadShape("upuparm1.obj"); //week09_5
  hand1 = loadShape("hand1.obj"); //week09_5
}
float [] angleX = new float[10];
float [] angleY = new float[10];
int ID = 0; //0:頭, 1:上上手臂, 2:上手臂, 3:手
void mouseDragged(){
  angleX[ID] += radians(mouseX - pmouseX); //左右拖曳
  angleY[ID] += radians(mouseY - pmouseY); //上下拖曳
}
void draw() {
  background(204);
  translate(200, 300);
  sphere(10); // 原點的球

  scale(10, -10, 10);
  
  shape(body, 0, 0);
  pushMatrix();
    translate(0, 22.5);
    rotateY(angleX[0]); //x方向 左右拖曳,是對Y軸轉
    rotateX(angleY[0]); //y方向 上下拖曳,是對X軸轉
    translate(0, -22.5);
    shape(head, 0, 0);
  popMatrix();
  
  pushMatrix(); //左邊的手臂系列
      shape(upuparm1, 0, 0); // 上上手臂
  pushMatrix();
    translate(-4.1, 19.9); // 再掛回去原本的位置
    //rotateZ(radians(mouseX));
    rotateZ(angleY[2]);
    rotateY(angleX[2]);
    translate(4.1, -19.9); // 把物體的旋轉中心, 放到座標中心
    shape(uparm1, 0, 0); // 上手臂
    pushMatrix();
        translate(-4.5, +16.9);
        //rotateX(radians(mouseY));
        rotateZ(angleY[3]);
        rotateY(angleX[3]);
        translate(4.5, -16.9); // 剛剛把手移到座標中心的移動量
        //translate(mouseX/10.0, -mouseY/10.0); // 一邊移動、一邊找到數值
        //println(mouseX/10.0, -mouseY/10.0); // 印出適合的數值 ex. 4.5, -16.9
        shape(hand1, 0, 0);
      popMatrix();
    popMatrix();
  popMatrix();
}


//week12_3_gundam_head_body_left_keyPressed_ID
//修改week12_2_gundam_head_body_uparm1_upuparm_hand
//要加上float [] angleX = new float
PShape body, head;
PShape uparm1, upuparm1, hand1; //week09_5
void setup() {
  size(400, 400, P3D);
  body = loadShape("body.obj");
  head = loadShape("head.obj");
  uparm1 = loadShape("uparm1.obj"); //week09_5
  upuparm1 = loadShape("upuparm1.obj"); //week09_5
  hand1 = loadShape("hand1.obj"); //week09_5
}
float [] angleX = new float[10];
float [] angleY = new float[10];
int ID = 0; //0:頭, 1:上上手臂, 2:上手臂, 3:手
void mouseDragged(){
  angleX[ID] += radians(mouseX - pmouseX); //左右拖曳
  angleY[ID] += radians(mouseY - pmouseY); //上下拖曳
}
void keyPressed(){ //小心,注音輸入法會把1變成bo
  if(key=='1') ID = 1;
  if(key=='2') ID = 2;
  if(key=='3') ID = 3;
  if(key=='4') ID = 4;
  if(key=='5') ID = 5;
  if(key=='6') ID = 6;
  if(key=='7') ID = 7;
  if(key=='8') ID = 8;
  if(key=='9') ID = 9;
  if(key=='0') ID = 0;
}
void draw() {
  background(204);
  translate(200, 300);
  sphere(10); // 原點的球

  scale(10, -10, 10);
  
  shape(body, 0, 0);
  pushMatrix();
    translate(0, 22.5);
    rotateY(angleX[0]); //x方向 左右拖曳,是對Y軸轉
    rotateX(angleY[0]); //y方向 上下拖曳,是對X軸轉
    translate(0, -22.5);
    shape(head, 0, 0);
  popMatrix();
  
  pushMatrix(); //左邊的手臂系列
      shape(upuparm1, 0, 0); // 上上手臂
  pushMatrix();
    translate(-4.1, 19.9); // 再掛回去原本的位置
    //rotateZ(radians(mouseX));
    rotateZ(angleY[2]);
    rotateY(angleX[2]);
    translate(4.1, -19.9); // 把物體的旋轉中心, 放到座標中心
    shape(uparm1, 0, 0); // 上手臂
    pushMatrix();
        translate(-4.5, +16.9);
        //rotateX(radians(mouseY));
        rotateX(angleY[3]);
        rotateY(angleX[3]);
        translate(4.5, -16.9); // 剛剛把手移到座標中心的移動量
        //translate(mouseX/10.0, -mouseY/10.0); // 一邊移動、一邊找到數值
        //println(mouseX/10.0, -mouseY/10.0); // 印出適合的數值 ex. 4.5, -16.9
        shape(hand1, 0, 0);
      popMatrix();
    popMatrix();
  popMatrix();
}

//week12_4_gundam_head_body_push_try_pop_again
//修改week12_2_gundam_head_body_uparm1_upuparm_hand
//要加上float [] angleX = new float
PShape body, head;
PShape uparm1, upuparm1, hand1; //week09_5
void setup() {
  size(400, 400, P3D);
  body = loadShape("body.obj");
  head = loadShape("head.obj");
  uparm1 = loadShape("uparm1.obj"); //week09_5
  upuparm1 = loadShape("upuparm1.obj"); //week09_5
  hand1 = loadShape("hand1.obj"); //week09_5
}
float [] angleX = new float[10];
float [] angleY = new float[10];
int ID = 0; //0:頭, 1:上上手臂, 2:上手臂, 3:手
void mouseDragged(){
  angleX[ID] += radians(mouseX - pmouseX); //左右拖曳
  angleY[ID] += radians(mouseY - pmouseY); //上下拖曳
}
void keyPressed(){ //小心,注音輸入法會把1變成bo
  if(key=='1') ID = 1;
  if(key=='2') ID = 2;
  if(key=='3') ID = 3;
  if(key=='4') ID = 4;
  if(key=='5') ID = 5;
  if(key=='6') ID = 6;
  if(key=='7') ID = 7;
  if(key=='8') ID = 8;
  if(key=='9') ID = 9;
  if(key=='0') ID = 0;
}
void draw() {
  background(204);
  translate(200, 300);
  sphere(10); // 原點的球

  scale(10, -10, 10);
  
  shape(body, 0, 0);
  pushMatrix();
    translate(0, 22.5);
    rotateY(angleX[0]); //x方向 左右拖曳,是對Y軸轉
    rotateX(angleY[0]); //y方向 上下拖曳,是對X軸轉
    translate(0, -22.5);
    shape(head, 0, 0);
  popMatrix();
  
  pushMatrix(); //左邊的手臂系列
    translate(-2.9, 20.8);
    rotateY(angleX[1]);
    rotateX(angleY[1]);
    translate(2.9, -20.8);
    //translate(mouseX/10.0,-mouseY/10.0);
    //println(mouseX/10.0,-mouseY/10.0);
    shape(upuparm1, 0, 0); // 上上手臂
  pushMatrix();
    translate(-4.1, 19.9); // 再掛回去原本的位置
    //rotateZ(radians(mouseX));
    rotateZ(angleY[2]);
    rotateY(angleX[2]);
    translate(4.1, -19.9); // 把物體的旋轉中心, 放到座標中心
    shape(uparm1, 0, 0); // 上手臂
    pushMatrix();
        translate(-4.5, +16.9);
        //rotateX(radians(mouseY));
        rotateX(angleY[3]);
        rotateY(angleX[3]);
        translate(4.5, -16.9); // 剛剛把手移到座標中心的移動量
        //translate(mouseX/10.0, -mouseY/10.0); // 一邊移動、一邊找到數值
        //println(mouseX/10.0, -mouseY/10.0); // 印出適合的數值 ex. 4.5, -16.9
        shape(hand1, 0, 0);
      popMatrix();
    popMatrix();
  popMatrix();
}


//week12_5_gundam_left_cope_right
//修改week12_4_gundam_head_body_push_try_pop_again
//PShape宣告要複製,要改成2
//void setup()裡,也要複製loadShape裡面也要改成2
//void draw()裡,也要複製整組TRT,右半邊裡1變成2
PShape body, head;
PShape uparm1, upuparm1, hand1;  //week09_5
PShape uparm2, upuparm2, hand2; //week12_5
void setup() {
  size(400, 400, P3D);
  body = loadShape("body.obj");
  head = loadShape("head.obj");
  uparm1 = loadShape("uparm1.obj"); //week09_5
  upuparm1 = loadShape("upuparm1.obj"); //week09_5
  hand1 = loadShape("hand1.obj"); //week09_5
  uparm2 = loadShape("uparm2.obj"); //week12_5
  upuparm2 = loadShape("upuparm2.obj"); //week12_5
  hand2 = loadShape("hand2.obj"); //week12_5
}
float [] angleX = new float[10];
float [] angleY = new float[10];
int ID = 0; //0:頭, 1:上上手臂, 2:上手臂, 3:手
void mouseDragged(){
  angleX[ID] += radians(mouseX - pmouseX); //左右拖曳
  angleY[ID] += radians(mouseY - pmouseY); //上下拖曳
}
void keyPressed(){ //小心,注音輸入法會把1變成bo
  if(key=='1') ID = 1;
  if(key=='2') ID = 2;
  if(key=='3') ID = 3;
  if(key=='4') ID = 4;
  if(key=='5') ID = 5;
  if(key=='6') ID = 6;
  if(key=='7') ID = 7;
  if(key=='8') ID = 8;
  if(key=='9') ID = 9;
  if(key=='0') ID = 0;
}
void draw() {
  background(204);
  translate(200, 300);
  sphere(10); // 原點的球

  scale(10, -10, 10);
  
  shape(body, 0, 0);
  pushMatrix();
    translate(0, 22.5);
    rotateY(angleX[0]); //x方向 左右拖曳,是對Y軸轉
    rotateX(angleY[0]); //y方向 上下拖曳,是對X軸轉
    translate(0, -22.5);
    shape(head, 0, 0);
  popMatrix();
  
  pushMatrix(); //左邊的手臂系列
    translate(-2.9, 20.8);
    rotateY(angleX[1]);
    rotateX(angleY[1]);
    translate(2.9, -20.8);
    //translate(mouseX/10.0,-mouseY/10.0);
    //println(mouseX/10.0,-mouseY/10.0);
    shape(upuparm1, 0, 0); // 上上手臂
  pushMatrix();
    translate(-4.1, 19.9); // 再掛回去原本的位置
    //rotateZ(radians(mouseX));
    rotateZ(angleY[2]);
    rotateY(angleX[2]);
    translate(4.1, -19.9); // 把物體的旋轉中心, 放到座標中心
    shape(uparm1, 0, 0); // 上手臂
    pushMatrix();
        translate(-4.5, +16.9);
        //rotateX(radians(mouseY));
        rotateX(angleY[3]);
        rotateY(angleX[3]);
        translate(4.5, -16.9); // 剛剛把手移到座標中心的移動量
        //translate(mouseX/10.0, -mouseY/10.0); // 一邊移動、一邊找到數值
        //println(mouseX/10.0, -mouseY/10.0); // 印出適合的數值 ex. 4.5, -16.9
        shape(hand1, 0, 0);
      popMatrix();
    popMatrix();
  popMatrix();
  
    pushMatrix(); //右邊的手臂系列
    translate(+2.9, 20.8);
    rotateY(angleX[4]);
    rotateX(angleY[4]);
    translate(-2.9, -20.8);
    //translate(mouseX/10.0,-mouseY/10.0);
    //println(mouseX/10.0,-mouseY/10.0);
    shape(upuparm2, 0, 0); // 上上手臂
  pushMatrix();
    translate(+4.1, 19.9); // 再掛回去原本的位置
    //rotateZ(radians(mouseX));
    rotateZ(angleY[5]);
    rotateY(angleX[5]);
    translate(-4.1, -19.9); // 把物體的旋轉中心, 放到座標中心
    shape(uparm2, 0, 0); // 上手臂
    pushMatrix();
        translate(+4.5, +16.9);
        //rotateX(radians(mouseY));
        rotateX(angleY[6]);
        rotateY(angleX[6]);
        translate(-4.5, -16.9); // 剛剛把手移到座標中心的移動量
        //translate(mouseX/10.0, -mouseY/10.0); // 一邊移動、一邊找到數值
        //println(mouseX/10.0, -mouseY/10.0); // 印出適合的數值 ex. 4.5, -16.9
        shape(hand2, 0, 0);
      popMatrix();
    popMatrix();
  popMatrix();
}


//week12_6_sound
//要有聲音,需要聲音library函式庫
//Sketch - Library - managed Libraries找sound
//會看到Sound | provides a simple way to work with audio
//選他,右下角Install下載安裝
//安裝好Sound後,會看到file-Examples點開Library核心函式庫
//Soundfile 那堆範例看SimplePlayBack簡單播放音樂
import processing.sound.*; //抄範例
SoundFile mySound; //抄範例,改檔名
void setup(){
 size(400,400);
 mySound = new SoundFile(this, "music.mp3");
 mySound.play();
}
void draw(){
  
}




//week12_7_sound_intro_ingame_sword_monkey
import processing.sound.*;
SoundFile sndInGame, sndIntro, sndMonkey, sndSword;
void setup(){
 size(400,400);
 sndInGame = new SoundFile(this, "In Game Music.mp3");
 sndIntro = new SoundFile(this, "Intro Song_Final.mp3");
 sndMonkey = new SoundFile(this, "Monkey 1.mp3");
 sndSword = new SoundFile(this, "sword slash.mp3");
 sndIntro.play(); //開場簡介的音樂
}
boolean playingIntro = true;
void keyPressed(){  //按下空白鍵會進入音樂
  if(playingIntro){  //若在撥開場簡介
  sndIntro.stop();  //開場簡介音樂stop
  sndInGame.play();  //進入遊戲關卡的音樂play
  playingIntro = false;  //現在沒播開場簡介
  }else{  //若沒播開場簡介
  sndInGame.stop();
  sndIntro.play();
  playingIntro = true;
  }
}
void mousePressed(){
 if(mouseButton==LEFT) sndSword.play();
 if(mouseButton==RIGHT) sndMonkey.play();
}
void draw(){
  
}






沒有留言:

張貼留言