///////////////////////////////////////////PAGE 3 /* This page has 3 code sections: 1. functions that intialize the program 2. functions that evalute the incoming serial message 3. functions that render to the screen */ /////////////////////////////////////////////////////////////////////// //INITIALIZE FUNCTIONS /////////////////////////////////////////////////////////////////////// void initializeRUN() { //LOAD font font = loadFont("ArialMT-48.vlw"); textFont(font, 12); //INITIALIZE Fingers initializeF(); //INITIALIZE Variables serialmsg= new Smsg(0,0,0); Play=true; //INITIALIZE serial println(Serial.list()); myPort = new Serial(this, Serial.list()[0], 19200); //initialize getting to punctuation bit while(initial != startbit) { if (myPort.available() > 0) { initial = myPort.read(); println(initial); } } waiting = false; count=0; }//END initializeRUN() void initializeF() { int sp=60; //LEFT hand /*pointer*/ f[5]= new Finger(100 + 4*sp, 100, 10, 0, true); /*middle*/ f[6]= new Finger(100 + 3*sp, 100, 12, 0, true); /*ring*/ f[7]= new Finger(100 + 2*sp, 100, 16, 0, true); /*pinky*/ f[8]= new Finger(100 + sp, 100, 19, 0, true); /*thumb*/ f[9]= new Finger(100 + 5*sp, 100+30,0, 0, true); //RIGHT hand /*pointer*/ f[0]= new Finger(450 + 2*sp, 100, 10, 0, true); /*middle*/ f[1]= new Finger(450 + 3*sp, 100, 12, 0, true); /*ring*/ f[2]= new Finger(450 + 4*sp, 100, 16, 0, true); /*pinky*/ f[3]= new Finger(450 + 5*sp, 100, 19, 0, true); /*thumb*/ f[4]= new Finger(450 + sp, 100+30, 0, 0, true); }//END initializeF() /////////////////////////////////////////////////////////////////////// //EVALUATE FUNCTIONS /////////////////////////////////////////////////////////////////////// void evalmsg(Smsg SEmsg) { int[] msg= new int[3]; //parse message apart here, assume its an array msg[0]=SEmsg.getMSG(0); msg[1]=SEmsg.getMSG(1); msg[2]=SEmsg.getMSG(2); //evaluate hit codes if(msg[0] >-1 && msg[0] <13) { if(msg[0]>=5)//corrects for the fact one hand is 8-12 { msg[0]=msg[0]-3; } if(Play) { f[msg[0]].setVELOCITY(2*msg[2]); } else if(Play==false && (msg[1]==210 || msg[1]==211) )//unlock { f[msg[0]].setLOCKED(!f[msg[0]].getLOCKED()); } else //menu mode { if(f[msg[0]].getLOCKED()==false) { f[msg[0]].setSOUND((f[msg[0]].getSOUND()+1)%35); } else { f[msg[0]].setVELOCITY(100); } } } //switch to play if(msg[0] == playmsg) { Play=true; lockF(); } //switch to menu if(msg[0] == menumsg) { Play=false; } }//END evalmsg() void lockF() { for(int i=0; i < f.length; i++) { f[i].setLOCKED(true); } }//END lockF() //////////////////////////////////////////////////////////////////////////// //RENDER FUNCTIONS //////////////////////////////////////////////////////////////////////////// void renderscreen() { renderFingers(); renderMode(); resetFvel(); }//END renderscreen() void renderFingers() { for(int i=0; i < f.length; i++) { f[i].render(); } }//END renderFingers() void renderMode() { textSize(24); if(Play) { text("PLAY",20,20); } else { text("MENU",20,20); } textSize(14); }//END renderMode() void resetFvel() { for(int i=0; i < f.length; i++) { if(f[i].getVELOCITY() > 0) { f[i].setVELOCITY(f[i].getVELOCITY()-1); } } }//END resetFvel()