顯示具有 Week19 標籤的文章。 顯示所有文章
顯示具有 Week19 標籤的文章。 顯示所有文章

2018年1月24日 星期三

WEEK19_電子三乙_04370316_杜東瀛的期末作品


這是期末作品的成品,花了我非常多的心血,他可以用手機或是電腦進行控制,可以在遙遠的地方透過網路控制冰箱的溫度。
這是期末作品的影片。
這是期末作品的程式碼。



2018年1月23日 星期二

18/01/23 德宇的筆記Week19

目標一:期末作品展示


組員:
04160790 陸德宇
04160303 謝紹勳


原遊戲參考:
http://anan.game.tw/ettc/6263.html


遊戲玩法:
本遊戲中間的紅球為主角,可以發射雪球攻擊敵人,敵人則會衝撞主角扣血。
在血歸零前則到100分,則獲勝。若歸零未達到分數則失敗


本遊戲操控方法如下
上鍵: 向前
下鍵: 向後
右鍵: 順時針
左鍵 逆時針
空白鍵: 發射雪球


實體成品:
概念啟發至7、8年級生小時候的紅白機,也意味著遊戲即便簡單,但也能很有趣的發想。




























展示影片:

Week19-期末作品-貓抓老鼠

https://youtu.be/DlcrJJDFHKY

week19



03160153 顏其威 自己一個人一組

2018年1月22日 星期一

week19 3D的互動期末作品展示



組員:顏士傑04160560

主題:猴子射氣球(塔防)

說明:這遊戲是一個利用放置猴子來攻擊,阻止氣球通過的遊戲,
這次期末作品是利用搖桿來控制鼠標,通過搖桿可以移動加按壓,
模擬滑鼠的移動以及左鍵,製造即使是用搖桿也可以玩以前用滑鼠玩的遊戲,
並且我加以改良了遊戲內容,設置出2個關卡,並且加入金錢、生命制度,
玩家必須有50元才能放置一隻猴子,當氣球成功通過道路,就會從3條生命中扣除。

展示影片:https://www.youtube.com/watch?v=6_DWKtj_wao

Week19 期末作品

作品名稱:桌上曲棍球


week19





Week19




Week19 是賴小沫的_期末作品

✎期末作品展示

👀程式碼

Arduino

const int finish = A0;
const int hole1 = A1;
const int hole2 = A2;
const int hole3 = A3;
const int hole4 = A4;
const int hole5 = A5;
const int start = A6;

int finishValue = 0;
int hole1Value = 0;
int hole2Value = 0;
int hole3Value = 0;
int hole4Value = 0;
int hole5Value = 0;
int startValue = 0;

void setup() {
  Serial.begin(9600);
}

void loop() {
  // Read the sensors first:
  finishValue = analogRead(finish)/50;
  hole1Value = analogRead(hole1)/50; 
  hole2Value = analogRead(hole2)/50;
  hole3Value = analogRead(hole3)/50;
  hole4Value = analogRead(hole4)/50;
  hole5Value = analogRead(hole5)/50;
  startValue = analogRead(start)/50;

  //用來判斷光敏電阻的門檻值
  /*Serial.println(finishValue);
  Serial.println(hole1Value);
  Serial.println(hole2Value);
  Serial.println(hole3Value);
  Serial.println(hole4Value);
  Serial.println(hole5Value);
  Serial.println(startValue);
  Serial.println(" ");*/

 
  if(finishValue<4) Serial.println("f");
  if(hole1Value<4) Serial.println("a");
  if(hole2Value<4) Serial.println("b");
  if(hole3Value<4) Serial.println("c");
  if(hole4Value<4) Serial.println("d");
  if(hole5Value<4) Serial.println("e");
  if(startValue>10) Serial.println("s");
  if(startValue<6) Serial.println("r");
  delay(50);
}

processing
//music
import ddf.minim.*;
Minim minim;
AudioPlayer player;

//devices
import processing.serial.*;
Serial myPort;
int val;

PImage h1,h2,h3,h4,h5,finish;
int state=0,count=0;
float time=0;
boolean game=false;

