changeset 8:040c922bd7ff draft

keyChar -> keyCode,add sounds
author e105711 <yomitan.ie.u-ryukyu.ac.jp>
date Mon, 14 May 2012 16:19:40 +0900
parents c5455ae6cd70
children 52045eb7a220
files webGL/DrumSimulator.html webGL/sound/BGM_cnt.ogg webGL/sound/ride.ogg webGL/sound/ride.wav webGL/sound/toma.ogg webGL/sound/toma.wav webGL/sound/tomb.ogg webGL/sound/tomb.wav webGL/src/Note.js webGL/src/const.js webGL/src/f4notes.js webGL/src/keybord.js webGL/src/mainfunc.js webGL/src/sound.js
diffstat 14 files changed, 220 insertions(+), 143 deletions(-) [+]
line wrap: on
line diff
--- a/webGL/DrumSimulator.html	Sat May 05 23:57:18 2012 +0900
+++ b/webGL/DrumSimulator.html	Mon May 14 16:19:40 2012 +0900
@@ -59,51 +59,51 @@
     }
   </script> 
   <script> 
-    renderStats = new Stats();
-    updateStats = new Stats();
+renderStats = new Stats();
+updateStats = new Stats();
 
-    var MODE = TITLE;
-    notesArray = [];
-    objsArray = [];
-    
-    /* these variables are defined at const.js */
+var MODE = TITLE;
+var AUTO = true;
+notesArray = [];
+objsArray = [];
+
+/* these variables are defined at const.js */
 //    var WIDTH = 1024;
 //    var HEIGHT = 640;
 //    var FPS = 50;
 //    var Interval = 1000/FPS;
 
 
-    function main(){
+function main(){
     document.body.appendChild(renderStats.domElement);
     document.body.appendChild(updateStats.domElement);
     c = document.getElementById("example");
     c.width = WIDTH;
     c.height = HEIGHT;
     var ctx = init();
-    framerate = new Framerate("framerate");
-
+    
     loop = (function(){
         nextGameTick = (new Date).getTime();
         return function(){
-	  while((new Date).getTime()>nextGameTick){
-            updateStats.update();
-            gameUpdate();
-            nextGameTick += Interval;
-          }
-          renderStats.update();
-          gameRender(ctx);
+	    while((new Date).getTime()>nextGameTick){
+		updateStats.update();
+		gameUpdate();
+		nextGameTick += Interval;
+	    }
+	    renderStats.update();
+	    gameRender(ctx);
         };
     })();
     toTitle();
     loadSounds();
     loadNotes();
-    }
-    
-    function gameStart(){
+}
+
+function gameStart(){
     setInterval(loop,0);
-    }
+}
 
-    function init(){
+function init(){
     var gl = initWebGL("example","vshader","fshader",["vNormal","vTexCoord","vPosition"],[0,0,0,1],10000);
     gl.uniform3f(gl.getUniformLocation(gl.program,"lightDir"),0,0,1);
     gl.uniform1i(gl.getUniformLocation(gl.program,"sampler2d"),0);
@@ -111,14 +111,14 @@
     parseXml(gl);
     
     return gl;
-    }
-    
+}
+
 
-    width = -1;
-    height = -1;
-    
-    function reshape(ctx)
-    {
+width = -1;
+height = -1;
+
+function reshape(ctx)
+{
     width = c.width;
     height = c.height;
     
@@ -126,8 +126,8 @@
     
     ctx.perspectiveMatrix = new J3DIMatrix4();
     ctx.perspectiveMatrix.ortho(0, -200, 0, -140, 0, 10000);
-    }
-    
+}
+
   </script> 
   <style type="text/css"> 
     canvas {
@@ -135,7 +135,6 @@
     }
   </style> 
   <body onload="main()" onkeydown="keybordDown()" onkeypress="keybordPress()" onkeyup="keybordUp()" style='overflow:scroll'>
-    <div id="framerate"></div> 
     <canvas id="example"> 
       There is supposed to be an example drawing here, but it's not important.
     </canvas> 
