Mercurial > hg > Members > e105711
changeset 15:80789d11de5c draft
add function for text draw
author | e105711 <yomitan.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 01 Jul 2012 22:01:18 +0900 |
parents | 1eebc1f7874d |
children | b322a8557f93 |
files | webGL/DrumSimulator.html webGL/ruby/directoryReader.rb webGL/src/Note.js webGL/src/const.js webGL/src/f4notes.js webGL/src/f4xml.js webGL/src/keybord.js webGL/src/loadMusicFiles.js webGL/src/mainfunc.js webGL/src/sound.js |
diffstat | 10 files changed, 141 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/webGL/DrumSimulator.html Thu Jun 07 23:12:53 2012 +0900 +++ b/webGL/DrumSimulator.html Sun Jul 01 22:01:18 2012 +0900 @@ -73,20 +73,31 @@ var cursor = new Cursor(); /* these variables are defined at const.js */ -// var WIDTH = 1024; -// var HEIGHT = 640; -// var FPS = 50; -// var Interval = 1000/FPS; +// var WIDTH,HEIGHT,FPS,Interval + +function drawText(ctext,message){ + ctext.font = "18px 'MS Pゴシック'"; + ctext.fillStyle = "blue"; + ctext.fillText(message, 10, 50, canvas4text.width); +} function main(){ document.body.appendChild(renderStats.domElement); document.body.appendChild(updateStats.domElement); c = document.getElementById("example"); + canvas4text = document.getElementById("textCanvas"); + ctext = canvas4text.getContext("2d"); + canvas4text.height = 100; c.width = WIDTH; c.height = HEIGHT; cursor.reset(); ctx = init(); + + drawText(ctext,"test1"); + testImage = document.getElementById("textCanvas").toDataURL(); + makeTextObj(ctx,"testImage",testImage,432,86); + loop = (function(){ nextGameTick = (new Date).getTime(); return function(){ @@ -97,16 +108,18 @@ } renderStats.update(); gameRender(ctx); + }; })(); toTitle(); loadSounds(); loadMusicFiles(); + dummyPlay(); } function gameStart(){ - setInterval(loop,0); + setInterval(loop,10); } function init(){ @@ -144,6 +157,8 @@ <canvas id="example"> There is supposed to be an example drawing here, but it's not important. </canvas> + <canvas id="textCanvas" style="display: none;"> + </canvas> <div id="console"></div> </body> </html>
--- a/webGL/ruby/directoryReader.rb Thu Jun 07 23:12:53 2012 +0900 +++ b/webGL/ruby/directoryReader.rb Sun Jul 01 22:01:18 2012 +0900 @@ -4,7 +4,7 @@ file = File.open("../src/loadMusicFiles.js","w"); file.print "function loadMusicFiles(){\n"; dir.each{|list| - if list.match("json") then + if list.match(".json") && !(list.match("~")) then file.print "\tmusicsArray.push(\"music/" + list + "\");\n"; end }
--- a/webGL/src/Note.js Thu Jun 07 23:12:53 2012 +0900 +++ b/webGL/src/Note.js Sun Jul 01 22:01:18 2012 +0900 @@ -38,7 +38,7 @@ }; Note.prototype.kill = function(){ -// console.log(this.time+","+audioBGM.currentTime); + console.log(this.time+","+audioBGM.currentTime); this.alive = false; }; @@ -69,4 +69,4 @@ audioCymbal = audioPlay(audioCymbal); break; } -}; \ No newline at end of file +};
--- a/webGL/src/const.js Thu Jun 07 23:12:53 2012 +0900 +++ b/webGL/src/const.js Sun Jul 01 22:01:18 2012 +0900 @@ -4,6 +4,7 @@ const MAIN = 2; const PLAY = 3; const READY = 4; +const RESULT = 5; // Constituents of game const WIDTH = 960; @@ -28,4 +29,4 @@ const PERFECT = 0.025; const GREAT = 0.05; const GOOD = 0.075; -const BAD = 0.1; \ No newline at end of file +const BAD = 0.1;
--- a/webGL/src/f4notes.js Thu Jun 07 23:12:53 2012 +0900 +++ b/webGL/src/f4notes.js Sun Jul 01 22:01:18 2012 +0900 @@ -1,10 +1,17 @@ +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; - PutSpriteF(ctx,58.984375+(note.getLane()-1)*11.71875,note.getLocate(),1,imgs[5-(note.getLane()%2)]); + var noteObj = imgs[5-(note.getLane()%2)]; + PutSpriteF(ctx,58.984375+(note.getLane()-1)*11.71875,note.getLocate(),1,noteObj,noteObj.texture); } } } @@ -35,6 +42,7 @@ if(note.isAlive() && note.getTime() + BAD < audioBGM.currentTime){ note.kill(); notesArray[i].splice(j,1); + poorCount++; console.log("poor"); } @@ -42,6 +50,23 @@ } } +function resetResult(){ + perfectCount=0; + greatCount=0; + goodCount=0; + badCount=0; + poorCount=0; +} + +function showResult(){ + console.log("PERFECT:" + perfectCount); + console.log("GREAT:" + greatCount); + console.log("GOOD:" + goodCount); + console.log("BAD:" + badCount); + console.log("POOR:" + poorCount); + resetResult(); +} + /* judge() @@ -82,12 +107,16 @@ function solveDiff(diff,hitTime){ if(diff<=PERFECT){ + perfectCount++; console.log("perfect"); }else if(diff<=GREAT){ + greatCount++; console.log("great"); }else if(diff<=GOOD){ + goodCount++; console.log("good"); }else if(diff<=BAD){ + badCount++; console.log("bad"); }else{ console.log("judge error: hit:"+hitTime+" diff:"+diff); @@ -112,15 +141,9 @@ function noteAdd(time,lane,BPM){ - notesArray[lane-1].push(new Note(time,lane,BPM)); + notesArray[lane-1].push(new Note(time,lane,BPM)); } -/* -function loadMusicFiles(){ - musicsArray.push("music/test.json"); - musicsArray.push("music/test2.json"); - cursor.setMAX(musicsArray.length); -} -*/ + function loadMusics(filepath){ var httpObj = jQuery.get(filepath,null,function(){ @@ -135,4 +158,4 @@ } ); -} \ No newline at end of file +}
--- a/webGL/src/f4xml.js Thu Jun 07 23:12:53 2012 +0900 +++ b/webGL/src/f4xml.js Sun Jul 01 22:01:18 2012 +0900 @@ -30,7 +30,47 @@ } } -function PutSpriteF(ctx,x,y,scale,glObj){ +function makeTextObj(ctx,objName,imageText,w,h){ + var obj = new Object(); + obj.model = [0.0,0.0,0.0]; + obj.normal = [ + "0.0","0.0","1.0", + "0.0","0.0","1.0", + "0.0","0.0","1.0", + "0.0","0.0","1.0", + "0.0","0.0","1.0", + "0.0","0.0","1.0", + ]; + obj.texCoords = [ + "0.0","0.0", + "1.0","0.0", + "1.0","1.0", + "1.0","1.0", + "0.0","1.0", + "0.0","0.0", + ]; + obj.vertex = calcSize(w,h); + + ctx.obj[objName] = makeXmlObj(ctx,obj); + ctx.obj[objName].texture = loadImageTexture(ctx,imageText); +} + +function calcSize(w,h){ + var x = w*200/WIDTH/2; + var y = h*140/HEIGHT/2; + var z = 0.0; + var size = [ + -x,-y,z, + x,-y,z, + x,y,z, + x,y,z, + -x,y,z, + -x,-y,z, + ]; + return size; +} + +function PutSpriteF(ctx,x,y,scale,glObj,texture){ ctx.enableVertexAttribArray(0); ctx.enableVertexAttribArray(1); ctx.enableVertexAttribArray(2); @@ -63,7 +103,7 @@ mvpMatrix.setUniform(ctx, ctx.getUniformLocation(ctx.program, "u_modelViewProjMatrix"), false); - ctx.bindTexture(ctx.TEXTURE_2D, glObj.texture); + ctx.bindTexture(ctx.TEXTURE_2D, texture); ctx.drawElements(ctx.TRIANGLES, glObj.numIndices, ctx.UNSIGNED_SHORT, 0); @@ -73,7 +113,6 @@ var http = new JKL.ParseXML( url ); var data = http.parse()["OBJECT-3D"]; var xmlObj = new Object(); - if (data["surface"][0]) { for (var i in data["surface"]) { var obj = xmlObj[data["surface"][i]["name"]] = new Object(); @@ -97,6 +136,7 @@ return xmlObj; } + function splitVector(str) { // return str.replace(/^\s+/g, "").replace(/\s+/g, " ").split(" "); return str.replace(/^\s+/g, "").replace(/\s+/g, " ").replace(/\s$/g, "").split(" "); @@ -176,4 +216,4 @@ ctx.bufferData(ctx.ELEMENT_ARRAY_BUFFER, new Uint16Array(indexData), ctx.STREAM_DRAW); return retval; -} \ No newline at end of file +}
--- a/webGL/src/keybord.js Thu Jun 07 23:12:53 2012 +0900 +++ b/webGL/src/keybord.js Sun Jul 01 22:01:18 2012 +0900 @@ -115,15 +115,6 @@ toPlay(); } break; -/* - case keyX: - if(!XPressed){ - XPressed = true; - PlayingBGM = true; - AUTO = true; - toPlay(); - } -*/ } } @@ -208,6 +199,16 @@ } } +function keyResult(key){ + switch(key){ + case keySpace: + if(!SpacePressed){ + SpacePressed = true; + toMenu(); + } + } +} + function keybordDown() { @@ -227,6 +228,9 @@ case PLAY: keyPlay(keyCode); break; + case RESULT: + keyResult(keyCode); + break; } }
--- a/webGL/src/loadMusicFiles.js Thu Jun 07 23:12:53 2012 +0900 +++ b/webGL/src/loadMusicFiles.js Sun Jul 01 22:01:18 2012 +0900 @@ -1,4 +1,5 @@ function loadMusicFiles(){ + musicsArray.push("music/Am.json"); musicsArray.push("music/test.json"); musicsArray.push("music/test2.json"); cursor.setMAX(musicsArray.length);
--- a/webGL/src/mainfunc.js Thu Jun 07 23:12:53 2012 +0900 +++ b/webGL/src/mainfunc.js Sun Jul 01 22:01:18 2012 +0900 @@ -12,6 +12,9 @@ break; case PLAY: playUpdate(); + break; + case RESULT: + break; } } @@ -40,9 +43,12 @@ objsArray.length = 0; objsArray.push(new Obj(100,7.8125,1,2)); // main mode loadMusics(musicsArray[cursor.getIndex()]); -// audioBGM.play(); } +function toResult(){ + MODE = RESULT; + showResult(); +} function drawObj(ctx){ reshape(ctx); @@ -50,18 +56,20 @@ ctx.clear(ctx.COLOR_BUFFER_BIT | ctx.DEPTH_BUFFER_BIT); for(var i=0;i < objsArray.length;i++){ var obj = objsArray[i]; - PutSpriteF(ctx,obj.x,obj.y,obj.scale,imgs[obj.imgNo]); + PutSpriteF(ctx,obj.x,obj.y,obj.scale,imgs[obj.imgNo],imgs[obj.imgNo].texture); } if(MODE==PLAY){ drawNote(ctx); - PutSpriteF(ctx,100,105,1,imgs[3]); // line + PutSpriteF(ctx,100,105,1,imgs[3],imgs[3].texture); // line } - PutSpriteF(ctx,100,70,1,imgs[6]); // background - + PutSpriteF(ctx,100,70,1,imgs[6],imgs[6].texture); // background ctx.flush(); } function playUpdate(){ updateNote(); + if(BGMEndCheck()){ + toResult(); + } }
--- a/webGL/src/sound.js Thu Jun 07 23:12:53 2012 +0900 +++ b/webGL/src/sound.js Sun Jul 01 22:01:18 2012 +0900 @@ -24,13 +24,23 @@ isAppLoaded(); // ensure gameStart. } +function dummyPlay(){ + audioHClose.volume = 0; + audioHClose = audioPlay(audioHClose); + audioHClose.volume = 1.0; +} + function loadBGM(filepath){ audioBGM = new Audio(); audioBGM.src = filepath; - audioBGM.volume = 0.65; + audioBGM.volume = 0.7; } +function BGMEndCheck(){ + return audioBGM.ended; +} + function loadAudio(filepath){ audioVar = new Audio(); filesLoaded++; @@ -62,4 +72,4 @@ function audioStart(audioFile){ audioFile.load(); audioFile.play(); -} \ No newline at end of file +}