changeset 9:52045eb7a220 draft

Add judgement function
author e105711 <yomitan.ie.u-ryukyu.ac.jp>
date Tue, 15 May 2012 01:30:47 +0900
parents 040c922bd7ff
children 98a90bc478b3
files webGL/src/Note.js webGL/src/const.js webGL/src/f4notes.js webGL/src/keybord.js webGL/src/mainfunc.js
diffstat 5 files changed, 97 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/webGL/src/Note.js	Mon May 14 16:19:40 2012 +0900
+++ b/webGL/src/Note.js	Tue May 15 01:30:47 2012 +0900
@@ -23,8 +23,10 @@
 
 Note.prototype.updLocate = function(BPM,sp){
     //sp:HI-SPEED,BPM:Music's BPM
-//    this.locate += BPM*0.01*sp;
-    this.locate = 105.0 - ((this.time-audioBGM.currentTime)*BPM*ALPHA/Interval);
+    if(this.locate<105.0)
+	this.locate = 105.0 - ((this.time-audioBGM.currentTime)*BPM*ALPHA/Interval);
+    if(this.locate>105.0)
+	this.locate = 105.0;
 };
 
 Note.prototype.isAlive = function(){
@@ -32,7 +34,7 @@
 };
 
 Note.prototype.kill = function(){
-    console.log(this.time+","+audioBGM.currentTime);
+//    console.log(this.time+","+audioBGM.currentTime);
     this.alive = false;
 };
 
--- a/webGL/src/const.js	Mon May 14 16:19:40 2012 +0900
+++ b/webGL/src/const.js	Tue May 15 01:30:47 2012 +0900
@@ -1,18 +1,18 @@
-//Game mode
+// Game mode
 const TITLE = 0;
 const MENU = 1;
 const MAIN = 2;
 const PLAY = 3;
 const READY = 4;
 
-//Constituents of game
+// Constituents of game
 const WIDTH = 960;
 const HEIGHT = 600;
 const FPS = 50;
 const Interval = 1000/FPS;
 const ALPHA = 5; // influence speed of notes
 
-//Key code
+// Key code
 const keyA = 65;
 const keyS = 83;
 const keyD = 68;
@@ -23,3 +23,9 @@
 const keyX = 88;
 const keySemicolon = 186;
 const keySpace = 32;
+
+// judges (s)
+const PERFECT = 0.15;
+const GREAT = 0.03;
+const GOOD = 0.06;
+const BAD = 0.08;
\ No newline at end of file
--- a/webGL/src/f4notes.js	Mon May 14 16:19:40 2012 +0900
+++ b/webGL/src/f4notes.js	Tue May 15 01:30:47 2012 +0900
@@ -14,15 +14,86 @@
 function updNote(){
     for(i=0;i<notesArray.length;i++){
 	var note = notesArray[i];
+	if(!note.isAlive()){
+	    notesArray.splice(i,1);
+	    continue;
+	}
 	note.updLocate(testBPM,1.0);
+
 	if(note.getLocate() >= 105 && note.isAlive() && AUTO){//105:line's locate
 	    note.autoSound();
 	    note.kill();
 	    notesArray.splice(i,1);
+	    continue;
+	}
+	// judge:POOR
+	if(note.isAlive() && note.getTime() + BAD < audioBGM.currentTime){
+	    note.kill();
+	    notesArray.splice(i,1);
+	    console.log("poor");
 	}
     }
 }
 
