Mercurial > hg > Members > e105711
changeset 7:c5455ae6cd70 draft
8th,change a way of update to notes,support ogg and wav sound
author | e105711 <yomitan.ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 05 May 2012 23:57:18 +0900 |
parents | 8c25fd3f9866 |
children | 040c922bd7ff |
files | webGL/DrumSimulator.html webGL/sound/BGM_cnt.ogg webGL/sound/BGM_cnt.wav webGL/sound/BGM_notcnt.ogg webGL/sound/BGM_notcnt.wav webGL/src/Note.js webGL/src/Obj.js webGL/src/const.js webGL/src/f4notes.js webGL/src/f4xml.js webGL/src/keybord.js webGL/src/mainfunc.js webGL/src/sound.js |
diffstat | 13 files changed, 130 insertions(+), 132 deletions(-) [+] |
line wrap: on
line diff
--- a/webGL/DrumSimulator.html Sat May 05 01:49:16 2012 +0900 +++ b/webGL/DrumSimulator.html Sat May 05 23:57:18 2012 +0900 @@ -15,6 +15,7 @@ <script src="src/f4notes.js"></script> <script src="src/Note.js"></script> <script src="src/stats.js"></script> + <script src="src/Obj.js"></script> </head> <script id="vshader" type="x-shader/x-vertex"> uniform mat4 u_modelViewProjMatrix; @@ -61,14 +62,17 @@ renderStats = new Stats(); updateStats = new Stats(); - var WIDTH = 1024; - var HEIGHT = 640; -// var WIDTH = 800; -// var HEIGHT = 500; var MODE = TITLE; notesArray = []; - var FPS = 30; - var Interval = 1000/FPS; + objsArray = []; + + /* these variables are defined at const.js */ +// var WIDTH = 1024; +// var HEIGHT = 640; +// var FPS = 50; +// var Interval = 1000/FPS; + + function main(){ document.body.appendChild(renderStats.domElement); document.body.appendChild(updateStats.domElement); @@ -77,50 +81,28 @@ c.height = HEIGHT; var ctx = init(); framerate = new Framerate("framerate"); -// l = function(){loop(ctx)}; loop = (function(){ nextGameTick = (new Date).getTime(); return function(){ while((new Date).getTime()>nextGameTick){ updateStats.update(); - gameUpdate(MODE); + gameUpdate(); nextGameTick += Interval; } renderStats.update(); - gameRender(ctx,MODE); + gameRender(ctx); }; })(); - - loadNotes(); + toTitle(); loadSounds(); - ptime=0; - time1=0 + loadNotes(); } function gameStart(){ setInterval(loop,0); } -/* - function loop(ctx){ //main loop - d1 = new Date(); - framerate.snapshot(); - gameRender(ctx,MODE); - d2 = new Date(); - ptime = d2.getMilliseconds()-time1; - ttime = d2.getMilliseconds() - d1.getMilliseconds(); - if(ttime<0) - ttime+=1000; - if(ptime<0) - ptime+=1000; - - console.log("ptime is "+ptime+", ttime is "+ttime); - time1 = d2.getMilliseconds(); - setTimeout(l,Interval-ttime); - } -*/ - 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);
--- a/webGL/src/Note.js Sat May 05 01:49:16 2012 +0900 +++ b/webGL/src/Note.js Sat May 05 23:57:18 2012 +0900 @@ -1,9 +1,11 @@ var Note = function(time,lane,BPM){ - this.time = time; + this.time = time + (60/BPM*4); //60/BPM*4 = Time of a bar this.lane = lane; - this.locate = - (time*BPM/(Interval*0.1)); +// this.locate = - (this.time*BPM/(Interval*0.1)); + this.locate = 105.0 - ((this.time-audioBGM.currentTime)*BPM*ALPHA/Interval); + this.alive = true; }; @@ -21,7 +23,8 @@ Note.prototype.updLocate = function(BPM,sp){ //sp:HI-SPEED,BPM:Music's BPM - this.locate += BPM*0.01*sp; +// this.locate += BPM*0.01*sp; + this.locate = 105.0 - ((this.time-audioBGM.currentTime)*BPM*ALPHA/Interval); }; Note.prototype.isAlive = function(){ @@ -29,7 +32,6 @@ }; Note.prototype.kill = function(){ - this.alive = false; console.log(this.time+","+audioBGM.currentTime); switch(this.lane){ case 1: @@ -54,4 +56,5 @@ case 8: break; } + this.alive = false; }; \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/webGL/src/Obj.js Sat May 05 23:57:18 2012 +0900 @@ -0,0 +1,8 @@ +var Obj = function(x,y,scale,imgNo){ + + this.x = x; + this.y = y; + this.scale = scale; + this.imgNo = imgNo; + +}; \ No newline at end of file
--- a/webGL/src/const.js Sat May 05 01:49:16 2012 +0900 +++ b/webGL/src/const.js Sat May 05 23:57:18 2012 +0900 @@ -1,5 +1,13 @@ +//Game mode const TITLE = 0; const MENU = 1; const MAIN = 2; const PLAY = 3; -const READY = 4; \ No newline at end of file +const READY = 4; + +//Constituents of game +const WIDTH = 960; +const HEIGHT = 600; +const FPS = 50; +const Interval = 1000/FPS; +const ALPHA = 5; // influence speed of notes \ No newline at end of file
--- a/webGL/src/f4notes.js Sat May 05 01:49:16 2012 +0900 +++ b/webGL/src/f4notes.js Sat May 05 23:57:18 2012 +0900 @@ -1,51 +1,68 @@ -testBPM = 121; +testBPM = 120; -function drawNote(ctx,note){ - if(note.getLocate() > 105 && note.isAlive())//105:line's locate - note.kill(); - if(!note.isAlive()) - 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]); +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; + + 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]); + } } } -function updNote(note){ - if(note.getLocate() > 105 && note.isAlive())//105:line's locate - note.kill(); - if(!note.isAlive()) - return; - note.updLocate(testBPM,1.0); +function updNote(){ + 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(); + notesArray.splice(i,1); + } + } } function loadNotes(){ -/* notesArray.push(new Note(0,4,testBPM)); - notesArray.push(new Note(0.25,4,testBPM)); - notesArray.push(new Note(0.5,4,testBPM)); - notesArray.push(new Note(0.75,4,testBPM)); - notesArray.push(new Note(1.0,4,testBPM)); - notesArray.push(new Note(1.25,4,testBPM)); - notesArray.push(new Note(1.5,4,testBPM)); + + notesArray.push(new Note(0.0,4,testBPM)); notesArray.push(new Note(1.75,4,testBPM)); -*/ + + notesArray.push(new Note(2.0,4,testBPM)); + notesArray.push(new Note(3.75,4,testBPM)); - notesArray.push(new Note(0,4,121)); - notesArray.push(new Note(1.736,4,121)); + 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(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(8.0,4,testBPM)); + notesArray.push(new Note(9.75,4,testBPM)); - notesArray.push(new Note(1.983,4,121)); - notesArray.push(new Note(3.719,4,121)); + notesArray.push(new Note(10.0,4,testBPM)); + notesArray.push(new Note(11.75,4,testBPM)); - notesArray.push(new Note(3.967,4,121)); - notesArray.push(new Note(4.215,4,121)); - notesArray.push(new Note(5.702,4,121)); + 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(5.950,4,121)); - notesArray.push(new Note(6.942,4,121)); - notesArray.push(new Note(7.314,4,121)); - notesArray.push(new Note(7.686,4,121)); + 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(16.0,4,testBPM)); + notesArray.push(new Note(16.0,6,testBPM)); } \ No newline at end of file
--- a/webGL/src/f4xml.js Sat May 05 01:49:16 2012 +0900 +++ b/webGL/src/f4xml.js Sat May 05 23:57:18 2012 +0900 @@ -28,7 +28,6 @@ } } - function PutSpriteF(ctx,x,y,scale,glObj){ ctx.enableVertexAttribArray(0); ctx.enableVertexAttribArray(1);
--- a/webGL/src/keybord.js Sat May 05 01:49:16 2012 +0900 +++ b/webGL/src/keybord.js Sat May 05 23:57:18 2012 +0900 @@ -3,7 +3,6 @@ FPressed = false; JPressed = false; KPressed = false; -QPressed = false; APressed = false; SpacePressed = false; PlayingBGM = false; @@ -46,10 +45,9 @@ if(!SpacePressed){ SpacePressed = true; PlayingBGM = true; - pl = function(){audioBGM.play()}; var setTime = Interval*105.0*100.0/testBPM; - setTimeout(pl,setTime); - MODE = PLAY; + audioBGM.play(); + toPlay(); } break; default: @@ -94,7 +92,7 @@ SpacePressed = true; audioStop(audioBGM); PlayingBGM = false; - MODE = MAIN; + toMain(); } break; default: @@ -107,7 +105,7 @@ case " ": if(!SpacePressed){ SpacePressed = true; - MODE = MAIN; + toMain(); } break; default: @@ -154,11 +152,8 @@ if(keyChar == "K"){ KPressed = false; } - if(keyChar == "Q"){ - JPressed = false; - } if(keyChar == "A"){ - KPressed = false; + APressed = false; } if(keyChar == " "){ SpacePressed = false;
--- a/webGL/src/mainfunc.js Sat May 05 01:49:16 2012 +0900 +++ b/webGL/src/mainfunc.js Sat May 05 23:57:18 2012 +0900 @@ -1,17 +1,8 @@ -function gameRender(ctx,MODE){ - switch(MODE){ - case TITLE: - titleRender(ctx); - break; - case MAIN: - mainRender(ctx); - break; - case PLAY: - playRender(ctx); - } +function gameRender(ctx){ + drawObj(ctx); } -function gameUpdate(MODE){ +function gameUpdate(){ switch(MODE){ case TITLE: // titleUpdate(); @@ -24,37 +15,40 @@ } } -function titleRender(ctx){ - reshape(ctx); - ctx.clearColor(0,0,0,1); - ctx.clear(ctx.COLOR_BUFFER_BIT | ctx.DEPTH_BUFFER_BIT); - PutSpriteF(ctx,100,30,1,imgs[0]); - PutSpriteF(ctx,100,90,1,imgs[1]); - PutSpriteF(ctx,100,70,1,imgs[6]); - ctx.flush(); +function toTitle(){ + MODE = TITLE; + objsArray.length = 0; + objsArray.push(new Obj(100,30,1,0)); + objsArray.push(new Obj(100,90,1,1)); } -function mainRender(ctx){ +function toMain(){ + MODE = MAIN; + objsArray.length = 0; + objsArray.push(new Obj(100,7.8125,1,2)); + objsArray.push(new Obj(100,105,1,3)); +} + +function toPlay(){ + MODE = PLAY; + objsArray.length = 0; + objsArray.push(new Obj(100,7.8125,1,2)); + objsArray.push(new Obj(100,105,1,3)); +} + + +function drawObj(ctx){ reshape(ctx); ctx.clearColor(0,0,0,1); ctx.clear(ctx.COLOR_BUFFER_BIT | ctx.DEPTH_BUFFER_BIT); - PutSpriteF(ctx,100,7.8125,1,imgs[2]); - PutSpriteF(ctx,100,105,1,imgs[3]); //y == 480 - - PutSpriteF(ctx,100,70,1,imgs[6]); - ctx.flush(); -} - -function playRender(ctx){ - reshape(ctx); - ctx.clearColor(0,0,0,1); - ctx.clear(ctx.COLOR_BUFFER_BIT | ctx.DEPTH_BUFFER_BIT); - PutSpriteF(ctx,100,7.8125,1,imgs[2]); - PutSpriteF(ctx,100,105,1,imgs[3]); //y == 480 - for(i=0;i<notesArray.length;i++){ - drawNote(ctx,notesArray[i]); + 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,100,70,1,imgs[6]); + if(MODE==PLAY){ + drawNote(ctx); + } + PutSpriteF(ctx,100,70,1,imgs[6]); //background ctx.flush(); }
--- a/webGL/src/sound.js Sat May 05 01:49:16 2012 +0900 +++ b/webGL/src/sound.js Sat May 05 23:57:18 2012 +0900 @@ -17,8 +17,8 @@ audioCymbal = loadAudio("sound/cymbal"+ext); audioKick = loadAudio("sound/kick"+ext); audioSnare = loadAudio("sound/snare"+ext); - audioBGM = loadAudio("sound/BGM"+ext); - + audioBGM = loadAudio("sound/BGM_cnt"+ext); + audioBGM.volume = 0.65; } function loadAudio(filepath){ @@ -53,12 +53,4 @@ function audioStart(audioFile){ audioFile.load(); audioFile.play(); -} - -function getBGMTime(){ - return audioBGM.currentTime; -} - -function getLoadedCnt(){ - return filesLoaded; } \ No newline at end of file