Binary file webGL/sound/BGM_cnt.ogg has changed
Binary file webGL/sound/ride.ogg has changed
Binary file webGL/sound/ride.wav has changed
Binary file webGL/sound/toma.ogg has changed
Binary file webGL/sound/toma.wav has changed
Binary file webGL/sound/tomb.ogg has changed
Binary file webGL/sound/tomb.wav has changed
--- a/webGL/src/Note.js	Sat May 05 23:57:18 2012 +0900
+++ b/webGL/src/Note.js	Mon May 14 16:19:40 2012 +0900
@@ -33,28 +33,34 @@
 
 Note.prototype.kill = function(){
     console.log(this.time+","+audioBGM.currentTime);
+    this.alive = false;
+};
+
+Note.prototype.autoSound = function(){
     switch(this.lane){
     case 1:
-	break;
-    case 2:
 	audioHClose = audioPlay(audioHClose);
 	break;
-    case 3:
+    case 2:
 	audioSnare = audioPlay(audioSnare);
 	break;
+    case 3:
+	audioKick = audioPlay(audioKick);
+	break;
     case 4:
-	audioKick = audioPlay(audioKick);
+	audioTomA = audioPlay(audioTomA);
 	break;
     case 5:
-	audioFtom = audioPlay(audioFtom);
+	audioTomB = audioPlay(audioTomB);
 	break;
     case 6:
-	audioCymbal = audioPlay(audioCymbal);
+	audioFtom = audioPlay(audioFtom);
 	break;
     case 7:
+	audioRide = audioPlay(audioRide);
 	break;
     case 8:
+	audioCymbal = audioPlay(audioCymbal);
 	break;
     }
-    this.alive = false;
 };
\ No newline at end of file
--- a/webGL/src/const.js	Sat May 05 23:57:18 2012 +0900
+++ b/webGL/src/const.js	Mon May 14 16:19:40 2012 +0900
@@ -10,4 +10,16 @@
 const HEIGHT = 600;
 const FPS = 50;
 const Interval = 1000/FPS;
-const ALPHA = 5; // influence speed of notes
\ No newline at end of file
+const ALPHA = 5; // influence speed of notes
+
+//Key code
+const keyA = 65;
+const keyS = 83;
+const keyD = 68;
+const keyF = 70;
+const keyJ = 74;
+const keyK = 75;
+const keyL = 76;
+const keyX = 88;
+const keySemicolon = 186;
+const keySpace = 32;
--- a/webGL/src/f4notes.js	Sat May 05 23:57:18 2012 +0900
+++ b/webGL/src/f4notes.js	Mon May 14 16:19:40 2012 +0900
@@ -6,12 +6,8 @@
 	if(note.getLocate()<0) //note isn't in the screen.
 	    return;
 	
-	if(note.getLane()%2!=0){
-	    PutSpriteF(ctx,58.984375+(note.getLane()-1)*11.71875,note.getLocate(),1,imgs[4]);
-	}
-	else{
-	    PutSpriteF(ctx,58.984375+(note.getLane()-1)*11.71875,note.getLocate(),1,imgs[5]);
-	}
+	PutSpriteF(ctx,58.984375+(note.getLane()-1)*11.71875,note.getLocate(),1,imgs[5-(note.getLane()%2)]);
+
     }
 }
 
