2023年12月7日 星期四

Doing Nothing Losing Life Week13

 Week13

覺得上週的分成16個區塊不太適合模擬鋼琴遊戲
```
import processing.sound.*;
int [][] pos = {{66,532},{205,532},{348,532},{492,532},{633,532},{773,532},{914,532}
};
SoundFile Do,Re,Mi,Fa,Sol,La,Si;
PImage img,img2;

void setup(){
  size(960,540);
  img = loadImage("Piano.png");
  img2= loadImage("Piano2.png");
  Do = new SoundFile(this,"Do.MP3");
  Re = new SoundFile(this,"Re.MP3");
  Mi = new SoundFile(this,"Mi.MP3");
  Fa = new SoundFile(this,"Fa.MP3");
  Sol = new SoundFile(this,"Sol.MP3");
  La = new SoundFile(this,"La.MP3");
  Si = new SoundFile(this,"Si.MP3");
  rectMode(CENTER);
}

void draw() {
  background(#303030);
  image(img2,-10,150,1000,540);
  fill(#616362);
  rect(480,153,980,5);
  
  /*for (int i = 0; i < 4; i++) {//跟著滑鼠移動的方框
    for (int j = 0; j < 4; j++) {      
      fill(255,0,0, 128); //128是透明度
      rect(mouseX, mouseY, 130, 10, 5);
      fill(0,255,0,  128);      
    }
  }*/

  for(int i=0;i<7;i++){//按下按鍵顯示方框
    if(pressed[i]){
      fill(#7eeffd);
      rect(pos[i][0],pos[i][1],130,10,5);
    }
  }
  /*for(int i=0;i<7;i++){
    fill(#7eeffd);
    rect(pos[i][0],pos[i][1],130,10,5);
    fill(#7eeffd);
  }*/
}
//void mousePressed(){
  //println(mouseX,mouseY);//滑鼠定位
//}
boolean [] pressed = new boolean[7];
void keyPressed(){
  if(key=='1'){
    pressed[key-'1']=true;
    Do.play();
  }
  if(key== '2'){
    pressed[key-'1']=true;
    Re.play();
  }
  if(key== '3'){
    pressed[key-'1']=true;
    Mi.play();
  }
  if(key== '4'){
    pressed[key-'1']=true;
    Fa.play();
  }
  if(key== '5'){
    pressed[key-'1']=true;
    Sol.play();
  }
  if(key== '6'){
    pressed[key-'1']=true;
    La.play();
  }
  if(key== '7'){
    pressed[key-'1']=true;
    Si.play();
  }
}
void keyReleased(){
  if(key == '1')pressed[key-'1']=false;
  if(key == '2')pressed[key-'1']=false;
  if(key == '3')pressed[key-'1']=false;
  if(key == '4')pressed[key-'1']=false;
  if(key == '5')pressed[key-'1']=false;
  if(key == '6')pressed[key-'1']=false;
  if(key == '7')pressed[key-'1']=false;
}
```
加入鋼琴的圖片,並且畫出一條分界線,在按下相應的按鍵之後會出現藍色方塊,顯示對應按下的鍵










沒有留言:

張貼留言