2016年10月20日 星期四

Week06 彩鳳筆記

Typing game
http://www.freetypinggame.net/play.asp



Processing
Import Sound & Video to library


Sound sample


Adding sound to processing by dragging the mp3 file to processing window


Press play and hear the song you just added

Typing a, b, c
import processing.sound.*;
SoundFile soundfile;
boolean[]drawKey = new boolean[26];//26: english alphabet
int[]a=new int[100];
void setup() {
  size(600, 400);
  soundfile = new SoundFile(this, "new.mp3");
  soundfile.play();
}

void draw() {
  for (int i=0; i<26; i++) {
    if (drawKey[i]) {
      rect(i*50, 100, 50, 50);
    }
  }
}

void keyPressed() {
  if (key=='a' || key=='A') {
    drawKey[0]=true;
  } else if (key=='b' || key=='B') {
    drawKey[1]=true;
  } else if (key=='c' || key=='C') {
    drawKey[2]=true;
  }
}

Typing game (shooting alphabet)
import processing.sound.*;
SoundFile soundfile;
boolean[]drawKey = new boolean[26];
int[]a=new int[100];
void setup() {
  size(600, 400);
  soundfile = new SoundFile(this, "new.mp3");
  soundfile.play();
}
int shooting=0;  
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;
}
}


沒有留言:

張貼留言