void setup(){
  size(600,800);
  //播放音樂
  minim=new Minim(this);
  player=minim.loadFile("music.mp3",2048);
  player.play();
  player.loop();

  myPort = new Serial(this,"COM9",9600);  //讀取裝置的變數

  h1=loadImage("1.png");
  h2=loadImage("2.png");
  h3=loadImage("3.png");
  h4=loadImage("4.png");
  h5=loadImage("5.png");
  finish=loadImage("F.png");
}

void draw(){
  //Game Start/Over
  if(myPort.available()>0){
      val=myPort.read();

      if(val==115){  //如果起點接收到光,遊戲開始
        game=true;
      }
      else if(val==114) game=false;  //如果起點沒有接收到光,遊戲重置
  }
  back();  //繪出場景
 
  if(game==true){  //遊戲開始
    count++;
    if(count==60 && state==0){  //計時器
      time++;
      count=0;
    }
    //判斷球掉進哪一個洞裡
    if(myPort.available()>0 && state==0){
      val=myPort.read();
      if(val==97){
        state=5;
        println("Hole5");
      }
      else if(val==98){
        state=4;
        println("Hole4");
      }
      else if(val==99){
        state=3;
        println("Hole3");
      }
      else if(val==100){
        state=2;
        println("Hole2");
      }
      else if(val==101){
        state=1;
        println("Hole1");
      }
      else if(val==102){
        state=6;
        println("Finish");
      }
    }

    textSize(25);text("Time:"+time,450,40);
    //秀出結果畫面
    if(state==1) image(h1,100,200,400,400);
    else if(state==2) image(h2,100,200,400,400);
    else if(state==3) image(h3,100,200,400,400);
    else if(state==4) image(h4,100,200,400,400);
    else if(state==5) image(h5,100,200,400,400);
    else if(state==6) image(finish,70,200,450,400);
  }
  else if(game==false){
    //reset
    state=0;
    time=0;
    count=0;
    back();
  }
}

