Mercurial > hg > Members > e105711
view webGL/src/f4notes.js @ 28:42d54603b2d5 draft default tip
add graffle
author | e105711 <yomitan.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 19 Jul 2012 17:04:43 +0900 |
parents | 3f8305d62106 |
children |
line wrap: on
line source
var perfectCount=0; var greatCount=0; var goodCount=0; var badCount=0; var poorCount=0; function drawNote(ctx){ for(i=0;i<notesArray.length;i++){ for(j=0;j<notesArray[i].length;j++){ var note = notesArray[i][j]; if(note.getLocate()<0) //note isn't in the screen. break; var noteObj = (note.getLane()%2==0) ? ctx.obj["pink_notes"] : ctx.obj["blue_notes"]; PutSpriteF(ctx,58.984375+(note.getLane()-1)*11.71875,note.getLocate(),1,noteObj); } } } function drawBeam(ctx){ if(APressed) PutSpriteF(ctx,58.984375,60,1,ctx.obj["beam"]); if(SPressed) PutSpriteF(ctx,58.984375+11.71875,60,1,ctx.obj["beam"]); if(DPressed) PutSpriteF(ctx,58.984375+11.71875*2,60,1,ctx.obj["beam"]); if(FPressed) PutSpriteF(ctx,58.984375+11.71875*3,60,1,ctx.obj["beam"]); if(JPressed) PutSpriteF(ctx,58.984375+11.71875*4,60,1,ctx.obj["beam"]); if(KPressed) PutSpriteF(ctx,58.984375+11.71875*5,60,1,ctx.obj["beam"]); if(LPressed) PutSpriteF(ctx,58.984375+11.71875*6,60,1,ctx.obj["beam"]); if(SemicolonPressed) PutSpriteF(ctx,58.984375+11.71875*7,60,1,ctx.obj["beam"]); } /* updateNote() Update a note's locate and dead or alive. */ function updateNote(){ for(i=0;i<notesArray.length;i++){ for(j=0;j<notesArray[i].length;j++){ var note = notesArray[i][j]; if(!note.isAlive()){ notesArray[i].splice(j,1); continue; } note.updateLocate(note.getBPM(),1.0); if(note.getLocate() >= 105 && note.isAlive() && AUTO){ // 105:line's locate note.autoSound(); note.kill(); notesArray[i].splice(j,1); continue; } // judge:POOR if(note.isAlive() && note.getTime() + BAD < audioBGM.currentTime){ note.kill(); notesArray[i].splice(j,1); poorCount++; drawText(ctx,"judge","poor",35,"purple","center"); } } } } function resetResult(ctx){ perfectCount=0; greatCount=0; goodCount=0; badCount=0; poorCount=0; } function showResult(){ var resultScore = (perfectCount + greatCount + goodCount + badCount + poorCount)*5; // calculate MAX score. resultScore = Math.round((perfectCount*5 + greatCount*3 + goodCount*1)/resultScore*10000)/100; objsArray.push(new Obj(100,30,1,"perfect_count")); objsArray.push(new Obj(100,40,1,"great_count")); objsArray.push(new Obj(100,50,1,"good_count")); objsArray.push(new Obj(100,60,1,"bad_count")); objsArray.push(new Obj(100,70,1,"poor_count")); objsArray.push(new Obj(100,85,1,"result")); drawText(ctx,"perfect_count","PERFECT "+perfectCount,40,"white","left",450,50); drawText(ctx,"great_count" ,"GREAT "+greatCount,40,"white","left",450,50); drawText(ctx,"good_count" ,"GOOD "+goodCount,40,"white","left",450,50); drawText(ctx,"bad_count" ,"BAD "+badCount,40,"white","left",450,50); drawText(ctx,"poor_count" ,"POOR "+poorCount,40,"white","left",450,50); drawText(ctx,"result" ,"Your score is "+resultScore,40,"white","left",450,50); resetResult(); } /* judge() Judge a player's input. */ function judge(lane,hitTime){ var note1,note2; // The passage of time : note1 -> note2 var diff1,diff2; note1=note2=null; diff1=diff2=0; var i; for(i=0;i<notesArray[lane-1].length;i++){ var note = notesArray[lane-1][i]; if(hitTime < note.getTime()-BAD || note.getTime()+BAD < hitTime) break; note1 = notesArray[lane-1][i]; if(i+1<notesArray[lane-1].length) note2 = notesArray[lane-1][i+1]; 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); note1.kill(); notesArray[lane-1].splice(i,1); }else{ // Input for note2. solveDiff(diff2,hitTime); note2.kill(); notesArray[lane-1].splice(i+1,1); } } function solveDiff(diff,hitTime){ if(diff<=PERFECT){ perfectCount++; drawText(ctx,"judge","perfect",35,"yellow","center"); }else if(diff<=GREAT){ greatCount++; drawText(ctx,"judge","great",35,"green","center"); }else if(diff<=GOOD){ goodCount++; drawText(ctx,"judge","good",35,"blue","center"); }else if(diff<=BAD){ badCount++; drawText(ctx,"judge","bad",35,"red","center"); }else{ // console.log("judge error: hit:"+hitTime+" diff:"+diff); } } function loadNotes(filepath){ var httpObj = jQuery.get(filepath,null,function(){ var JSONObj = JSON.parse(httpObj.responseText); console.log("loadNotes : load '" + JSONObj.title + "'"); for(i=0;i<JSONObj.notes.length;i++){ var note = JSONObj.notes[i]; noteAdd(note.time,note.lane,note.BPM); } } ); } function noteAdd(time,lane,BPM){ notesArray[lane-1].push(new Note(time,lane,BPM)); } function initNotesArray(){ for(var i=0;i<notesArray.length;i++) notesArray[i].length = 0; } function loadMusics(filepath){ initNotesArray(); drawText(ctx,"judge","",35,"purple","center"); var httpObj = jQuery.get(filepath,null,function(){ var JSONObj = JSON.parse(httpObj.responseText); console.log("loadNotes : load '" + JSONObj.title + "'"); loadBGM(JSONObj.filepath+EXT); //EXT -> extension. defined at sound.js for(i=0;i<JSONObj.notes.length;i++){ var note = JSONObj.notes[i]; noteAdd(note.time,note.lane,note.BPM); } audioBGM.play(); }); } function loadMusicTitle(index){ var filepath = musicsArray[index]; var httpObj = jQuery.get(filepath,null,function(){ var JSONObj = JSON.parse(httpObj.responseText); drawText(ctx,"music_title",JSONObj.title,60,"white","center",432,86); }); }