@@ -19,8 +15,9 @@
     for(i=0;i<notesArray.length;i++){
 	var note = notesArray[i];
 	note.updLocate(testBPM,1.0);
-	if(note.getLocate() >= 105 && note.isAlive()){//105:line's locate
-	    note.kill(); 
+	if(note.getLocate() >= 105 && note.isAlive() && AUTO){//105:line's locate
+	    note.autoSound();
+	    note.kill();
 	    notesArray.splice(i,1);
 	}
     }
@@ -28,41 +25,41 @@
 
 function loadNotes(){
 
-    notesArray.push(new Note(0.0,4,testBPM));
-    notesArray.push(new Note(1.75,4,testBPM));
+    notesArray.push(new Note(0.0,3,testBPM));
+    notesArray.push(new Note(1.75,3,testBPM));
 
-    notesArray.push(new Note(2.0,4,testBPM));
-    notesArray.push(new Note(3.75,4,testBPM));
+    notesArray.push(new Note(2.0,3,testBPM));
+    notesArray.push(new Note(3.75,3,testBPM));
 
-    notesArray.push(new Note(4.0,4,testBPM));
-    notesArray.push(new Note(4.25,4,testBPM));
-    notesArray.push(new Note(5.625,4,testBPM));
-    notesArray.push(new Note(5.875,4,testBPM));
+    notesArray.push(new Note(4.0,3,testBPM));
+    notesArray.push(new Note(4.25,3,testBPM));
+    notesArray.push(new Note(5.625,3,testBPM));
+    notesArray.push(new Note(5.875,3,testBPM));
 
-    notesArray.push(new Note(6.0,4,testBPM));
-    notesArray.push(new Note(7.0,4,testBPM));
-    notesArray.push(new Note(7.375,4,testBPM));
-    notesArray.push(new Note(7.75,4,testBPM));
+    notesArray.push(new Note(6.0,3,testBPM));
+    notesArray.push(new Note(7.0,3,testBPM));
+    notesArray.push(new Note(7.375,3,testBPM));
+    notesArray.push(new Note(7.75,3,testBPM));
 
-    notesArray.push(new Note(8.0,4,testBPM));
-    notesArray.push(new Note(9.75,4,testBPM));
+    notesArray.push(new Note(8.0,3,testBPM));
+    notesArray.push(new Note(9.75,3,testBPM));
 
-    notesArray.push(new Note(10.0,4,testBPM));
-    notesArray.push(new Note(11.75,4,testBPM));
+    notesArray.push(new Note(10.0,3,testBPM));
+    notesArray.push(new Note(11.75,3,testBPM));
 
-    notesArray.push(new Note(12.0,4,testBPM));
-    notesArray.push(new Note(12.25,4,testBPM));
-    notesArray.push(new Note(13.625,4,testBPM));
-    notesArray.push(new Note(13.875,4,testBPM));
+    notesArray.push(new Note(12.0,3,testBPM));
+    notesArray.push(new Note(12.25,3,testBPM));
+    notesArray.push(new Note(13.625,3,testBPM));
+    notesArray.push(new Note(13.875,3,testBPM));
 
-    notesArray.push(new Note(14.0,4,testBPM));
-    notesArray.push(new Note(15.0,4,testBPM));
-    notesArray.push(new Note(15.375,4,testBPM));
-    notesArray.push(new Note(15.75,4,testBPM));
-    notesArray.push(new Note(15.0,2,testBPM));
-    notesArray.push(new Note(15.375,2,testBPM));
-    notesArray.push(new Note(15.75,2,testBPM));
+    notesArray.push(new Note(14.0,3,testBPM));
+    notesArray.push(new Note(15.0,3,testBPM));
+    notesArray.push(new Note(15.375,3,testBPM));
+    notesArray.push(new Note(15.75,3,testBPM));
+    notesArray.push(new Note(15.0,1,testBPM));
+    notesArray.push(new Note(15.375,1,testBPM));
+    notesArray.push(new Note(15.75,1,testBPM));
 
-    notesArray.push(new Note(16.0,4,testBPM));
-    notesArray.push(new Note(16.0,6,testBPM));
+    notesArray.push(new Note(16.0,3,testBPM));
+    notesArray.push(new Note(16.0,8,testBPM));
 }
\ No newline at end of file
--- a/webGL/src/keybord.js	Sat May 05 23:57:18 2012 +0900
+++ b/webGL/src/keybord.js	Mon May 14 16:19:40 2012 +0900
@@ -1,93 +1,143 @@
+APressed = false;
 SPressed = false;
 DPressed = false;
 FPressed = false;
 JPressed = false;
 KPressed = false;
-APressed = false;
+LPressed = false;
+SemicolonPressed = false;
+ZPressed = false;
+
+XPressed = false; // Main -> Play(Auto)
+
 SpacePressed = false;
 PlayingBGM = false;
-AUTO = false;
+
 
 function keyMain(key){
     switch(key){
-    case "S":
-	if(!SPressed){
-	    SPressed = true;
+    case keyA:
+	if(!APressed){
+	    APressed = true;
 	    audioHClose = audioPlay(audioHClose);
 	}
-	    
 	break;
-    case "D":
-	if(!DPressed){
-    	    DPressed = true;
+    case keyS:
+	if(!SPressed){
+	    SPressed = true;
 	    audioSnare = audioPlay(audioSnare);
 	}
 	break;
-    case "F":
-	if(!FPressed){
-    	    FPressed = true;
+    case keyD:
+	if(!DPressed){
+    	    DPressed = true;
 	    audioKick = audioPlay(audioKick);
 	}
 	break;
-    case "J":
+    case keyF:
+	if(!FPressed){
+    	    FPressed = true;
+	    audioTomA = audioPlay(audioTomA);
+	}
+	break;
+    case keyJ:
 	if(!JPressed){
     	    JPressed = true;
+	    audioTomB = audioPlay(audioTomB);
+	}
+	break;
+    case keyK:
+	if(!KPressed){
+    	    KPressed = true;
 	    audioFtom = audioPlay(audioFtom);
 	}
 	break;
-    case "K":
-	if(!KPressed){
-    	    KPressed = true;
+    case keyL:
+	if(!LPressed){
+	    LPressed = true;
+	    audioRide = audioPlay(audioRide);
+	}
+	break;
+    case keySemicolon:
+	if(!SemicolonPressed){
+	    SemicolonPressed = true;
 	    audioCymbal = audioPlay(audioCymbal);
 	}
 	break;
-    case " ":
+
+    case keySpace:
 	if(!SpacePressed){
     	    SpacePressed = true;
 	    PlayingBGM = true;
-	    var setTime = Interval*105.0*100.0/testBPM;
+//	    var setTime = Interval*105.0*100.0/testBPM;
+	    AUTO = false;
 	    audioBGM.play();
 	    toPlay();
 	}
 	break;
-    default:
-	break;
+    case keyX:
+	if(!XPressed){
+	    XPressed = true;
+	    PlayingBGM = true;
+//	    var setTime = Interval*105.0*100.0/testBPM;
+	    AUTO = true;
+	    audioBGM.play();
+	    toPlay();	    
+	}
     }
 }
 
 function keyPlay(key){
     switch(key){
-    case "S":
-	if(!SPressed){
-	    SPressed = true;
+    case keyA:
+	if(!APressed && !AUTO){
+	    APressed = true;
 	    audioHClose = audioPlay(audioHClose);
 	}
 	break;
-    case "D":
-	if(!DPressed){
-    	    DPressed = true;
+    case keyS:
+	if(!SPressed && !AUTO){
+	    SPressed = true;
 	    audioSnare = audioPlay(audioSnare);
 	}
 	break;
-    case "F":
-	if(!FPressed){
-    	    FPressed = true;
-	    audioKick = audioPlay(audioSnare);
+    case keyD:
+	if(!DPressed && !AUTO){
+    	    DPressed = true;
+	    audioKick = audioPlay(audioKick);
 	}
 	break;
-    case "J":
-	if(!JPressed){
+    case keyF:
+	if(!FPressed && !AUTO){
+    	    FPressed = true;
+	    audioTomA = audioPlay(audioTomA);
+	}
+	break;
+    case keyJ:
+	if(!JPressed && !AUTO){
     	    JPressed = true;
+	    audioTomB = audioPlay(audioTomB);
+	}
+	break;
+    case keyK:
+	if(!KPressed && !AUTO){
+    	    KPressed = true;
 	    audioFtom = audioPlay(audioFtom);
 	}
 	break;
-    case "K":
-	if(!KPressed){
-    	    KPressed = true;
+    case keyL:
+	if(!LPressed && !AUTO){
+	    LPressed = true;
+	    audioRide = audioPlay(audioRide);
+	}
+	break;
+    case keySemicolon:
+	if(!SemicolonPressed && !AUTO){
+	    SemicolonPressed = true;
 	    audioCymbal = audioPlay(audioCymbal);
 	}
 	break;
-    case " ":
+    case keySpace:
 	if(!SpacePressed){
     	    SpacePressed = true;
 	    audioStop(audioBGM);
@@ -95,37 +145,35 @@
 	    toMain();
 	}
 	break;
-    default:
-	break;
     }
 }
 
 function keyTitle(key){
     switch(key){
-    case " ":
+    case keySpace:
 	if(!SpacePressed){
 	    SpacePressed = true;
 	    toMain();
 	}
 	break;
-    default:
-	break;
     }
 }
 
 function keybordDown()
 {
 
-    var keyChar = String.fromCharCode(event.keyCode);
+    var keyCode = event.keyCode;
+    var keyChar = String.fromCharCode(keyCode);
+    console.log(keyChar+":"+keyCode);
     switch(MODE){
     case TITLE:
-	keyTitle(keyChar);
+	keyTitle(keyCode);
 	break;
     case MAIN:
-	keyMain(keyChar);
+	keyMain(keyCode);
 	break;
     case PLAY:
-//	keyPlay(keyChar);
+	keyPlay(keyCode);
 	break;
     }
 
@@ -136,26 +184,35 @@
 
 function keybordUp()
 {
-    var keyChar = String.fromCharCode(event.keyCode);
-    if(keyChar == "S"){
+    var keyCode = event.keyCode;
+    if(keyCode == keyA){ 
+	APressed = false;
+    }
+    if(keyCode == keyS){
 	SPressed = false;
     }
-    if(keyChar == "D"){
+    if(keyCode == keyD){
 	DPressed = false;
     }
-    if(keyChar == "F"){
+    if(keyCode == keyF){
 	FPressed = false;
     }
-    if(keyChar == "J"){
+    if(keyCode == keyJ){
 	JPressed = false;
     }
-    if(keyChar == "K"){
+    if(keyCode == keyK){
 	KPressed = false;
     }
-    if(keyChar == "A"){
-	APressed = false;
+    if(keyCode == keyL){
+	LPressed = false;
     }
-    if(keyChar == " "){
+    if(keyCode == keySemicolon){
+	SemicolonPressed = false;
+    }
+    if(keyCode == keyX){
+	XPressed = false;
+    }
+    if(keyCode == keySpace){
 	SpacePressed = false;
     }
 }
--- a/webGL/src/mainfunc.js	Sat May 05 23:57:18 2012 +0900
+++ b/webGL/src/mainfunc.js	Mon May 14 16:19:40 2012 +0900
@@ -48,12 +48,10 @@
     if(MODE==PLAY){
 	drawNote(ctx);
     }
-    PutSpriteF(ctx,100,70,1,imgs[6]); //background
+    PutSpriteF(ctx,100,70,1,imgs[6]); // background
     ctx.flush();
 }
 
 function playUpdate(){
-    for(i=0;i<notesArray.length;i++){
-	updNote(notesArray[i]);
-    }
+    updNote();
 }
\ No newline at end of file
--- a/webGL/src/sound.js	Sat May 05 23:57:18 2012 +0900
+++ b/webGL/src/sound.js	Mon May 14 16:19:40 2012 +0900
@@ -1,5 +1,4 @@
-var filesLoaded = 0;
-var filesToLoad = 7;
+var filesLoaded = 1; // prevent early gameStart.
 
 function loadSounds(){
 
@@ -12,27 +11,36 @@
 	alert("your browser does not support wav and ogg File.");
 
     audioHClose = loadAudio("sound/hclose"+ext);
-    audioHOpen = loadAudio("sound/hopen"+ext);
+//    audioHOpen = loadAudio("sound/hopen"+ext);
+    audioSnare = loadAudio("sound/snare"+ext);
+    audioKick = loadAudio("sound/kick"+ext);
+    audioTomA = loadAudio("sound/toma"+ext);
+    audioTomB = loadAudio("sound/tomb"+ext);
     audioFtom = loadAudio("sound/ftom"+ext);
+    audioRide = loadAudio("sound/ride"+ext);
     audioCymbal = loadAudio("sound/cymbal"+ext);
-    audioKick = loadAudio("sound/kick"+ext);
-    audioSnare = loadAudio("sound/snare"+ext);
+
     audioBGM = loadAudio("sound/BGM_cnt"+ext);
+
+
+    
+    isAppLoaded(); // ensure gameStart.
     audioBGM.volume = 0.65;
 }
 
 function loadAudio(filepath){
     audioVar = new Audio();
+    filesLoaded++;
     audioVar.addEventListener('canplaythrough', isAppLoaded, false);
-    console.log("loading...");
+//    console.log("loading...");
     audioVar.src = filepath;
     return audioVar;
 }
 
 function isAppLoaded()
 {
-    filesLoaded++;
-    if (filesLoaded == filesToLoad){
+    filesLoaded--;
+    if (filesLoaded == 0){
 	gameStart();
     }
 }