//Scene
void back(){
  background(#F7AAAA);
  strokeWeight(5); fill(255); rect(50,50,500,700);
  strokeWeight(5); stroke(0);
  //row1
  line(335,680,550,680);
  line(100,680,265,680);
  //row2
  line(120,610,265,610);
  //row3
  line(50,540,215,540);
  line(265,540,450,540);
  //row4
  line(120,470,480,470);
  //row5
  line(450,400,550,400);
  line(190,400,380,400);
  //row6
  line(380,330,480,330);
  //row8
  line(50,190,380,190);
  //row9
  line(140,120,480,120);
  //cou1
  line(335,680,335,610);
  //cou2
  line(450,610,450,540);
  line(265,610,265,540);
  //cou3
  line(120,470,120,260);
  //cou5
  line(190,400,190,260);
  line(380,400,380,330);
  //cou6
  line(280,190,280,330);
  //cou7
  line(380,190,380,260);
  line(480,120,480,260);
  //hole
  fill(0,0,255);
  ellipse(90,90,60,60); //finish
  fill(0);
  ellipse(415,575,40,40);  //hole1
  ellipse(415,365,40,40);  //hole2
  ellipse(85,295,40,40);  //hole3
  ellipse(445,155,40,40);  //hole4
  ellipse(410,95,35,35);  //hole5
  //start
  fill(200);ellipse(510,715,60,60);
  fill(0);textSize(20);text("Start",490,720);
  //timer
  textSize(25);text("Time:"+time,450,40);
}

👀實體裝置





👀展示結果








https://youtu.be/kFIuPNTb-sw


Week 19 期末作品展示

 03161211 林聖倫 03160402林品至
電蚊拍飛鏢遊戲

程式碼:
const int buzzer = 8; // 用Pin8 輸出方波至蜂鳴器 void setup() { pinMode(buzzer,OUTPUT); } void loop() { // simulate phone call for ( int ii=0; ii<10; ii++ ) { tone(buzzer,1000); delay(50); tone(buzzer,500); delay(50); } noTone(buzzer); delay(2000); }

Week 19 : 普通的ㄒㄆ的普通的筆記_ 期末展示



主題:小精靈
組員:04160152 謝佩軒 04160551 劉宛俞
說明:利用方向鍵控是小精靈移動,吃掉白點點,吃掉全部的白點點遊戲就獲勝。同時還要躲避鬼怪,如果被鬼怪碰到的話遊戲就結束了。

Youtube 影片


遊戲畫面


Processing 

import processing.serial.*;
Serial myPort;
int [][]map={ {9,9,9,9,9,9,9,9,9 ,9,9,9,9,9,9,9,9,9,9 ,9,9,9,9,9,9,9,9,9,9},//9,10,10
              {9,5,5,5,5,5,5,5,5 ,9,5,5,5,5,5,5,5,5,5 ,9,5,5,5,5,5,5,5,5,9},
              {9,5,0,1,1,1,1,1,1 ,9,5,1,1,1,1,1,1,1,1 ,9,5,1,1,1,1,1,1,1,9},
              {9,5,1,9,9,9,9,5,1 ,9,9,5,1,0,0,0,0,1,9 ,9,5,1,9,9,9,9,5,1,9},
              {9,5,1,9,5,5,5,5,1 ,5,5,5,1,0,0,0,0,1,5 ,5,5,1,5,5,5,9,5,1,9}, //5
              {9,5,1,9,5,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,9,5,1,9},
              {9,5,1,9,5,1,1,1,9 ,5,1,9,9,9,9,9,9,9,5 ,1,9,5,1,1,1,9,5,1,9},
              {9,5,1,9,9,9,5,1,9 ,5,1,9,9,9,9,9,9,9,5 ,1,9,5,1,9,9,9,5,1,9},
              {9,5,1,5,5,5,5,1,5 ,5,1,5,5,5,5,5,5,5,0 ,1,5,5,1,5,5,5,5,1,9},
              {9,5,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,9}, //10
              {9,9,9,9,9,9,9,9,9 ,9,9,9,9,9,9,9,9,9,9 ,9,9,9,9,9,9,9,9,9,9} };
              /// 9=wall , 5= no pass , 0=pacman , 1=food
import ddf.minim.*;
Minim minim;
AudioPlayer music;
AudioPlayer game;
AudioPlayer end;
AudioPlayer over;

PImage imgUP, imgDOWN, imgLEFT , imgRIGHT;
PImage imgMG, imgMP, imgMR , imgMY;
int dir=0,dx=0,dy=0;

void setup(){
  size(870,330);
  background(0);
  imgUP=loadImage("up.JPG");
  imgDOWN=loadImage("down.JPG");
  imgRIGHT=loadImage("right.JPG");
  imgLEFT=loadImage("left.JPG");
  imgMG=loadImage("mos_green.png");
  imgMR=loadImage("mos_red.png");
  myPort = new Serial(this, "COM3", 115200);
 
  minim = new Minim(this);
  music = minim.loadFile("Intro.mp3",1024);//new SoundFile(this, "Intro.mp3");
  game = minim.loadFile("PacMan.mp3",1024);
  end = minim.loadFile("End.mp3",1024);
  over = minim.loadFile("gameover.mp3",1024);
  music.play();
  game.pause();
  end.pause();
  over.pause();
}
float open=1, angle=0;
int now=0;
int pacX=2, pacY=2, pacVX=50 , pacVY=120;
int mX=14,mY=3,MX=16,MY=3;
int food=0, eatfood=0;
int time=0 , time0=0;
int state=0;
void draw(){
  if(state==0){ ///homepage
  ///========pacman=========
    background(0);
    fill(255,255,0);
    noStroke(); arc(pacVX,pacVY,70,70,0+angle+open,PI*2+angle-open);
    pacVX+=1;
    if(pacVX>=940) {pacVX=-70;}
    now++;
    open=abs ((now%60)/60.0-0.5);
  ///=======how to play button=========
    fill(255);
    textSize(28);
    text("How To Play",350,220);
    if(mousePressed && mouseX>350 && mouseX<520 && mouseY>200 && mouseY<225){
       state=3;
    }
  ///=======play game button=========
    fill(255);
    textSize(28);
    text("Play Game",360,275);
    if(mousePressed && mouseX>360 && mouseX<500 && mouseY>255 && mouseY<280){
       state=1;
    } 
  }///State_0, homepage
 
  ///========game Start=========
  if(state==1){
    music.pause();
    game.play();
    //------------around_wall---------
    background(0);
    for(int i=0;i<11;i++){
      for(int j=0;j<29;j++){
         if(map[i][j]==9) {fill(0,0,255); noStroke(); rect(j*30,i*30,30,30);}
      }
    } 
    //------------pacman---------
    fill(255,255,0);
    noStroke(); arc(pacX*30,pacY*30,30,30,0+angle+open,PI*2+angle-open);
    now++;
    open=abs ((now%60)/60.0-0.5);
    //-----------monster----------
    image(imgMG,mX*30-15,mY*30-15,40,40);
    float a, b,c,d;
    a=mX-pacX; b=mY-pacY;
    c=abs(mX-pacX); d=abs(mY-pacY);
    if(a>0 && c>d && map[mY][mX-1]<=1) mX--; //mos to left
    else if(a<=0 && c>d && map[mY][mX+1]<=1) mX++; //mos to right
    else if(b>0 && c<d && map[mY-1][mX]<=1) mY--; //mos to up
    else if(b<=0 && c<d && map[mY+1][mX]<=1) mY++; //mos to down
   
    //-----------Game over----------
      if(mX==pacX && mY==pacY)
      {state=4;}
     
    ///========pacman move=========
    if(dx>0) dx-=3;
    if(dx<0) dx+=3;
    if(dy>0) dy-=3;
    if(dy<0) dy+=3;
    if(dx==0 && dy==0 && dir==1 && pacY-1<11 && map[pacY-1][pacX]<=1) {pacY--; angle=radians(270);dy=-30;} //up
    if(dx==0 && dy==0 && dir==2 && pacY+1>1 && map[pacY+1][pacX]<=1) {pacY++;angle=radians(90);dy=30;}//down
    if(dx==0 && dy==0 && dir==3 && pacX-1>1 && map[pacY][pacX-1]<=1) {pacX--;angle=radians(180);dx=-30;}//left
    if(dx==0 && dy==0 && dir==4 && pacX+1<29 && map[pacY][pacX+1]<=1) {pacX++;angle=0;dx=30;}//right
    if(map[pacY][pacX]==1) {map[pacY][pacX]=0; eatfood++;}
    //-----------food----------
    for(int i=0;i<11;i++){
      for(int j=0;j<29;j++){
        if(map[i][j]==1) {fill(255); noStroke(); ellipse(j*30,i*30, 10, 10);}
      }
    }  ///eatfood=103 
   
    if(eatfood>=103) {state=2;}
  }///state_1 game;
 
   ///========game End(state 2)=========
   if(state==2){
     game.pause();
     end.play();
     fill(255,0,0);
     textSize(100);
     ///text("TIME:"+time, 250, 180);
     text("WIN!!",330,180);   
    }
   
    ///========Game   Over(state 4)=========
      if(state==4){
       game.pause();
       over.play();
       fill(255,0,0);
       textSize(100);
       ///text("TIME:"+time, 250, 180);
       text("GameOver!!",150,180);   
    }
   
   
    ///========how to Play(state 3)=========
    if(state==3){
      background(0);
      fill(255); textSize(24);
      text("Use the keybroad to control pacman move", 80, 80);
      image(imgUP,400,120,60,60);
      image(imgDOWN,400,190,60,60);
      image(imgLEFT,330,190,60,60);
      image(imgRIGHT,470,190,60,60);

      fill(255,255,0); textSize(20);
      text("Back", 800, 300);
      if(mousePressed && mouseX>800 && mouseX<850 && mouseY>280 && mouseY<305){
       state=0;
      } 
    }/// state 3 how to play
   
  }

void keyPressed(){
  if(keyCode==UP) {dir=1;}
  if(keyCode==DOWN) {dir=2;}
  if(keyCode==LEFT) {dir=3;}
  if(keyCode==RIGHT) {dir=4;} 

}


聰明河馬密技18 期末作品展示

期末作品展示
feat.03160490黃慧緣

Galibare clock 把你打醒的鬧鐘
將塞滿棉花的手套黏在馬達上
將電線擺放在設定好的時間上
時針後方黏一根導電的電線
當電線互相碰觸
馬達就會開始轉動



week19 03160801期末展示

我們這組做的是跑跑薑餅人,點盒子上的薑餅人,可以讓薑餅人跳起來吃金幣,吃越多就可以得到越多分數,掉到白色洞裡就會死掉,最後結束會顯示得到的分數





互動期末作品展示

雙人砸派機

https://youtu.be/0jO5F0XgzKU



week19

期末展示

跑跑薑餅人

接線的示意圖

裝在盒子裡

可以按按鈕


影片網址
https://www.youtube.com/watch?v=MXZXGCWav-0
影片展示


Week19 中澤的期末作品展示


Week 19 中澤的期末作品展示

第二組 : 踩地雷 (改題目)

組員:  蕭中澤  04162710       林書玄  04163056
 
硬體設備: Maga板 、 4*4按鈕組件

遊戲說明:在16個地雷區中2位玩家輪流按取一個地雷踩下去,而16個地雷區只有1個隨機

出現的地雷,最終踩到地雷的玩家為輸方。而按取滑鼠左鍵可以再玩一次遊戲。

Youtube連結: https://youtu.be/Rb31cHjJMVw











Week 19 期末作品展示

04160214 郭晉瑜
04162523 劉旆君




Ardiuno 程式碼
const int SW_pin = 2; // digital pin connected to switch output
const int X_pin = 0; // analog pin connected to X output
const int Y_pin = 1; // analog pin connected to Y output


void setup() {
  pinMode(SW_pin, INPUT);
  digitalWrite(SW_pin, HIGH);
  Serial.begin(115200);
}

void loop() {
  Serial.write(digitalRead(2));
  Serial.write(analogRead(A0)/4);
  Serial.write(analogRead(A1)/4);
  delay(150);
}

Processing程式碼
import processing.serial.*;
Serial myPort;
PImage img0,img1,img2,img3,bg;
int stage=0;
int time=0;
void setup(){
  size(600,500);
  img0 = loadImage("Crab.png");
  img1 = loadImage("Bear.png");
  img2 = loadImage("Panda.png");
  img3 = loadImage("fox.png");
  bg = loadImage("sky.jpg");
  myPort = new Serial(this, "COM3", 115200);
}
float grabX=50, grabY=50;
float bearX=150,bearY=200;
float pandaX=350,pandaY=250;
float foxX=500,foxY=300;
float holeX=100,holeY=400;
boolean Gotit=false;
boolean Gotit1=false;
boolean Gotit2=false;
boolean bearAlive=true;
boolean pandaAlive=true;
boolean foxAlive=true;
void draw(){
  background(bg);
 if(myPort.available()>0){
 /*   t=myPort.read();
    if(t=='w') pin2=myPort.read();
    else if(t=='x') x=myPort.read();
    else if(t=='y') y=myPort.read();*/
    int pin2=myPort.read();
    int x=myPort.read();
    int y=myPort.read();
    analyze(y,x);
    if(pin2==1 && dist(grabX,grabY,bearX,bearY)<50)
    {
      Gotit=true;
    }
    else if(dist(bearX,bearY,holeX,holeY)<100){
      bearAlive=false;
    }
    if(pin2==1 && dist(grabX,grabY,pandaX,pandaY)<50){
      Gotit1=true;
    }
    else if(dist(pandaX,pandaY,holeX,holeY)<100){
      pandaAlive=false;
    }
    if(pin2==1 && dist(grabX,grabY,foxX,foxY)<50){
      Gotit2=true;
    }
    else if(dist(foxX,foxY,holeX,holeY)<100){
      foxAlive=false;
    }
    println(x+" "+y);
  }
  if(stage==0){
    textSize(80);
    text("start game",125,250);
  }
  else if(stage==1){
    ellipse(holeX,holeY,100,100);
    if(bearAlive) image(img1,bearX,bearY,100,100);
    if(pandaAlive) image(img2,pandaX,pandaY,100,100);
    if(foxAlive) image(img3,foxX,foxY,100,100);
    fill(200); image(img0,grabX,grabY,120,100);
    if(keyCode==' ' && dist(grabX,grabY,bearX,bearY)<50){
      Gotit=true;
    }
    else if(dist(bearX,bearY,holeX,holeY)<100){
      bearAlive=false;
    }
    if(keyCode==' ' && dist(grabX,grabY,pandaX,pandaY)<50){
      Gotit1=true;
    }
    else if(dist(pandaX,pandaY,holeX,holeY)<100){
      pandaAlive=false;
    }
    if(keyCode==' ' && dist(grabX,grabY,foxX,foxY)<50){
      Gotit2=true;
    }
    else if(dist(foxX,foxY,holeX,holeY)<100){
      foxAlive=false;
    }
    textSize(30);
    text("Time:"+time/60,5,35);
    time--;
    if(time<0) stage=2;
 
  }
  else if(stage==2)
  {
    textSize(80);
    text("Game Over",125,250);
  }
}
void mousePressed(){
  if(stage==0){
    stage=1;   time=60*60;
    grabX=50;  grabY=50;
    bearX=150; bearY=200;
    pandaX=350;pandaY=250;
    foxX=500;  foxY=300;
    holeX=100; holeY=400;
    Gotit=false;
    Gotit1=false;
    Gotit2=false;
    bearAlive=true;
    pandaAlive=true;
    foxAlive=true;
  }
  if(stage==2){
    stage=0;
  }
}
void analyze(int x, int y){
  if(y>200){
    grabY-=7;
    if(Gotit) bearY-=7;
    if(Gotit1) pandaY-=7;
    if(Gotit2) foxY-=7;
  }
  if(y<50){
    grabY+=7;
    if(Gotit) bearY+=7;
    if(Gotit1) pandaY+=7;
    if(Gotit2) foxY+=7;
  }
  if(x<50){
    grabX-=7;
      if(Gotit) bearX-=7;
      if(Gotit1) pandaX-=7;
      if(Gotit2) foxX-=7;
  }
  if(x>200){
    grabX+=7;
      if(Gotit) bearX+=7;
      if(Gotit1) pandaX+=7;
      if(Gotit2) foxX+=7;
   }
}
void keyPressed(){
  if(keyCode==UP){
    grabY-=7;
    if(Gotit) bearY-=7;
    if(Gotit1) pandaY-=7;
    if(Gotit2) foxY-=7;
  }
  if(keyCode==DOWN){
    grabY+=7;
      if(Gotit) bearY+=7;
      if(Gotit1) pandaY+=7;
      if(Gotit2) foxY+=7;
  }
  if(keyCode==LEFT){
    grabX-=7;
      if(Gotit) bearX-=7;
      if(Gotit1) pandaX-=7;
      if(Gotit2) foxX-=7;
  }
  if(keyCode==RIGHT){
    grabX+=7;
      if(Gotit) bearX+=7;
      if(Gotit1) pandaX+=7;
      if(Gotit2) foxX+=7;
   }
}



WEEK19 期末作品展示

打人鬧鐘 Galibare

feat. 03161236何誼庭

此作品靈感來源自一位瑞典女孩
較為不同的是我們將電線黏貼於預設的六點鐘及時針上
當時針走到六點鐘電線互相接觸導電時則啟動馬達轉動
馬達帶動手套旋轉,打在使用者臉上
使用者於睡眠中被打臉覺得不爽就會起床關鬧鐘。



Week19 期末作品展示

影片Demo網址:
https://www.youtube.com/watch?v=1FxdWV-X5fI&feature=youtu.be



互動裝置截圖:
左方為藍鼓,右方為紅鼓
















程式碼:

Arduino中
void setup()
{
  Serial.begin(9600);
  pinMode (2,INPUT_PULLUP);
  pinMode (3,INPUT_PULLUP);
}
 
void loop()
{
int a = digitalRead(2);
int b = digitalRead(3);
//Serial.println(digitalRead(3));
//Serial.println(digitalRead(4));
Serial.write(digitalRead(2));
Serial.write(digitalRead(3));
delay(220);
}


於Processing中
import processing.video.*; 
Movie movie;
import ddf.minim.*;
Minim minim;
import processing.serial.*;
Serial myPort;
AudioPlayer song;
PImage A;
PImage Q;
PImage z;
PImage x;
PImage red;
PImage summer;
PImage center;
PImage End;
float rx=800, ry=160;
int bx=800, by=160;
PVector v1, v2;
float []array=new float [560];
PVector []newarray=new PVector[560];
float []array2=new float [560];
byte[] drum3=new byte[560];
byte[] bluedrum=new byte[560];
int []dy=new int [100];
int Score=0;
int shift=200;
int state=0;
int sta=0;
int rs=0;
int bs=0;
PImage home;
PImage good;
PImage setting;
PImage drum;
PImage blue;
PImage song1;
PImage mm;
PImage nn;
PImage bluebird;
int user=120;

void setup()
{
  size(1200, 900);
  A=loadImage("A.png");
  home= loadImage("home.png");
  setting=loadImage("setting.png");
  summer=loadImage("summer2.png");
  drum=loadImage("drum.png");
  Q=loadImage("Q.jpg");
  song1=loadImage("song1.png"); 
  good=loadImage("good.png");
  center=loadImage("center.png"); 
  red=loadImage("red.png");
  blue=loadImage("blue.png");
  mm=loadImage("mm.png");
  nn=loadImage("nn.png");
  z=loadImage("z.png");
  x=loadImage("x.png");
  bluebird=loadImage("bluebird.png");
  drum3=loadBytes("drum.bin");
  bluedrum=loadBytes("bluedrum.bin");
  movie = new Movie(this, "123.mp4");
  movie.loop();
  myPort=new Serial(this, "COM3", 9600);
}
int k, f, g;
void movieEvent(Movie movie)
{
  movie.read();
int bgShift=0;
void draw()
{
  int rs=0;
  int bs=0;
  bgShift+=15;

  if (state==0)
  {
    image(home, 0, 0, 1200, 900);
    fill(255, 255, 255);
    rect(355, 803, 487, 80);
    fill(255, 0, 0);
    textSize(80);
    text("Press:P", 454, 870);
  }
  if (state==4)
  {
    image(bluebird, 100, 100, 1000, 200);
    image(mm, 600, 100, 1000, 200);
    image(song1, 100, 400, 1000, 200);
    image(nn, 600, 400, 1000, 200);
    image(z, 100, 600, 1000, 200);
    image(x, 600, 600, 1000, 200);
  }
  if (state==1) 
  {      
    image(A, 0, 0, 1200, 900);
    image(movie, 0, 498, 1200, 400);
    image(center, 470, 370, 240, 180);
    image(Q, 0, 415, 300, 80);
    fill(255, 0, 0);
    rect(690, 153, 510, 58);
    noStroke();
    textSize(50);
    fill(255);
    text(Score*100, 800, 200);

    for (int i=0; i<array.length; i++)
    {  
      if (drum3[i]!=0)
      { 
        array[i]=i*100+600-bgShift;
        if (array[i]>shift)
        {  
          image(red, array[i], 253, 80, 80);
        }
      }
      if (bluedrum[i]!=0)
      { 
        array2[i]=i*100+600-bgShift;
        if (array2[i]>shift)
        {  
          image(blue, array2[i], 253, 80, 80);
        }
      }   
      {  
        if (myPort.available()>0) {
          int pin2=myPort.read();
          if (pin2==1) rs=1;
          println(pin2);
        }
        if (myPort.available()>0) {
          int pin3=myPort.read();
          if (pin3==1) bs=1;
          println(pin3);
        }
        if (abs(array[i]-shift-25)<20 && array[i]!=0&&rs==1)
        {   
          fill(255, 0, 0, 200);
          ellipse(110, 285, 140, 110);
          Score++;
          textSize(30);
          fill(255, 227, 132);
          text("GOOD", 250, 222);
          noFill();

          song=minim.loadFile("r.mp3", 2048);     
          song.play();
          rs=0;
        }
        if (abs(array2[i]-shift-25)<20 && array2[i]!=0&&bs==1)
        {

          ellipseMode(RADIUS);
          fill(0, 0, 255, 200);
          ellipse(110, 285, 95, 80);
          ellipseMode(CENTER);
          fill(255, 255, 255, 200);
          ellipse(110, 285, 140, 110);
          Score++;
          textSize(30);
          fill(255, 227, 132);


          song=minim.loadFile("b.mp3", 2048);     
          song.play();
          bs=0;
          text("GOOD", 250, 222);
          noFill();
        }
      }
    }
    k=Score*2;
    f=30;
    g=440;
    rect(g, 58, k, f, 255); 

    if (sta==0)
    {
      fill(255, 0, 0);
      textSize(80);
      text(Score, 85, 310);
    }
  }
  if (state==2) 
  {    
    image(A, 0, 0, 1200, 900);
    image(Q, 0, 415, 300, 80);
    fill(0);
    rect(695, 454, 470, 36);
    image(movie, 0, 498, 1200, 400);
    image(summer, 840, 420, 150, 70);
    image(center, 470, 370, 240, 180);
    fill(255, 0, 0);
    rect(690, 153, 510, 58);
    noStroke();
    textSize(50);
    fill(255);
    text(Score*100, 800, 200);

    for (int i=0; i<array.length; i++)
    {  

      if (drum3[i]!=0)
      { 
        array[i]=i*100+600-bgShift;
        if (array[i]>shift)
        {  

          image(red, array[i], 253, 80, 80);
        }
      }
      if (bluedrum[i]!=0)
      { 
        array2[i]=i*100+600-bgShift;
        if (array2[i]>shift)
        {  

          image(blue, array2[i], 253, 80, 80);
        }
      }   


      {  
        if (myPort.available()>0) {
          int pin2=myPort.read();
          if (pin2==1) rs=1;
          println(pin2);
        }

        if (myPort.available()>0) {
          int pin3=myPort.read();
          if (pin3==1) bs=1;
          println(pin3);
        }
        if (abs(array[i]-shift-25)<20 && array[i]!=0&&rs==1)
        {   


          fill(255, 0, 0, 200);
          ellipse(110, 285, 140, 110);
          Score++;
          textSize(30);
          fill(255, 227, 132);
          text("GOOD", 250, 222);
          noFill();

          song=minim.loadFile("r.mp3", 2048);     
          song.play();
          rs=0;
        }


        if (abs(array2[i]-shift-25)<20 && array2[i]!=0&&bs==1)
        {

          ellipseMode(RADIUS);
          fill(0, 0, 255, 200);
          ellipse(110, 285, 95, 80);
          ellipseMode(CENTER);
          fill(255, 255, 255, 200);
          ellipse(110, 285, 140, 110);
          Score++;
          textSize(30);
          fill(255, 227, 132);


          song=minim.loadFile("b.mp3", 2048);     
          song.play();
          bs=0;
          text("GOOD", 250, 222);
          noFill();
        }
      }

      if (sta==0)
      {
        fill(255, 0, 0);
        textSize(80);
        text(Score, 85, 310);
      }
    }
    k=Score*2;
    f=30;
    g=440;
    fill(255, 0, 0);
    rect(g, 58, k, f, 255); 

    if (key=='q'||key=='Q')
    {
      sta=1;

      fill(255, 255, 255);
      rect(218, 208, 1000, 200);
      textSize(100);
      fill(255, 0, 0);
      text("Score:"+Score*100, 300, 310);
      song.close();
      minim.stop();
      super.stop();
    }
  }
}
void keyReleased()
{

  if (key=='p'||key=='P')
  {
    state=4;
  }
  if (key=='m'||key=='M')
  {
    state=1; 
    minim=new Minim(this);
    song=minim.loadFile("blue bird.mp3", 2048);     
    song.play();
  }
  if (key=='n'||key=='N')
  {
    state=2; 
    minim=new Minim(this);
    song=minim.loadFile("summer.mp3", 2048);     
    song.play();
  }
  if (state==4)
  {
    background(#FFE153);
  }
}