2016年10月20日 星期四

Week 06 蕭阿火筆記

本日上課內容

-sound程式設計
-實作
-本日體驗:HTC VIVE

-本日實作重點:for迴圈&陣列

1.Sound的背景音樂程式設計

=====================================
import processing.sound.*;

SoundFile soundfile;

void setup() {
    size(640,360);    
    //Load a soundfile
    soundfile = new SoundFile(this,"ok.mp3");  //將檔案名稱相符合的拖曳進程式碼內
    soundfile.play();//播放的時候發現音樂會變兩倍速度,因此可以使用soundfile.rate(0.5)變成一半。
}    
======================================


2.Sound加上打字遊戲
===============
int shooting=0;    //int一個變數來操控打對字後要下一個步驟的if
float boxX=200, boxY=0;
int c=0;
char [] boxC = {'a','b','c','d','e','f','g','h','i','j','k','l',
'm','n','o','p','q','r','s','t','u','v','w','x','y','z'};    //運用字元陣列來存放英文字

void draw() {
  background(255);
  boxY+=2;
  if (boxY>400) {
    c = int(random(26));       //運用字元陣列來亂數選取其中一個英文字
    boxY=0;
  }
  fill(255);
  rect(boxX, boxY, 50, 50);
  fill(255, 0, 0);
  textSize(80);
  text(boxC[c], boxX, boxY);
  if (shooting>0) {  
    strokeWeight(40);
    stroke(255, 0, 0);
    line(300, 400, boxX, boxY);
    strokeWeight(1);
    shooting--;  
    if (shooting==0) {
      c = int(random(26));
      boxX=random(400)+100;     //讓英文字的框框可以換不同地方下來。
      boxY=0;
    }
  }
}
void keyPressed() {
  if (key==boxC[c]) {
    shooting=10;
  }
}

沒有留言:

張貼留言