view webGL/src/f4notes.js @ 10:98a90bc478b3 draft

Change function name.upd->update
author e105711 <yomitan.ie.u-ryukyu.ac.jp>
date Thu, 17 May 2012 16:04:02 +0900
parents 52045eb7a220
children 502bc41e0c59
line wrap: on
line source

testBPM = 120;

function drawNote(ctx){
    for(i=0;i<notesArray.length;i++){
	var note = notesArray[i];
	if(note.getLocate()<0) //note isn't in the screen.
	    return;
	
	PutSpriteF(ctx,58.984375+(note.getLane()-1)*11.71875,note.getLocate(),1,imgs[5-(note.getLane()%2)]);

    }
}

function updateNote(){
    for(i=0;i<notesArray.length;i++){
	var note = notesArray[i];
	if(!note.isAlive()){
	    notesArray.splice(i,1);
	    continue;
	}
	note.updateLocate(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));
    notesArray.push(new Note(1.75,3,testBPM));

    notesArray.push(new Note(2.0,3,testBPM));
    notesArray.push(new Note(3.75,3,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,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,3,testBPM));
    notesArray.push(new Note(9.75,3,testBPM));

    notesArray.push(new Note(10.0,3,testBPM));
    notesArray.push(new Note(11.75,3,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,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,3,testBPM));
    notesArray.push(new Note(16.0,8,testBPM));
}