+function judge(lane,hitTime){
+    var note1,note2; // The passage of time : note1 -> note2
+    var diff1,diff2;
+    note1=note2=null;
+    diff1=diff2=0;
+    var i,j;
+    for(i=0;i<notesArray.length;i++){
+	var note = notesArray[i];
+	if(note.getLane()!=lane)
+	    continue;
+	if(hitTime < note.getTime()-BAD || note.getTime()+BAD < hitTime)
+	    break;
+	note1 = notesArray[i];
+	for(j=i+1;j<notesArray.length;j++){
+	    note = notesArray[j];
+	    if(note.getLane()!=lane)
+		continue;
+	    if(hitTime < note.getTime()-BAD)
+		break;
+	    note2 = notesArray[j];
+	    break;
+	}
+	break;
+    }
+
+    if(note1==null){ // This input doesn't need judgement.
+//	console.log("through the judgement");
+	return;
+    }
+    diff1 = Math.abs(hitTime-note1.getTime());
+    diff2 = (note2==null)? 100 : Math.abs(hitTime-note2.getTime());
+    if(diff1<diff2){ // Input for note1.
+	solveDiff(diff1,hitTime);
+	console.log("di1");
+	note1.kill();
+	notesArray.splice(i,1);
+    }else{                          // Input for note2.
+	solveDiff(diff2,hitTime);
+	console.log("di2");
+	note2.kill();
+	notesArray.splice(j,1);
+    }
+}
+
+function solveDiff(diff,hitTime){
+    if(diff<=PERFECT){
+	console.log("perfect");
+    }else if(diff<=GREAT){
+	console.log("great");
+    }else if(diff<=GOOD){
+	console.log("good");
+    }else if(diff<=BAD){
+	console.log("bad");
+    }else{
+	console.log("judge error: hit:"+hitTime+" diff:"+diff);
+    }
+    
+}
+
 function loadNotes(){
 
     notesArray.push(new Note(0.0,3,testBPM));
--- a/webGL/src/keybord.js	Mon May 14 16:19:40 2012 +0900
+++ b/webGL/src/keybord.js	Tue May 15 01:30:47 2012 +0900
@@ -93,48 +93,56 @@
 	if(!APressed && !AUTO){
 	    APressed = true;
 	    audioHClose = audioPlay(audioHClose);
+	    judge(1,audioBGM.currentTime);
 	}
 	break;
     case keyS:
 	if(!SPressed && !AUTO){
 	    SPressed = true;
 	    audioSnare = audioPlay(audioSnare);
+	    judge(2,audioBGM.currentTime);
 	}
 	break;
     case keyD:
 	if(!DPressed && !AUTO){
     	    DPressed = true;
 	    audioKick = audioPlay(audioKick);
+	    judge(3,audioBGM.currentTime);
 	}
 	break;
     case keyF:
 	if(!FPressed && !AUTO){
     	    FPressed = true;
 	    audioTomA = audioPlay(audioTomA);
+	    judge(4,audioBGM.currentTime);
 	}
 	break;
     case keyJ:
 	if(!JPressed && !AUTO){
     	    JPressed = true;
 	    audioTomB = audioPlay(audioTomB);
+	    judge(5,audioBGM.currentTime);
 	}
 	break;
     case keyK:
 	if(!KPressed && !AUTO){
     	    KPressed = true;
 	    audioFtom = audioPlay(audioFtom);
+	    judge(6,audioBGM.currentTime);
 	}
 	break;
     case keyL:
 	if(!LPressed && !AUTO){
 	    LPressed = true;
 	    audioRide = audioPlay(audioRide);
+	    judge(7,audioBGM.currentTime);
 	}
 	break;
     case keySemicolon:
 	if(!SemicolonPressed && !AUTO){
 	    SemicolonPressed = true;
 	    audioCymbal = audioPlay(audioCymbal);
+	    judge(8,audioBGM.currentTime);
 	}
 	break;
     case keySpace:
@@ -164,7 +172,7 @@
 
     var keyCode = event.keyCode;
     var keyChar = String.fromCharCode(keyCode);
-    console.log(keyChar+":"+keyCode);
+//    console.log(keyChar+":"+keyCode);
     switch(MODE){
     case TITLE:
 	keyTitle(keyCode);
@@ -177,8 +185,6 @@
 	break;
     }
 
-    console.log("Key: Pushed '"+keyChar+"'");
-    
 }
 function keybordPress(){}
 
--- a/webGL/src/mainfunc.js	Mon May 14 16:19:40 2012 +0900
+++ b/webGL/src/mainfunc.js	Tue May 15 01:30:47 2012 +0900
@@ -33,7 +33,7 @@
     MODE = PLAY;
     objsArray.length = 0;
     objsArray.push(new Obj(100,7.8125,1,2));
-    objsArray.push(new Obj(100,105,1,3));
+//    objsArray.push(new Obj(100,105,1,3));
 }
 
 
@@ -47,8 +47,10 @@
     }
     if(MODE==PLAY){
 	drawNote(ctx);
+	PutSpriteF(ctx,100,105,1,imgs[3]); //line
     }
     PutSpriteF(ctx,100,70,1,imgs[6]); // background
+    
     ctx.flush();
 }