Permalink
Browse files

Initial audio support and new resource loader

  • Loading branch information...
1 parent 35b5a66 commit 28aa68102c8602b53a70145e79fc8653084741da @kesiev committed Jun 2, 2010
Showing with 4,848 additions and 1,395 deletions.
  1. +7 −0 README-AUDIO.markdown
  2. +5 −3 README.markdown
  3. BIN akihabara/fretboard.png
  4. +36 −9 akihabara/gamecycle.js
  5. +727 −73 akihabara/gbox.js
  6. +105 −15 akihabara/help.js
  7. +57 −0 akihabara/iphofretboard.js
  8. +0 −8 akihabara/iphopad.js
  9. BIN akihabara/splash.png
  10. +148 −18 akihabara/toys.js
  11. +283 −0 extra-halloffame.html
  12. +712 −0 extras/akibahero-mapper.html
  13. +409 −0 game-akibahero.html
  14. +29 −7 game-capman.html
  15. +16 −307 game-leavemealone.html
  16. +17 −547 game-solitude.html
  17. +78 −363 game-tlol.html
  18. +45 −33 game-tspin.html
  19. +78 −0 resources/akibahero/bundle-credits.js
  20. +252 −0 resources/akibahero/bundle-song-demo.js
  21. +134 −0 resources/akibahero/bundle-song-skee.js
  22. +47 −0 resources/akibahero/bundle.js
  23. BIN resources/akibahero/cels.png
  24. BIN resources/akibahero/font.png
  25. BIN resources/akibahero/fontbig.png
  26. BIN resources/akibahero/ingame-demo.png
  27. BIN resources/akibahero/ingame-skee.png
  28. BIN resources/akibahero/logo.png
  29. BIN resources/akibahero/wallpaper.png
  30. BIN resources/akibahero/warn.png
  31. BIN resources/audio/bigexplosion.mp3
  32. BIN resources/audio/bigexplosion.ogg
  33. BIN resources/audio/capman-ingame.mp3
  34. BIN resources/audio/capman-ingame.ogg
  35. BIN resources/audio/coin.mp3
  36. BIN resources/audio/coin.ogg
  37. BIN resources/audio/die.mp3
  38. BIN resources/audio/die.ogg
  39. BIN resources/audio/eat.mp3
  40. BIN resources/audio/eat.ogg
  41. BIN resources/audio/explosion.mp3
  42. BIN resources/audio/explosion.ogg
  43. BIN resources/audio/halloffame-theme.mp3
  44. BIN resources/audio/halloffame-theme.ogg
  45. BIN resources/audio/hit.mp3
  46. BIN resources/audio/hit.ogg
  47. BIN resources/audio/hypermarkup5-guitar.mp3
  48. BIN resources/audio/hypermarkup5-guitar.ogg
  49. BIN resources/audio/hypermarkup5-mix.mp3
  50. BIN resources/audio/hypermarkup5-mix.ogg
  51. BIN resources/audio/hypermarkup5-song.mp3
  52. BIN resources/audio/hypermarkup5-song.ogg
  53. BIN resources/audio/jump.mp3
  54. BIN resources/audio/jump.ogg
  55. BIN resources/audio/laser.mp3
  56. BIN resources/audio/laser.ogg
  57. BIN resources/audio/leavemealone-ending.mp3
  58. BIN resources/audio/leavemealone-ending.ogg
  59. BIN resources/audio/leavemealone-ingame.mp3
  60. BIN resources/audio/leavemealone-ingame.ogg
  61. BIN resources/audio/leavemealone-intro.mp3
  62. BIN resources/audio/leavemealone-intro.ogg
  63. BIN resources/audio/megaexplosion.mp3
  64. BIN resources/audio/megaexplosion.ogg
  65. BIN resources/audio/powerup3.mp3
  66. BIN resources/audio/powerup3.ogg
  67. BIN resources/audio/select.mp3
  68. BIN resources/audio/select.ogg
  69. BIN resources/audio/solitude-boss.mp3
  70. BIN resources/audio/solitude-boss.ogg
  71. BIN resources/audio/solitude-ending.mp3
  72. BIN resources/audio/solitude-ending.ogg
  73. BIN resources/audio/solitude-ingame.mp3
  74. BIN resources/audio/solitude-ingame.ogg
  75. BIN resources/audio/solitude-intro.mp3
  76. BIN resources/audio/solitude-intro.ogg
  77. BIN resources/audio/start.mp3
  78. BIN resources/audio/start.ogg
  79. BIN resources/audio/sword.mp3
  80. BIN resources/audio/sword.ogg
  81. BIN resources/audio/tlol-cave.mp3
  82. BIN resources/audio/tlol-cave.ogg
  83. BIN resources/audio/tlol-ending.mp3
  84. BIN resources/audio/tlol-ending.ogg
  85. BIN resources/audio/tlol-intro.mp3
  86. BIN resources/audio/tlol-intro.ogg
  87. BIN resources/audio/tlol-village.mp3
  88. BIN resources/audio/tlol-village.ogg
  89. BIN resources/audio/voice_bad.mp3
  90. BIN resources/audio/voice_bad.ogg
  91. BIN resources/audio/voice_narrator.mp3
  92. BIN resources/audio/voice_narrator.ogg
  93. BIN resources/halloffame/font.png
  94. BIN resources/halloffame/kesiev.png
  95. BIN resources/halloffame/logo.png
  96. +178 −0 resources/leavemealone/bundle-dialogues.js
  97. +35 −0 resources/leavemealone/bundle-stage1.js
  98. +37 −0 resources/leavemealone/bundle-stage2.js
  99. +47 −0 resources/leavemealone/bundle-stage3.js
  100. +42 −0 resources/leavemealone/bundle-stage4.js
  101. +47 −0 resources/leavemealone/bundle.js
  102. +27 −0 resources/solitude/bundle-attractmode.js
  103. +327 −0 resources/solitude/bundle-dialogues.js
  104. +209 −0 resources/solitude/bundle-enemies.js
  105. +85 −0 resources/solitude/bundle-stage1.js
  106. +63 −0 resources/solitude/bundle.js
  107. +61 −0 resources/tlol/bundle-credits.js
  108. +87 −0 resources/tlol/bundle-map-begin.js
  109. +138 −0 resources/tlol/bundle-map-floor1.js
  110. +125 −0 resources/tlol/bundle-map-floor2.js
  111. +67 −0 resources/tlol/bundle.js
  112. BIN resources/tlol/cels.png
  113. BIN resources/tlol/gfx-cave.png
  114. BIN resources/tlol/gfx-village.png
  115. +4 −0 resources/tspin/data/sim-gb.js
  116. +17 −1 resources/tspin/engine/block-resources.js
  117. +28 −5 resources/tspin/engine/block.js
  118. +39 −6 tool-settings.html
View
7 README-AUDIO.markdown
@@ -0,0 +1,7 @@
+Akihabara Audio
+===============
+
+* Make sure that you're using the latest version of your browser before using audio features.
+* Firefox stable has little audio caching problem/slowdowns and sometime freezes - can't figure out if is plugin's fault. Seems fixed on nightly builds. Audio is not marked as experimental.
+* For compatibility with Safari, every audio file used for games MUST be more than 1.5 seconds long. Add silence to reach the 1.5secs length.
+* Safari is having troubles on downloading audio for unknown reasons. Seems fixed on nightly builds. For now AUDIO IS EXPERIMENTAL.
View
8 README.markdown
@@ -7,10 +7,12 @@ Todo
----
* Akihabara needs to be documented!
-* Implement audio tag *Work in progress*
-* Loading screen *Work in progress*
* Better embeddability keeping playability on mobile
-* Ingame/casacaded resource loader
+
+Improvement
+-----------
+
+* Audio compatibility *Work in progress*
Nice to have
----
View
BIN akihabara/fretboard.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
45 akihabara/gamecycle.js
@@ -22,7 +22,7 @@ var gamecycle={
difficulty:0,
// state transition
- state:100,
+ state:50,
stateFirstIteration:true,
hud:{},
@@ -38,19 +38,27 @@ var gamecycle={
* meant to be overridden since you have to do garbage collection.
*/
newLife:function() { },
+
+ // game disclaimer animation (if needed)
+ gameDisclaimerAnimation:function(reset) {
+ return true;
+ },
- // level intro animation
+ // game intro animation
gameIntroAnimation:function(reset) {
if (reset) {
+ gbox.stopChannel("bgmusic");
toys.resetToy(this,"default-blinker");
} else {
gbox.blitFade(gbox.getBufferContext(),{alpha:1});
return toys.text.blink(this,"default-blinker",gbox.getBufferContext(),{font:"small",text:"LETS BEGIN!",valign:gbox.ALIGN_MIDDLE,halign:gbox.ALIGN_CENTER,dx:0,dy:0,dw:gbox.getScreenW(),dh:gbox.getScreenH(),blinkspeed:5,times:6});
}
},
+ // level intro animation
levelIntroAnimation:function(reset) {
if (reset) {
+ gbox.stopChannel("bgmusic");
toys.resetToy(this,"default-blinker");
} else {
gbox.blitFade(gbox.getBufferContext(),{alpha:1});
@@ -61,6 +69,7 @@ var gamecycle={
// Life intro animation
newlifeIntroAnimation:function(reset) {
if (reset) {
+ gbox.stopChannel("bgmusic");
toys.resetToy(this,"default-blinker");
} else {
gbox.blitFade(gbox.getBufferContext(),{alpha:1});
@@ -71,6 +80,7 @@ var gamecycle={
// gameover animation
gameoverIntroAnimation:function(reset) {
if (reset) {
+ gbox.stopChannel("bgmusic");
toys.resetToy(this,"default-blinker");
} else {
gbox.blitFade(gbox.getBufferContext(),{alpha:1});
@@ -80,7 +90,9 @@ var gamecycle={
// game title animation
gameTitleIntroAnimation:function(reset) {
- if (!reset) {
+ if (reset)
+ gbox.stopChannel("bgmusic");
+ else {
gbox.blitFade(gbox.getBufferContext(),{alpha:1});
gbox.blitText(gbox.getBufferContext(),{font:"small",text:"GAME TITLE",valign:gbox.ALIGN_MIDDLE,halign:gbox.ALIGN_CENTER,dx:0,dy:0,dw:gbox.getScreenW(),dh:gbox.getScreenH()-100});
}
@@ -132,7 +144,7 @@ var gamecycle={
toys.resetToy(this,"difficulty");
} else {
gbox.blitFade(gbox.getBufferContext(),{alpha:0.5});
- if (toys.ui.menu(this,"difficulty",{font:"small",keys:{up:"up",down:"down",ok:"a",cancel:"b"},selector:">",items:["EASY","NORMAL","HARD"],x:10,y:10})) {
+ if (toys.ui.menu(this,"difficulty",{audiooption:"default-menu-option",audioconfirm:"default-menu-confirm",font:"small",keys:{up:"up",down:"down",ok:"a",cancel:"b"},selector:">",items:["EASY","NORMAL","HARD"],x:10,y:10})) {
if (toys.getToyValue(this,"difficulty","ok") == -1) return -1;
else {
this.difficulty=toys.getToyValue(this,"difficulty","selected");
@@ -201,6 +213,17 @@ var gamecycle={
blit:function() {
switch (this.state) {
+ // Disclaimer
+ case 50: {
+ if (this.stateFirstIteration) {
+ this._resetGroups();
+ this.gameDisclaimerAnimation(true);
+ this.stateIsReady();
+ }
+ if (this.gameDisclaimerAnimation(false))
+ this.setState(100);
+ break;
+ }
// main menu
case 100:
case 101:
@@ -213,6 +236,7 @@ var gamecycle={
switch (this.state) {
case 100: { // Press to start
if (this.stateFirstIteration) {
+ gbox.resetChannel("bgmusic");
this.pressStartIntroAnimation(true);
this.stateIsReady();
}
@@ -221,6 +245,7 @@ var gamecycle={
}
case 101: { // Game menu
if (this.stateFirstIteration) {
+ gbox.setChannelVolume("bgmusic",0.5);
this.gameMenu(true);
this.stateIsReady();
}
@@ -236,7 +261,7 @@ var gamecycle={
toys.resetToy(this,"fadeout");
this.stateIsReady();
}
- if (toys.fullscreen.fadeout(this,"fadeout",gbox.getBufferContext(),{fadespeed:0.05}))
+ if (toys.fullscreen.fadeout(this,"fadeout",gbox.getBufferContext(),{fadespeed:0.05,audiochannelfade:"bgmusic"}))
this.setState(200);
break;
}
@@ -322,11 +347,13 @@ var gamecycle={
break;
}
case 700: {
+ gbox.resetChannel("bgmusic");
gbox.soloGroup(this.group);
this.gameoverIntroAnimation(true);
break;
}
case 801: {
+ gbox.resetChannel("bgmusic");
gbox.soloGroup(this.group);
this.gameEndingIntroAnimation(true);
break;
@@ -343,7 +370,7 @@ var gamecycle={
case 601: // Fade in with new life
case 402: // Fade in after level change
case 300: { // Fade in at the beginning of the game
- if (toys.fullscreen.fadein(this,"fadein",gbox.getBufferContext(),{fadespeed:0.05})) this.setState(301);
+ if (toys.fullscreen.fadein(this,"fadein",gbox.getBufferContext(),{fadespeed:0.05,audiochannelfade:"bgmusic"})) this.setState(301);
break;
}
case 301: { // Ingame stuff
@@ -352,16 +379,16 @@ var gamecycle={
}
case 400: { // Fade out before changing the level
if (this.endlevelIntroAnimation(false))
- if (toys.fullscreen.fadeout(this,"fadeout",gbox.getBufferContext(),{fadespeed:0.05})) this.setState(401);
+ if (toys.fullscreen.fadeout(this,"fadeout",gbox.getBufferContext(),{fadespeed:0.05,audiochannelfade:"bgmusic"})) this.setState(401);
break;
}
case 800: { // Fade out before game ending
if (this.endlevelIntroAnimation(false))
- if (toys.fullscreen.fadeout(this,"fadeout",gbox.getBufferContext(),{fadespeed:0.05})) this.setState(801);
+ if (toys.fullscreen.fadeout(this,"fadeout",gbox.getBufferContext(),{fadespeed:0.05,audiochannelfade:"bgmusic"})) this.setState(801);
break;
}
case 501: { // Fade out after dead
- if (toys.fullscreen.fadeout(this,"fadeout",gbox.getBufferContext(),{fadespeed:0.05}))
+ if (toys.fullscreen.fadeout(this,"fadeout",gbox.getBufferContext(),{fadespeed:0.05,audiochannelfade:"bgmusic"}))
if (this.gameIsOver())
this.setState(700); // GAME OVER
else
View
800 akihabara/gbox.js
@@ -103,13 +103,88 @@ var dynalist={
}
}
}
-
+}
+
+// A special circular queue with some features useful for the resource loader
+var cyclelist={
+ create:function(size) {
+ return {
+ _head:0,
+ _tail:0,
+ _data:[],
+ _size:(size?size:10),
+ _total:0,
+ _done:0,
+ _current:null,
+ getTotal:function(){return this._total}, // Number of elements to be "poped"
+ getDone:function(){return this._done}, // Number of popped elements since the last empty
+ getSize:function(){return this._size}, // The maximum number of elements in the queue
+ isProcessing:function(){return this._current!=null}, // The last pop was not a null (i.e. the queue returned a valid object)
+ isEnded:function(){return (this._head==this._tail)}, // There are other elements in the queue
+ isBusy:function(){return this.isProcessing()||!this.isEnded()}, // There are elements in the queue/the last one pop returned an object that is being processed
+ getCurrent:function(){return this._current}, // Return the last popped element
+ push:function(d) {
+ this._data[this._head]=d;
+ this._head=(this._head+1)%this._size;
+ this._total++;
+ },
+ pop:function() {
+ if (this.isEnded()) {
+ this._total=0;
+ this._done=0;
+ this._current=null;
+ } else {
+ this._current=this._data[this._tail];
+ this._tail=(this._tail+1)%this._size;
+ this._done++;
+ }
+ return this._current;
+ },
+ dump:function() {
+ var r="";
+ for (var i=0;i<this._size;i++) {
+ r+=i+") "+this._data[i]+" | "+(i==this._head?"HEAD ":"")+(i==this._tail?"TAIL ":"")+"\n";
+ }
+ r+="\n\n"+this._done+"/"+this._total;
+ return r;
+ }
+ }
+ }
+}
+
+// A simple circular cache handler
+var cachelist={
+ create:function(size) {
+ return {
+ _cache:{},
+ _queue:[],
+ _head:0,
+ _size:(size?size:10),
+ add:function(k,v) {
+ if (!this._cache[k]) {
+ if (this._queue[this._head])
+ delete this._cache[this._queue[this._head]];
+ this._queue[this._head]=k;
+ this._cache[k]={pos:this._head,value:v};
+ this._head=(this._head+1)%this._size;
+ } else this._cache[k].value=v;
+ },
+ read:function(k) {
+ return (this._cache[k]?this._cache[k].value:null);
+ },
+ clear:function() {
+ this._cache={};
+ this._queue=[];
+ this._head=0;
+ }
+ }
+ }
}
/**
* Gamebox module allows multiple grouped objects to move simultaneously, it helps with collisions,
* rendering and moving objects. It also provides monospaced pixel-font rendering, keyboard handling,
- * double buffering and eventually FSEs. Gamebox can also store and load data from cookies!
+ * audio, double buffering and eventually FSEs. Gamebox can also store and load data from cookies!
*/
var gbox={
// CONSTANTS
@@ -133,14 +208,13 @@ var gbox={
b:88,
c:67
},
+ _flags:{
+ experimental:false,
+ noaudio:false
+ },
_fonts:{},
- _count:0,
- _countloaded:0,
_tiles:{},
_images:{},
- _loaded:function() {
- gbox._countloaded++;
- },
_camera:{},
_screen:0,
_screenposition:0,
@@ -170,12 +244,30 @@ var gbox={
_zindex:dynalist.create(),
_db:false,
_systemcookie:"__gboxsettings",
+ _sessioncache:"",
+ _breakcacheurl:function(a) {return a+(a.indexOf("?")==-1?"?":"&")+"_brc="+gbox._sessioncache; },
+ _forcedidle:0,
+ _gamewaiting:0,
+ _splash:{
+ gaugeLittleColor:"rgb(255,240,0)",
+ gaugeLittleBackColor:"rgb(255,255,255)",
+ gaugeBorderColor:"rgb(0,0,0)",
+ gaugeBackColor:"rgb(100,100,100)",
+ gaugeColor:"rgb(255,240,0)",
+ gaugeHeight:10,
+ background:null,
+ minimalTime:0,
+ footnotes:null,
+ footnotesSpacing:1
+ },
+ _minimalexpired:0, // 0: not triggered, 1: triggered, 2: done
_safedrawimage:function(tox,img,sx,sy,sw,sh,dx,dy,dw,dh) {
+ if (!img||!tox) return;
if (sx<0) { dx-=(dw/sw)*sx;sw+=sx; sx=0; }
if (sy<0) { dy-=(dh/sh)*sy;sh+=sy; sy=0; }
if (sx+sw>img.width) { dw=(dw/sw)*(img.width-sx);sw=img.width-sx;}
if (sy+sh>img.height) { dh=(dh/sh)*(img.height-sy);sh=img.height-sy;}
- if ((sh>0)&&(sw>0)&&(sx<img.width)&&(sy<img.height)) tox.drawImage(img, sx,sy,sw,sh,dx,dy,dw,dh);
+ try { if ((sh>0)&&(sw>0)&&(sx<img.width)&&(sy<img.height)) tox.drawImage(img, sx,sy,sw,sh,dx,dy,dw,dh); } catch(e){}
},
_keydown:function(e){
var key=(e.fake||window.event?e.keyCode:e.which);
@@ -226,6 +318,8 @@ var gbox={
}
return sizes;
},
+ setForcedIdle:function(f) { this._forcedidle=f},
+ getFlag:function(f) { return this._flags[f] },
setStatusBar:function(a) { this._statbar=a },
setScreenBorder:function(a) { this._border=a},
initScreen:function(w,h) {
@@ -282,7 +376,11 @@ var gbox={
gbox._screen.ontouchmove=function(evt) { evt.preventDefault();evt.stopPropagation();};
gbox._screen.onmousedown=function(evt) {gbox._screenposition=gbox._domgetabsposition(gbox._screen);if (evt.pageY-gbox._screenposition.y<30) gbox._showkeyboardpicker(); else gbox._hidekeyboardpicker();evt.preventDefault();evt.stopPropagation();};
+ var d=new Date();
+ gbox._sessioncache=d.getDate()+"-"+d.getMonth()+"-"+d.getFullYear()+"-"+d.getHours()+"-"+d.getMinutes()+"-"+d.getSeconds();
+
gbox._loadsettings(); // Load default configuration
+ gbox.setCanAudio(true); // Tries to enable audio by default
},
setDoubleBuffering:function(db){this._db=db},
setStatBar:function(txt){ if (gbox._statbar) this._statbar.innerHTML=(txt?txt:"&nbsp")},
@@ -306,57 +404,84 @@ var gbox={
}
if (gbox._objects[g][obj][a]) gbox._objects[g][obj][a](obj,a);
},
- go:function() {
- gbox._framestart=new Date().getTime();
- var gr="";
- for (var g=0;g<gbox._renderorder.length;g++)
- if (gbox._groupplay[gbox._renderorder[g]])
- if (gbox._renderorder[g]==gbox.ZINDEX_LAYER) {
- var id;
- for (var i=0;i<gbox._actionqueue.length;i++) {
- id=gbox._zindex.first;
- while (id!=null) {
- if (gbox._groupplay[gbox._zindex.data[id].g])
- gbox._playobject(gbox._zindex.data[id].g,gbox._zindex.data[id].o,gbox._actionqueue[i]);
- id=gbox._zindex.data[id].__next;
- }
- }
- } else
- for (var i=0;i<gbox._actionqueue.length;i++)
- for (var obj in gbox._objects[gbox._renderorder[g]])
- gbox._playobject(gbox._renderorder[g],obj,gbox._actionqueue[i]);
- if (gbox._fskid>=gbox._frameskip) {
- if (gbox._db) gbox.blitImageToScreen(gbox.getBuffer());
- gbox._fskid=0;
- } else gbox._fskid++;
-
- gbox.purgeGarbage();
-
- if (gbox._zindexch.length) {
-
- for (var i=0;i<gbox._zindexch.length;i++) {
- if (gbox._objects[gbox._zindexch[i].o.g][gbox._zindexch[i].o.o])
- if (gbox._objects[gbox._zindexch[i].o.g][gbox._zindexch[i].o.o].__zt==null)
- gbox._objects[gbox._zindexch[i].o.g][gbox._zindexch[i].o.o].__zt=gbox._zindex.addObject(gbox._zindexch[i].o,gbox._zindexch[i].z);
- else
- gbox._zindex.setPrio(gbox._objects[gbox._zindexch[i].o.g][gbox._zindexch[i].o.o].__zt,gbox._zindexch[i].z);
- }
- gbox._zindexch=[];
- }
-
-
- // Handle holding
- for (var key in gbox._keymap)
- if (gbox._keyboard[gbox._keymap[key]]==-1) gbox._keyboard[gbox._keymap[key]]=0; else
- if (gbox._keyboard[gbox._keymap[key]]&&(gbox._keyboard[gbox._keymap[key]]<100)) gbox._keyboard[gbox._keymap[key]]++;
-
+ _nextframe:function(){
gbox._framestart=gbox._mspf-(new Date().getTime()-gbox._framestart);
if (gbox._autoskip)
if ((gbox._framestart<gbox._autoskip.lowidle)&&(gbox._frameskip<gbox._autoskip.max)) gbox.setFrameskip(gbox._frameskip+1); else
if ((gbox._framestart>gbox._autoskip.hiidle)&&(gbox._frameskip>gbox._autoskip.min)) gbox.setFrameskip(gbox._frameskip-1);
if (gbox._statbar) gbox.debugGetstats();
- this._gametimer=setTimeout(gbox.go,(gbox._framestart<=0?1:gbox._framestart));
+ this._gametimer=setTimeout(gbox.go,(gbox._framestart<=0?1:gbox._framestart));
+ },
+ go:function() {
+ if (gbox._loaderqueue.isBusy()) {
+ if (gbox._gamewaiting==1) {
+ gbox.blitFade(gbox._screen.getContext("2d"),{alpha:0.5});
+ gbox.blitText(gbox._screen.getContext("2d"),{font:"_dbf",dx:2,dy:2,text:"LOADING..."});
+ gbox._gamewaiting=true;
+ }
+ if (gbox._gamewaiting<=1) {
+ var bw=Math.floor(((gbox.getScreenW()-4)*gbox._loaderqueue.getDone())/gbox._loaderqueue.getSize());
+ gbox._screen.getContext("2d").globalAlpha=1;
+ gbox._screen.getContext("2d").fillStyle = gbox._splash.gaugeLittleBackColor;
+ gbox._screen.getContext("2d").fillRect(0,4+gbox.getFont("_dbf").tileh,gbox.getScreenW(),1);
+ gbox._screen.getContext("2d").fillStyle = gbox._splash.gaugeLittleColor;
+ gbox._screen.getContext("2d").fillRect(0,4+gbox.getFont("_dbf").tileh,(bw>0?bw:0),1);
+ gbox._screen.getContext("2d").restore();
+ gbox.setStatBar("Loading... ("+gbox._loaderqueue.getDone()+"/"+gbox._loaderqueue.getTotal()+")");
+ }
+ if (gbox._gamewaiting) gbox._gamewaiting--;
+ setTimeout(gbox.go,1000);
+ } else {
+ gbox._gamewaiting=3;
+ gbox._framestart=new Date().getTime();
+ var gr="";
+ for (var g=0;g<gbox._renderorder.length;g++)
+ if (gbox._groupplay[gbox._renderorder[g]])
+ if (gbox._renderorder[g]==gbox.ZINDEX_LAYER) {
+ var id;
+ for (var i=0;i<gbox._actionqueue.length;i++) {
+ id=gbox._zindex.first;
+ while (id!=null) {
+ if (gbox._groupplay[gbox._zindex.data[id].g])
+ gbox._playobject(gbox._zindex.data[id].g,gbox._zindex.data[id].o,gbox._actionqueue[i]);
+ id=gbox._zindex.data[id].__next;
+ }
+ }
+ } else
+ for (var i=0;i<gbox._actionqueue.length;i++)
+ for (var obj in gbox._objects[gbox._renderorder[g]])
+ gbox._playobject(gbox._renderorder[g],obj,gbox._actionqueue[i]);
+ if (gbox._fskid>=gbox._frameskip) {
+ if (gbox._db) gbox.blitImageToScreen(gbox.getBuffer());
+ gbox._fskid=0;
+ } else gbox._fskid++;
+
+ gbox.purgeGarbage();
+
+ if (gbox._zindexch.length) {
+
+ for (var i=0;i<gbox._zindexch.length;i++) {
+ if (gbox._objects[gbox._zindexch[i].o.g][gbox._zindexch[i].o.o])
+ if (gbox._objects[gbox._zindexch[i].o.g][gbox._zindexch[i].o.o].__zt==null)
+ gbox._objects[gbox._zindexch[i].o.g][gbox._zindexch[i].o.o].__zt=gbox._zindex.addObject(gbox._zindexch[i].o,gbox._zindexch[i].z);
+ else
+ gbox._zindex.setPrio(gbox._objects[gbox._zindexch[i].o.g][gbox._zindexch[i].o.o].__zt,gbox._zindexch[i].z);
+ }
+ gbox._zindexch=[];
+ }
+
+
+ // Handle holding
+ for (var key in gbox._keymap)
+ if (gbox._keyboard[gbox._keymap[key]]==-1) gbox._keyboard[gbox._keymap[key]]=0; else
+ if (gbox._keyboard[gbox._keymap[key]]&&(gbox._keyboard[gbox._keymap[key]]<100)) gbox._keyboard[gbox._keymap[key]]++;
+ if (gbox._forcedidle)
+ this._gametimer=setTimeout(gbox._nextframe,gbox._forcedidle); // Wait for the browser
+ else
+ gbox._nextframe();
+ }
},
+
debugGetstats:function() {
var statline="Idle: "+gbox._framestart+"/"+gbox._mspf+(gbox._frameskip>0?" ("+gbox._frameskip+"skip)":"")+" | ";
var cnt=0;
@@ -366,6 +491,14 @@ var gbox={
for (var obj in gbox._objects[gbox._groups[g]]) cnt++;
if (cnt) statline+=gbox._groups[g]+"["+cnt+"] ";
}
+ var cnt=0;
+ var ply=0;
+ for (var g in gbox._audio.aud)
+ for (var x=0;x<gbox._audio.aud[g].length;x++) {
+ cnt++;
+ if (!gbox._audio.aud[g][x].paused&&!gbox._audio.aud[g][x].ended) ply++;
+ }
+ statline+="| audio: "+ply+"/"+cnt+":"+this._audioteam;
/*
statline+="<br><br>";
var id=gbox._zindex.first;
@@ -389,6 +522,7 @@ var gbox={
_savesettings:function() {
var saved="";
for (var k in this._keymap) saved+="keymap-"+k+":"+this._keymap[k]+"~";
+ for (var f in this._flags) saved+="flag-"+f+":"+(this._flags[f]?1:0)+"~";
this.dataSave("sys",saved);
},
_loadsettings:function() {
@@ -402,6 +536,7 @@ var gbox={
mk=kv[0].split("-");
switch (mk[0]) {
case "keymap": { this._keymap[mk[1]]=kv[1]*1; break }
+ case "flag": { this._flags[mk[1]]=kv[1]*1; break }
}
}
}
@@ -441,6 +576,9 @@ var gbox={
this.setCameraX(data.x-this._screenhw,viewdata);
this.setCameraY(data.y-this._screenhh,viewdata);
},
+
+
+
getGroups:function() { return this._groups; },
setGroups:function(g){
this._groups=g;
@@ -519,42 +657,46 @@ var gbox={
},
groupIsEmpty:function(gid) { for (var i in this._objects[gid]) return false; return true; },
createCanvas:function(id,data) {
- if (this._canvas[id]) delete this._canvas[id];
+ this.deleteCanvas(id);
this._canvas[id]=document.createElement("canvas");
this._canvas[id].setAttribute('height',(data&&data.h?data.h:this._screenh));
this._canvas[id].setAttribute('width',(data&&data.w?data.w:this._screenw));
},
+ deleteCanvas:function(id) {
+ if (this._canvas[id]) delete this._canvas[id];
+ },
+ imageIsLoaded:function(id){ return this._images[id]&&(this._images[id].getAttribute("wasloaded"))&&this._images[id].width },
getImage:function(id){return this._images[id]},
getBuffer:function(id){return this.getCanvas("_buffer")},
getBufferContext:function(id){ return (gbox._fskid>=gbox._frameskip?(this._db?this.getCanvasContext("_buffer"):this._screen.getContext("2d")):null) },
getCanvas:function(id){return this._canvas[id]},
getCanvasContext:function(id){return this.getCanvas(id).getContext("2d");},
addImage:function(id,filename) {
- this._count++;
- this._images[id]=new Image();
- this._images[id].addEventListener('load', this._loaded,false);
- this._images[id].src=filename;
- this._images[id].setAttribute('id',id);
+ if (this._images[id])
+ if (this._images[id].getAttribute("src_org")==filename)
+ return;
+ else
+ delete this._images[id];
+ this._addtoloader({type:"image",id:id,filename:filename});
+ },
+ deleteImage:function(id) {
+ delete this._images[id];
},
addTiles:function(t) {
t.tilehh=Math.floor(t.tileh/2);
t.tilehw=Math.floor(t.tilew/2);
this._tiles[t.id]=t;
},
getTiles:function(t) { return this._tiles[t] },
+ getFont:function(t){ return this._fonts[t] },
loadAll:function() {
- if (gbox._count!=gbox._countloaded) {
- gbox.setStatBar("Loading... ("+gbox._count+"/"+gbox._countloaded+")");
- setTimeout(gbox.loadAll,50);
- } else {
- // Calculate half heights
- for (var id in gbox._images) {
- gbox._images[id].hheight=Math.floor(gbox._images[id].height/2);
- gbox._images[id].hwidth=Math.floor(gbox._images[id].width/2);
- }
- gbox.setStatBar();
- gbox._cb();
- }
+ // Default stuff
+ this.addImage("_dbf","akihabara/debugfont.png");
+ if (this._splash.background) this.addImage("_splash",this._splash.background);
+ gbox.addFont({id:"_dbf",image:"_dbf",firstletter:" ",tileh:5,tilew:4,tilerow:16,gapx:0,gapy:0});
+ if (!gbox._splash.minimalTime)
+ gbox._minimalexpired=2;
+ this._waitforloaded();
},
_implicitsargs:function(data) {
if (data.camera) {
@@ -583,7 +725,7 @@ var gbox={
tox.save();
tox.globalAlpha=(data.alpha?data.alpha:1);
tox.translate((data.fliph?image.width:0), (data.flipv?image.height:0)); tox.scale((data.fliph?-1:1), (data.flipv?-1:1));
- tox.drawImage(image, data.dx*(data.fliph?-1:1),data.dy*(data.flipv?-1:1));
+ this._safedrawimage(tox,image, 0,0, image.width,image.height,data.dx*(data.fliph?-1:1),data.dy*(data.flipv?-1:1),image.width,image.height);
tox.restore();
},
blit:function(tox,image,data) {
@@ -654,6 +796,518 @@ var gbox={
if (!t) t=0;
return !((o1.y<o2.y+t) || (o1.y> o2.y+o2.h-1-t) || (o1.x<o2.x+t) || (o1.x>o2.x+o2.w-1-t));
},
- objectIsVisible:function(obj) { return this.collides(obj,this._camera,0); }
+ objectIsVisible:function(obj) { return this.collides(obj,this._camera,0); },
+
+ // ---
+ // ---
+ // --- AUDIO ENGINE
+ // ---
+ // ---
+
+ _audiochannels:{},
+ _audiomastervolume:1.0,
+ _canaudio:false,
+ _audiodequeuetime:0,
+ _audioprefetch:0.5,
+ _audiocompatmode:0, // 0: pause/play, 1: google chrome compatibility, 2: ipad compatibility (single channel)
+ _createmode:0, // 0: clone, 1: rehinstance
+ _fakecheckprogressspeed:100, // Frequency of fake audio monitoring
+ _fakestoptime:1, // Fake audio stop for compatibility mode
+ _audioteam:2,
+ _loweraudioteam:1,
+ _audio:{lding:null,qtimer:false,aud:{},ast:{}},
+ _audioactions:[],
+ _showplayers:false,
+ _singlechannelname:"bgmusic",
+ _positiondelay:0,
+ _playerforcer:0,
+ _audiomutevolume:0.0001, // Zero is still not accepted by everyone :(
+ _rawstopaudio:function(su) {
+ if (gbox._audiocompatmode==1) {
+ if (su.duration-su.currentTime>gbox._fakestoptime)
+ su.currentTime=su.duration-gbox._fakestoptime;
+ su.muted=true;
+ } else
+ su.pause();
+
+ },
+ _rawplayaudio:function(su) {
+ if (gbox._audiocompatmode==1) {
+ try { su.currentTime=0; } catch (e) {}
+ su.muted=false;
+ su.play();
+ } else if (gbox._audiocompatmode==2) {
+ su.load();
+ gbox._playerforcer=setInterval(function(e){try{su.play();clearInterval(gbox._playerforcer)}catch(e){}},1000);
+ } else {
+ try { su.currentTime=0; } catch (e) {}
+ su.play();
+ }
+ },
+ _finalizeaudio:function(ob,who,donext){
+
+ var cur=(who?who:this);
+ cur.removeEventListener('ended', gbox._finalizeaudio,false);
+ cur.removeEventListener('timeupdate', gbox._checkprogress,false);
+
+ cur.addEventListener('ended', gbox._playbackended,false);
+ if (donext) gbox._loaderloaded();
+ },
+ _audiodoload:function() {
+ if (gbox._audiocompatmode==1) gbox._audio.lding.muted=true;
+ else if (gbox._audiocompatmode==2)
+ gbox._finalizeaudio(null,gbox._audio.lding,true);
+ else {
+ gbox._audio.lding.load();
+ gbox._audio.lding.play();
+ }
+ },
+ _timedfinalize:function() {
+ gbox._rawstopaudio(gbox._audio.lding);
+ gbox._finalizeaudio(null,gbox._audio.lding,true);
+ },
+ _checkprogress:function() {
+ if (gbox._audio.lding.currentTime>gbox._audioprefetch) gbox._timedfinalize();
+ },
+ _fakecheckprogress:function() {
+ if (gbox._audio.lding.currentTime>gbox._audioprefetch) gbox._timedfinalize(); else setTimeout(gbox._fakecheckprogress,gbox._fakecheckprogressspeed);
+ },
+ _audiofiletomime:function(f) {
+ var fsp=f.split(".");
+ switch (fsp.pop().toLowerCase()) {
+ case "ogg": { return "audio/ogg"; break }
+ case "mp3": { return "audio/mpeg"; break }
+ default: {
+ return "audio/mpeg";
+ }
+ }
+ },
+ _pushaudio:function(){try {this.currentTime=1.0} catch(e){} },
+ _createnextaudio:function(cau) {
+ if (cau.def) {
+ gbox.deleteAudio(cau.id);
+ this._audio.aud[cau.id]=[];
+ this._audio.ast[cau.id]={cy:-1,volume:1,channel:null,play:false,mute:false,filename:cau.filename[0]};
+ if (cau.def) for (var a in cau.def) this._audio.ast[cau.id][a]=cau.def[a];
+ }
+ if ((gbox._createmode==0)&&(cau.team>0)) {
+ var ael =this._audio.aud[cau.id][0].cloneNode(true);
+ gbox._finalizeaudio(null,ael,false);
+ } else {
+ var ael=document.createElement('audio');
+ ael.volume=gbox._audiomutevolume;
+ }
+ if (!gbox._showplayers) {
+ ael.style.display="none";
+ ael.style.visibility="hidden";
+ ael.style.width="1px";
+ ael.style.height="1px";
+ ael.style.position="absolute";
+ ael.style.left="0px";
+ ael.style.top="-1000px";
+ }
+ ael.setAttribute('controls',gbox._showplayers);
+ ael.setAttribute('aki_id',cau.id);
+ ael.setAttribute('aki_cnt',cau.team);
+ ael.addEventListener('loadedmetadata', gbox._pushaudio,false); // Push locked audio in safari
+ if (((gbox._createmode==0)&&(cau.team==0))||(gbox._createmode==1)) {
+ if (ael.canPlayType) {
+ var cmime;
+ for (var i=0;i<cau.filename.length;i++) {
+ cmime=gbox._audiofiletomime(cau.filename[i]);
+ if (("no" != ael.canPlayType(cmime)) && ("" != ael.canPlayType(cmime))) {
+ ael.src=gbox._breakcacheurl(cau.filename[i]);
+ break;
+ }
+ }
+ } else {
+ for (var i=0;i<cau.filename.length;i++) {
+ var src=document.createElement('source');
+ src.setAttribute('src', gbox._breakcacheurl(cau.filename[i]));
+ ael.appendChild(src);
+ }
+ }
+ ael.addEventListener('ended',this._finalizeaudio,false);
+ if (gbox._audiocompatmode==1)
+ setTimeout(gbox._fakecheckprogress,gbox._fakecheckprogressspeed);
+ else
+ ael.addEventListener('timeupdate',this._checkprogress,false);
+ ael.setAttribute('buffering',"auto");
+ ael.volume=0;
+ this._audio.aud[cau.id].push(ael);
+ document.body.appendChild(ael);
+ gbox._audio.lding=ael;
+ setTimeout(gbox._audiodoload,1);
+ } else {
+ this._audio.aud[cau.id].push(ael);
+ document.body.appendChild(ael);
+ gbox._loaderloaded();
+ }
+ },
+ _playbackended:function(e) {
+ if (gbox._audio.ast[this.getAttribute('aki_id')].cy==this.getAttribute('aki_cnt')) {
+ if (gbox._audio.ast[this.getAttribute('aki_id')].play&&gbox._audio.ast[this.getAttribute('aki_id')].loop)
+ if (gbox._audiocompatmode==2)
+ gbox._rawplayaudio(this);
+ else
+ this.currentTime=0;
+ else
+ gbox._audio.ast[this.getAttribute('aki_id')].play=false;
+ } else if (gbox._audiocompatmode==1) {
+ this.pause();
+ this.muted=false;
+ }
+ },
+ _updateaudio:function(a) {
+ if (this._audio.ast[a].play) {
+ this._audio.aud[a][this._audio.ast[a].cy].volume=(this._audio.ast[a].mute?this._audiomutevolume:
+ this._audiomastervolume*
+ (this._audio.ast[a].volume!=null?this._audio.ast[a].volume:1)*
+ ((this._audio.ast[a].channel!=null)&&(this._audiochannels[this._audio.ast[a].channel]!=null)&&(this._audiochannels[this._audio.ast[a].channel].volume!=null)?this._audiochannels[this._audio.ast[a].channel].volume:1)
+ )
+ }
+ },
+ _minimaltimeexpired:function() { gbox._minimalexpired=2; },
+ _splashscreeniscompleted:function() { return (gbox._splash.background?gbox.imageIsLoaded("_splash"):true) && (gbox._splash.minilogo?gbox.imageIsLoaded("logo"):true) && (gbox._splash.footnotes?gbox.imageIsLoaded("_dbf"):true) },
+ _addqueue:function(a) {
+ if (!gbox._audiodequeuetime)
+ gbox._dequeueaudio(null,a);
+ else {
+ gbox._audioactions.push(a);
+ if (!gbox._audio.qtimer) {
+ gbox._audio.qtimer=true;
+ setTimeout(gbox._dequeueaudio,gbox._audiodequeuetime);
+ }
+ }
+ },
+ _dequeueaudio:function(k,rt) {
+ var ac=(rt?rt:gbox._audioactions.pop());
+ switch (ac.t) {
+ case 0: {
+ gbox._updateaudio(ac.a.getAttribute("aki_id"));
+ gbox._rawplayaudio(ac.a);
+ break
+ }
+ case 1: {
+ gbox._rawstopaudio(ac.a);
+ break;
+ }
+ case 2: {
+ gbox._updateaudio(ac.a.getAttribute("aki_id"));
+ break;
+ }
+ }
+ if (!rt&&gbox._audioactions.length) {
+ gbox._audio.qtimer=true;
+ setTimeout(gbox._dequeueaudio,gbox._audiodequeuetime);
+ } else gbox._audio.qtimer=false;
+
+ },
+ getAudioIsSingleChannel:function() { return this._audiocompatmode==2; },
+ setAudioPositionDelay:function(m) { gbox._positiondelay=m },
+ setAudioDequeueTime:function(m) { gbox._audiodequeuetime=m },
+ setShowPlayers:function(m) { gbox._showplayers=m},
+ setAudioCompatMode:function(m) { gbox._audiocompatmode=m },
+ setAudioCreateMode:function(m) { gbox._createmode=m },
+ addAudio:function(id,filename,def) {
+ if (gbox._canaudio) {
+ if (gbox._audio.aud[id])
+ if (gbox._audio.ast[id].filename==filename[0])
+ return;
+ else
+ gbox.deleteAudio(id);
+ if ((gbox._audiocompatmode!=2)||(def.channel==gbox._singlechannelname)) {
+ var grsize=(def.channel==gbox._singlechannelname?gbox._loweraudioteam:(def.background?gbox._loweraudioteam:gbox._audioteam));
+ for (var i=0;i<grsize;i++)
+ gbox._addtoloader({type:"audio",data:{id:id,filename:filename,def:(i==0?def:null),team:i}});
+ }
+ }
+ },
+ deleteAudio:function(id) {
+ if (gbox._audio.aud[id]) {
+ for (var i=0;i<gbox._audio.aud[id].length;i++) {
+ try {document.body.removeChild(gbox._audio.aud[id][i]);}catch(e){}
+ delete gbox._audio.aud[id][i];
+ }
+ delete gbox._audio.aud[id];
+ if (gbox._audio.ast[id]) delete gbox._audio.ast[id];
+ }
+ },
+ playAudio:function(a,data) {
+ if (this._canaudio&&this._audio.ast[a])
+ if (!this._audio.ast[a].play) this.hitAudio(a,data);
+ },
+ hitAudio:function(a,data) {
+ if (this._canaudio&&this._audio.ast[a]) {
+ var ael;
+ if (this._audio.ast[a].cy!=-1)
+ this.stopAudio(a,true);
+ this._audio.ast[a].cy=(this._audio.ast[a].cy+1)%this._audio.aud[a].length;
+ ael=this._audio.aud[a][this._audio.ast[a].cy];
+ if (data)
+ for (var n in data) this._audio.ast[a][n]=data[n];
+ this._audio.ast[a].play=true;
+ this._addqueue({t:0,a:ael});
+ }
+ },
+ stopAudio:function(a,permissive) {
+ if (this._canaudio) {
+ var ael;
+ if (this._canaudio&&this._audio.ast[a]&&this._audio.ast[a].play) {
+ this._audio.ast[a].play=false;
+ ael=this._audio.aud[a][this._audio.ast[a].cy];
+ if (ael.duration-1.5>0)
+ this._addqueue({t:1,a:ael});
+ }
+ }
+ },
+ setSplashSettings:function(a) { for (var n in a) this._splash[n]=a[n]; },
+ resetChannel:function(ch) {
+ if (this._canaudio&&this._audiochannels[ch])
+ if (ch=="master")
+ for (var ch in this._audiochannels)
+ this.setChannelVolume(ch,this._audiochannels[ch]._def.volume);
+ else if (this._audiochannels[ch])
+ this.setChannelVolume(ch,this._audiochannels[ch]._def.volume);
+ },
+ getChannelDefaultVolume:function(ch) {
+ if (this._canaudio&&this._audiochannels[ch]) return this._audiochannels[ch]._def.volume; else return null;
+ },
+ setChannelVolume:function(ch,a) {
+ if (this._canaudio&&this._audiochannels[ch]) {
+ if (ch=="master") this._audiomastervolume=a; else this._audiochannels[ch].volume=a
+ for (var j in gbox._audio.aud)
+ if (this._audio.ast[j].cy>-1) this._updateaudio(j);
+ }
+ },
+ getChannelVolume:function(ch) { if (ch=="master") return this._audiomastervolume; else if (this._audiochannels[ch]) return this._audiochannels[ch].volume; else return 0 },
+ changeChannelVolume:function(ch,a) {
+ if (this._canaudio&&this._audiochannels[ch]) {
+ var vol=this.getChannelVolume(ch)+a;
+ if (vol>1) vol=1; else if (vol<0) vol=0;
+ this.setChannelVolume(ch,vol);
+ }
+ },
+ stopChannel:function(ch) {
+ if (this._canaudio)
+ for (var j in gbox._audio.aud)
+ if (this._audio.ast[j].cy>-1&&gbox._audio.ast[j].play&&((ch=="master")||(this._audio.ast[j].channel==ch)))
+ this.stopAudio(j);
+ },
+
+ setAudioUnmute:function(a) { if (this._canaudio&&this._audio.ast[a]) { this._audio.ast[a].mute=false; this._updateaudio(a); } },
+ setAudioMute:function(a) { if (this._canaudio&&this._audio.ast[a]) { this._audio.ast[a].mute=true; this._updateaudio(a); } },
+ getAudioMute:function(a) { if (this._canaudio&&this._audio.ast[a]) return this._audio.ast[a].mute; else return null},
+
+ setAudioVolume:function(a,vol) { if (this._canaudio&&this._audio.ast[a]) { this._audio.ast[a].volume=vol; this._updateaudio(a); } },
+ getAudioVolume:function(a,vol) { if (this._canaudio&&this._audio.ast[a]) return this._audio.ast[a].volume; else return null},
+
+ setAudioPosition:function(a,p) { if (this._canaudio&&this._audio.ast[a]&&this._audio.aud[a][this._audio.ast[a].cy]) this._audio.aud[a][this._audio.ast[a].cy].currentTime=p;},
+ getAudioPosition:function(a) {if (this._canaudio&&this._audio.ast[a]&&this._audio.aud[a][this._audio.ast[a].cy]) if (this._audio.aud[a][this._audio.ast[a].cy].currentTime>this._positiondelay) return this._audio.aud[a][this._audio.ast[a].cy].currentTime-this._positiondelay; else return 0; else return 0},
+
+ getAudioDuration:function(a) {if (this._canaudio&&this._audio.ast[a]&&this._audio.aud[a][this._audio.ast[a].cy]) return this._audio.aud[a][this._audio.ast[a].cy].duration; else return 0},
+
+ changeAudioVolume:function(a,vol) { if (this._canaudio&&this._audio.ast[a]) { if (this._audio.ast[a].volume+vol>1) this._audio.ast[a].volume=1; else if (this._audio.ast[a].volume+vol<0) this._audio.ast[a].volume=0; else this._audio.ast[a].volume+=vol; this._updateaudio(a); } },
+ setCanAudio:function(a) { this._canaudio=!this._flags.noaudio&&a;},
+ setAudioChannels:function(a){
+ this._audiochannels=a;
+ for (var ch in a) {
+ this._audiochannels[ch]._def={};
+ for (var attr in this._audiochannels[ch])
+ if (attr!="_def") this._audiochannels[ch]._def[attr]=this._audiochannels[ch][attr];
+ }
+ },
+ setAudioTeam:function(a){ this._audioteam=a; },
+ setLowerAudioTeam:function(a){ this._loweraudioteam=a; },
+
+ // ---
+ // ---
+ // --- DYNAMIC SCRIPT INCLUSION
+ // ---
+ // ---
+
+ addScript:function(call) {
+ gbox._addtoloader({type:"script",call:call});
+ },
+
+ // ---
+ // ---
+ // --- BUNDLES
+ // ---
+ // ---
+
+ addBundle:function(call){
+ gbox._addtoloader({type:"bundle",call:call});
+ },
+
+ readBundleData:function(pack,call) {
+ // Local resources first
+ if (pack.setObject) for (var i=0;i<pack.setObject.length;i++) eval("("+pack.setObject[i].object+")")[pack.setObject[i].property]=pack.setObject[i].value;
+ if (pack.addFont) for (var i=0;i<pack.addFont.length;i++) gbox.addFont(pack.addFont[i]);
+ if (pack.addTiles) for (var i=0;i<pack.addTiles.length;i++) gbox.addTiles(pack.addTiles[i]);
+ // Remote resources for last
+ if (pack.addImage) for (var i=0;i<pack.addImage.length;i++) gbox.addImage(pack.addImage[i][0],pack.addImage[i][1]);
+ if (pack.addAudio) for (var i=0;i<pack.addAudio.length;i++) gbox.addAudio(pack.addAudio[i][0],pack.addAudio[i][1],pack.addAudio[i][2]);
+ if (pack.addBundle) for (var i=0;i<pack.addBundle.length;i++) gbox.addBundle(pack.addBundle[i]);
+ if (pack.addScript) for (var i=0;i<pack.addScript.length;i++) gbox.addScript(pack.addScript[i]);
+ // Trigger the onLoad events in resource and loader
+ if (pack.onLoad) gbox._addtoloader({type:"exec-onl",func:pack.onLoad,call:call,pack:pack});
+ if (call.onLoad) gbox._addtoloader({type:"exec-onl",func:call.onLoad,call:call,pack:pack});
+ },
+
+ // ---
+ // ---
+ // --- DATA LOADER
+ // ---
+ // ---
+
+ _xmlhttp:null,
+ _loaderqueue:cyclelist.create(200),
+ _loadercache:cachelist.create(30),
+
+ // Callback for loaded image
+ _loaderimageloaded:function() {
+ this.setAttribute('wasloaded',true);
+ this.hheight=Math.floor(this.height/2);
+ this.hwidth=Math.floor(this.width/2);
+ gbox._loaderloaded();
+ },
+ // Callback for loaded bundle
+ _loaderhmlhttploading:function(){
+ if(this.readyState == 4 && (this.status == 0||this.status == 200)) {
+ if (this.responseText) {
+ if (!gbox._loaderqueue.getCurrent().call.skipCacheSave)
+ gbox._loadercache.add(gbox._loaderqueue.getCurrent().call.file,this.responseText);
+ var pack=eval("("+this.responseText+")");
+ gbox.readBundleData(pack,gbox._loaderqueue.getCurrent().call);
+ // Keep loading the other resources.
+ gbox._loaderloaded();
+ }
+ }
+ },
+
+ // Loader code
+ _addtoloader:function(d) { // type:xx, data:yy
+ gbox._loaderqueue.push(d);
+ if (!gbox._loaderqueue.isProcessing())
+ gbox._loadnext();
+ },
+ _loaderloaded:function() {
+ setTimeout(gbox._loadnext,10);
+ },
+ _loaderscript:function() {
+ if (gbox._loaderqueue.getCurrent().call.onLoad) gbox._addtoloader({type:"exec-onl",func:gbox._loaderqueue.getCurrent().call.onLoad,call:gbox._loaderqueue.getCurrent().call});
+ gbox._loadnext();
+ },
+ _loadnext:function() {
+ var current=gbox._loaderqueue.pop();
+ if (gbox._loaderqueue.isProcessing()) {
+ switch (gbox._loaderqueue.getCurrent().type) {
+ case "image":{
+ gbox._images[current.id]=new Image();
+ gbox._images[current.id].addEventListener('load', gbox._loaderimageloaded,false);
+ gbox._images[current.id].src=gbox._breakcacheurl(current.filename);
+ gbox._images[current.id].setAttribute('src_org',current.filename);
+ gbox._images[current.id].setAttribute('id',current.id);
+ gbox._images[current.id].setAttribute('wasloaded',false);
+ break;
+ }
+ case "bundle":{
+ var done=false;
+ if (!current.call.skipCacheLoad) {
+ var data=gbox._loadercache.read(current.call.file);
+ if (data) {
+ var pack=eval("("+data+")");
+ gbox.readBundleData(pack,current.call);
+ // Keep loading the other resources.
+ gbox._loaderloaded();
+ done=true;
+ }
+ }
+ if (!done) {
+ gbox._xmlhttp=new XMLHttpRequest();
+ gbox._xmlhttp.open((current.call.data?"POST":"GET"), gbox._breakcacheurl(current.call.file),true);
+ gbox._xmlhttp.onreadystatechange = gbox._loaderhmlhttploading;
+ if (current.call.data) {
+ gbox._xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+ gbox._xmlhttp.send(current.call.data);
+ } else gbox._xmlhttp.send();
+ }
+ break;
+ }
+ case "audio":{
+ gbox._createnextaudio(current.data);
+ break;
+ }
+ case "exec-onl":{
+ current.func(current.call,current.pack);
+ gbox._loaderloaded();
+ break;
+ }
+ case "script":{
+ var script= document.createElement('script');
+ script.type="text/javascript";
+ script.onload=gbox._loaderscript;
+ script.src=current.call.file;
+ document.getElementsByTagName('body')[0].appendChild(script);
+ break;
+ }
+ }
+ }
+
+ },
+ _waitforloaded:function() {
+ var aul;
+ if (gbox._loaderqueue.isBusy()||(gbox._minimalexpired!=2)) {
+ var tox=gbox._screen.getContext("2d");
+ tox.save();
+ gbox.blitFade(tox,{alpha:1});
+ if (!gbox._minimalexpired&&gbox._splashscreeniscompleted()) {
+ gbox._minimalexpired=1;
+ setTimeout(gbox._minimaltimeexpired,gbox._splash.minimalTime);
+ }
+ if (gbox._splash.loading) gbox._splash.loading(tox,gbox._loaderqueue.getDone(),gbox._loaderqueue.getTotal());
+ if (gbox._splash.background&&gbox.imageIsLoaded("_splash"))
+ gbox.blit(tox,gbox.getImage("_splash"),{w:gbox.getImage("_splash").width,h:gbox.getImage("_splash").height,dx:0,dy:0,dw:gbox.getScreenW(),dh:gbox.getScreenH()});
+ if (gbox._splash.minilogo&&gbox.imageIsLoaded("logo")) {
+ var dw=gbox.getScreenW()/4;
+ var dh=(gbox.getImage("logo").height*dw)/gbox.getImage("logo").width
+ gbox.blit(tox,gbox.getImage(gbox._splash.minilogo),{w:gbox.getImage("logo").width,h:gbox.getImage("logo").height,dx:gbox.getScreenW()-dw-5,dy:gbox.getScreenH()-dh-5,dw:dw,dh:dh});
+ }
+ if (gbox._splash.footnotes&&gbox.imageIsLoaded("_dbf")) {
+ if (!gbox.getCanvas("_footnotes")) {
+ var fd=gbox.getFont("_dbf");
+ gbox.createCanvas("_footnotes",{w:gbox.getScreenW()-5,h:(gbox._splash.footnotes.length)*(fd.tileh+gbox._splash.footnotesSpacing)});
+ for (var i=0;i<gbox._splash.footnotes.length;i++)
+ gbox.blitText(gbox.getCanvasContext("_footnotes"),{
+ font:"_dbf",
+ dx:0,
+ dy:i*(fd.tileh+gbox._splash.footnotesSpacing),
+ text:gbox._splash.footnotes[i]
+ });
+ }
+ gbox.blitAll(tox,gbox.getCanvas("_footnotes"),{dx:5,dy:gbox.getScreenH()-gbox.getCanvas("_footnotes").height-5});
+ }
+ if (gbox._loaderqueue.isBusy()) {
+ var bw=Math.floor(((gbox.getScreenW()-4)*gbox._loaderqueue.getDone())/gbox._loaderqueue.getTotal());
+ tox.globalAlpha=1;
+ tox.fillStyle = gbox._splash.gaugeBorderColor;
+ tox.fillRect(0,Math.floor((gbox.getScreenH()-gbox._splash.gaugeHeight)/2),gbox.getScreenW(),gbox._splash.gaugeHeight);
+ tox.fillStyle = gbox._splash.gaugeBackColor;
+ tox.fillRect(1,Math.floor(((gbox.getScreenH()-gbox._splash.gaugeHeight)/2)+1),gbox.getScreenW()-4,gbox._splash.gaugeHeight-2);
+ tox.fillStyle = gbox._splash.gaugeColor;
+ tox.fillRect(1,Math.floor(((gbox.getScreenH()-gbox._splash.gaugeHeight)/2)+1),(bw>0?bw:0),gbox._splash.gaugeHeight-2);
+ }
+ tox.restore();
+ gbox.setStatBar("Loading... ("+gbox._loaderqueue.getDone()+"/"+gbox._loaderqueue.getTotal()+")");
+ setTimeout(gbox._waitforloaded,50);
+ } else {
+ gbox.deleteImage("_splash");
+ gbox.setStatBar();
+ gbox._cb();
+ }
+ },
+ clearCache:function() { this._loadercache.clear(); }
+
};
View
120 akihabara/help.js
@@ -51,6 +51,13 @@ var help={
decideFrame:function(cnt,anim) {
return anim.frames[Math.floor(cnt/anim.speed)%anim.frames.length];
},
+ // Numbers going up and down once reached the half
+ // Args: (counter)
+ // Outs: the value
+ upAndDown:function(counter,max) {
+ if ((counter%max)>(max/2)) return max-(counter%max); else return (counter%max);
+ },
+
// Get the tile value in a map, using pixels as coords
// Args: (x,y,map,<output if any tile is found>,<index of the map array in the passed map>)
// Outs: the tile or ifout
@@ -215,34 +222,117 @@ var help={
for (var n in o) ret+=n+":["+o[n]+"] ";
return ret;
},
+
+ // Check if a variable is defined or not
+ isDefined:function(v) {
+ return ((typeof(v) !== 'undefined') || (v===null));
+ },
+
+ // Get device configuration
+ getDeviceConfig:function() {
+
+ var cap;
+ if (navigator.userAgent.match(/iPhone/i)||navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/Android/i))
+ cap={touch:true,width:320};
+ else if (navigator.userAgent.match(/iPad/i))
+ cap={touch:true,width:768,forcedidle:10}; // Forced idle time is needed for correct framerate calculation.
+ else
+ cap={zoom:2};
+
+ cap.canaudio=!!(document.createElement('audio').canPlayType);
+
+ if (cap.canaudio) {
+ if (navigator.userAgent.match(/iPad/i)||navigator.userAgent.match(/iPhone/i)||navigator.userAgent.match(/iPod/i)) {
+ cap.audiocompatmode=2; // Single audio per time, so compatibility mode is needed. Plays only the "bgmusic" channel.
+ cap.audioteam=1; // Only a member is required in the audioteam.
+ cap.audioisexperimental=true; // Audio is experimental, since limited.
+ } else if (navigator.userAgent.match(/Chrome/i)) {
+ cap.audioteam=3; // Quite low performance on playback responsiveness.
+ } else if (navigator.userAgent.match(/Firefox/i)) {
+ cap.audioteam=1; // Testing smaller audioteam
+ cap.audiopositiondelay=0.3; // Ogg playback is slower 0.3 between MP3 playback. Don't know why :)
+ cap.audiocreatemode=1; // Firefox is stalling while downloading lot of things
+ } else if (navigator.userAgent.match(/Minefield/i)) {
+ cap.audioteam=1; // Testing smaller audioteam
+ cap.audiocreatemode=1; // Firefox is stalling while downloading lot of things
+ // Minefield has fixed the 0.3 delay!
+ } else if (navigator.userAgent.match(/Safari/i)) {
+ cap.audioteam=1; // Testing smaller audioteam
+ cap.audioisexperimental=true; // Only for nightly builds for now
+ } else if (navigator.userAgent.match(/Opera/i)) {
+ cap.audioteam=1; // Testing smaller audioteam
+ cap.audiocreatemode=1; // Do not like audio object cloning very much
+ } else
+ cap.audioisexperimental=true; // Audio is just experimental on all other devices.
+
+ }
+
+ return cap;
+ },
// The default Akihabara initialization. Low-res, low-framerate, zoomed view
- akihabaraInit:function(title) {
- var device=iphopad.getDeviceConfig();
-
- document.title=(title?title:"Akihabara");
+ akihabaraInit:function(data) {
+ if ((typeof data).toLowerCase() == "string") data={title:data};
+ var device=this.getDeviceConfig();
+ var footnotes=["MADE WITH AKIHABARA (C)2010 - GPL2/MIT","Project: www.kesiev.com/akihabara","Sources: github.com/kesiev/akihabara"];
+ document.title=(data.title?data.title:"Akihabara");
+ if (data.splash) {
+ if (data.splash.footnotes)
+ for (var i=0;i<footnotes.length;i++) data.splash.footnotes.push(footnotes[i]);
+ gbox.setSplashSettings(data.splash);
+ }
+ if (!data.splash||(data.splash.minilogo==null)) gbox.setSplashSettings({minilogo:"logo"});
+ if (!data.splash||(data.splash.background==null)) gbox.setSplashSettings({background:"akihabara/splash.png"});
+ if (!data.splash||(data.splash.minimalTime==null)) gbox.setSplashSettings({minimalTime:3000});
+ if (!data.splash||(data.splash.footnotes==null)) gbox.setSplashSettings({footnotes:footnotes});
document.body.style.backgroundColor="#000000";
gbox.setScreenBorder(false);
if (help.geturlparameter("statusbar")) gbox.setStatusBar(1);
if (help.geturlparameter("db")) gbox.setDoubleBuffering(true);
if (help.geturlparameter("noautoskip")) gbox.setAutoskip(null);
if (help.geturlparameter("zoom")) gbox.setZoom(help.geturlparameter("zoom")); else
- if (device.zoom) gbox.setZoom(device.zoom); else
- if (device.width) gbox.setZoom(device.width/320);
+ if (help.isDefined(device.zoom)) gbox.setZoom(device.zoom); else
+ if (help.isDefined(device.width)) gbox.setZoom(device.width/320);
if (help.geturlparameter("fps")) gbox.setFps(help.geturlparameter("fps")*1);
- else gbox.setFps(25);
+ else gbox.setFps((data.fps?data.fps:25));
if (help.geturlparameter("fskip")) gbox.setFrameskip(help.geturlparameter("fskip"));
+ if (help.geturlparameter("forcedidle")) gbox.setForcedIdle(help.geturlparameter("forcedidle")*1);
+ else if (help.isDefined(device.forcedidle)) gbox.setForcedIdle(device.forcedidle);
+
+ gbox.initScreen((data.width?data.width:(data.portrait?240:320)),(data.height?data.height:(data.portrait?320:240)));
+
+ if (help.geturlparameter("showplayers")) gbox.setShowPlayers(help.geturlparameter("showplayers")=="yes");
+ if (help.geturlparameter("canaudio")) gbox.setCanAudio(help.geturlparameter("canaudio")=="yes"); else
+ gbox.setCanAudio(device.canaudio&&(!device.audioisexperimental||gbox.getFlag("experimental")));
+ if (help.geturlparameter("audiocompatmode")) gbox.setAudioCompatMode(help.geturlparameter("audiocompatmode")*1); else
+ if (help.isDefined(device.audiocompatmode)) gbox.setAudioCompatMode(device.audiocompatmode);
+ if (help.geturlparameter("audioteam")) gbox.setAudioTeam(help.geturlparameter("audioteam")*1); else
+ if (help.isDefined(device.audioteam)) gbox.setAudioTeam(device.audioteam);
+ if (help.geturlparameter("loweraudioteam")) gbox.setLowerAudioTeam(help.geturlparameter("loweraudioteam")*1); else
+ if (help.isDefined(device.loweraudioteam)) gbox.setLowerAudioTeam(device.loweraudioteam);
+ if (help.geturlparameter("audiocreatemode")) gbox.setAudioCreateMode(help.geturlparameter("audiocreatemode")*1); else
+ if (help.isDefined(device.audiocreatemode)) gbox.setAudioCreateMode(device.audiocreatemode);
+ if (help.geturlparameter("audiodequeuetime")) gbox.setAudioDequeueTime(help.geturlparameter("audiodequeuetime")*1); else
+ if (help.isDefined(device.audiodequeuetime)) gbox.setAudioDequeueTime(device.audiodequeuetime);
+ if (help.geturlparameter("audiopositiondelay")) gbox.setAudioPositionDelay(help.geturlparameter("audiopositiondelay")*1); else
+ if (help.isDefined(device.audiopositiondelay)) gbox.setAudioPositionDelay(device.audiopositiondelay);
+
- gbox.initScreen(320,240);
-
if (help.geturlparameter("touch")=="no");
else if ((help.geturlparameter("touch")=="yes")||device.touch)
- iphopad.initialize({h:100,dpad:"akihabara/dpad.png",buttons:"akihabara/buttons.png",bg:"akihabara/padbg.png"});
-
- // Debug fonts
- gbox.addImage("_dbf","akihabara/debugfont.png");
- gbox.addFont({id:"_dbf",image:"_dbf",firstletter:" ",tileh:5,tilew:4,tilerow:16,gapx:0,gapy:0});
-
+ switch (data.padmode) {
+ case "fretboard": {
+ iphofretboard.initialize({h:100,bg:"akihabara/fretboard.png"});
+ break;
+ }
+ case "none": {
+ break;
+ }
+ default: {
+ iphopad.initialize({h:100,dpad:"akihabara/dpad.png",buttons:"akihabara/buttons.png",bg:"akihabara/padbg.png"});
+ break;
+ }
+ }
}
}
View
57 akihabara/iphofretboard.js
@@ -0,0 +1,57 @@
+// ---
+// Copyright (c) 2010 Francesco Cottone, http://www.kesiev.com/
+// ---
+
+/**
+ * Fretboard module provides a touchpad for touch-based device (for now, Android and iDevices).
+ */
+var iphofretboard={
+ _swap:false,
+ _frets:["a","b","c","left","right"],
+ _move:["up","down"],
+ _buttons:{up:false,down:false,left:false,right:false,a:false,b:false,c:false},
+ _fretw:0,
+ _moveh:0,
+ _gapx:0,
+ _gapy:0,
+ _listen:function(e) {
+ var nc={up:false,down:false,left:false,right:false,a:false,b:false,c:false};
+ var fret;
+ for (var i=0;i<e.touches.length;i++) {
+ fret=Math.floor((e.touches[i].pageX-iphofretboard._gapx)/iphofretboard._fretw);
+ if (fret<iphofretboard._frets.length)
+ nc[iphofretboard._frets[fret]]=true;
+ else
+ nc[iphofretboard._move[Math.floor((e.touches[i].pageY-iphofretboard._gapy)/iphofretboard._moveh)]]=true;
+ }
+ this._swap=!this._swap;
+ for (var i in nc) {
+ if (nc[i]!=iphofretboard._buttons[i])
+ if (nc[i]) gbox._keydown({fake:true,keyCode:gbox._keymap[i]});
+ else gbox._keyup({fake:true,keyCode:gbox._keymap[i]});
+ }
+
+ iphofretboard._buttons=nc;
+ },
+ initialize:function(data) {
+ var oElement=document.createElement("img");
+ oElement.src=data.bg;
+ oElement.style.margin="auto";
+ oElement.style.padding="0px";
+ oElement.style.height=data.h+"px";
+ oElement.style.width="100%";
+
+ gbox._box.appendChild(oElement);
+
+ oElement.ontouchstart=function(evt) { evt.preventDefault();evt.stopPropagation(); iphofretboard._listen(evt) };
+ oElement.ontouchend=function(evt) { evt.preventDefault();evt.stopPropagation();iphofretboard._listen(evt) };
+ oElement.ontouchmove=function(evt) { evt.preventDefault();evt.stopPropagation();iphofretboard._listen(evt) };
+
+ var sizes=gbox._domgetabsposition(oElement);
+ this._gapx=sizes.x;
+ this._gapy=sizes.y;
+ this._fretw=sizes.w/(this._frets.length+1);
+ this._moveh=sizes.h/(this._move.length);
+ }
+
+}
View
8 akihabara/iphopad.js
@@ -69,14 +69,6 @@ var iphopad={
]
});
},
- getDeviceConfig:function() {
- if (navigator.userAgent.match(/iPhone/i)||navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/Android/i))
- return {touch:true,width:320};
- else if (navigator.userAgent.match(/iPad/i))
- return {touch:true,width:768};
- else
- return {zoom:2};
- },
initialize:function(data) {
var oElement=document.createElement("div");
oElement.style.margin="auto";
View
BIN akihabara/splash.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
166 akihabara/toys.js
@@ -204,11 +204,11 @@ var toys={
if (toys.topview.pixelcollides({x:th.x+th.colx,y:th.y+th.coly+th.colhh},wl)) {
th.touchedleft=true;
th.accx=0;
- th.x=wl.x+wl.colx+wl.colw-th.colx+1;
+ th.x=wl.x+wl.colx+wl.colw-th.colx;
} else if (toys.topview.pixelcollides({x:th.x+th.colx+th.colw,y:th.y+th.coly+th.colhh},wl)) {
th.touchedright=true;
th.accx=0;
- th.x=wl.x+wl.colx-th.colw-th.colx-1;
+ th.x=wl.x+wl.colx-th.colw-th.colx;
}
if (toys.topview.pixelcollides({x:th.x+th.colx+th.colhw,y:th.y+th.coly+th.colh},wl)) {
th.toucheddown=true;
@@ -226,6 +226,7 @@ var toys={
th.touchedfloor=false;
if (th.z>0) {
th.accz=(data==null?0:-Math.floor(th.accz/data.bounce));
+ if (data&&data.audiobounce&&th.accz) gbox.hitAudio(data.audiobounce);
th.z=0;
th.touchedfloor=true;
}
@@ -430,6 +431,8 @@ var toys={
opencounter:0,
opening:false,
closing:false,
+ audiobefore:null,
+ audioafter:null,
doOpen:function() {
this.opening=true;
},
@@ -447,23 +450,36 @@ var toys={
if (obj.closing) obj.opencounter=obj.doorheight;
obj.initialize=function() {
+ this.ismoving=false;
toys.topview.initialize(this);
};
obj[(data.logicon==null?"first":data.logicon)]=function() {
if (this.closing) {
+ if (!this.ismoving) {
+ if (this.audiobefore) gbox.hitAudio(this.audiobefore);
+ this.ismoving=true;
+ }
this.whileMoving();
this.opencounter--;
if (this.opencounter<0) {
+ if (this.audioafter) gbox.hitAudio(this.audioafter);
+ this.ismoving=false;
this.opencounter=0;
this.closing=false;
this.whenClosed();
}
}
if (this.opening) {
+ if (!this.ismoving) {
+ if (this.audiobefore) gbox.hitAudio(this.audiobefore);
+ this.ismoving=true;
+ }
this.whileMoving();
this.opencounter++;
if (this.opencounter>=this.doorheight) {
+ if (this.audioafter) gbox.hitAudio(this.audioafter);
+ this.ismoving=false;
if (!this.whenOpened()) gbox.trashObject(this);
}
}
@@ -1007,6 +1023,7 @@ var toys={
},
jumpKeys:function(th,key) {
if (toys.platformer.canJump(th)&&gbox.keyIsHit(key.jump)&&(th.curjsize==0)) {
+ if (key.audiojump) gbox.hitAudio(key.audiojump);
th.accy=-th.jumpaccy;
th.curjsize=th.jumpsize;
} else if (th.curjsize&&gbox.keyIsHold(key.jump)) { // Jump modulation
@@ -1128,7 +1145,11 @@ var toys={
if (!th.toys[id].subtimer) {
th.toys[id].subtimer=gbox.getFps();
if (data.countdown) {
- if (th.toys[id].time) th.toys[id].time--; else th.toys[id].done=true;
+ if (th.toys[id].time) {
+ th.toys[id].time--;
+ if (data.audiocritical&&(th.toys[id].time<=data.critical))
+ gbox.hitAudio(data.audiocritical);
+ } else th.toys[id].done=true;
} else
th.toys[id].time++;
}
@@ -1163,7 +1184,7 @@ var toys={
ui:{
menu:function(th,id,opt) {
if (toys._maketoy(th,id)||opt.resetmenu) {
- var fd=gbox._fonts[opt.font];
+ var fd=gbox.getFont(opt.font);
th.toys[id].selected=(opt.selected?opt.selected:0);
th.toys[id].ok=0;
var w=0;
@@ -1176,9 +1197,18 @@ var toys={
th.toys[id].fw=fd.tilew;
}
if (!th.toys[id].ok) {
- if (gbox.keyIsHit(opt.keys.up)&&(th.toys[id].selected>0)) th.toys[id].selected--; else
- if (gbox.keyIsHit(opt.keys.down)&&(th.toys[id].selected<opt.items.length-1)) th.toys[id].selected++; else
- if (gbox.keyIsHit(opt.keys.ok)) th.toys[id].ok=1; else
+ if (gbox.keyIsHit(opt.keys.up)&&(th.toys[id].selected>0)) {
+ if (opt.audiooption) gbox.hitAudio(opt.audiooption);
+ th.toys[id].selected--;
+ } else
+ if (gbox.keyIsHit(opt.keys.down)&&(th.toys[id].selected<opt.items.length-1)) {
+ if (opt.audiooption) gbox.hitAudio(opt.audiooption);
+ th.toys[id].selected++;
+ } else
+ if (gbox.keyIsHit(opt.keys.ok)) {
+ if (opt.audioconfirm) gbox.hitAudio(opt.audioconfirm);
+ th.toys[id].ok=1;
+ } else
if (gbox.keyIsHit(opt.keys.cancel)) th.toys[id].ok=-1;
}
gbox.blitAll(gbox.getBufferContext(),gbox.getCanvas("menu-"+id),{dx:opt.x+th.toys[id].fw,dy:opt.y,camera:opt.camera});
@@ -1248,6 +1278,11 @@ var toys={
if (this.w[i].value)
gbox.blitTile(gbox.getCanvasContext(this.surfaceid),{tileset:this.w[i].tileset,tile:this.w[i].frame,dx:this.w[i].dx,dy:this.w[i].dy,fliph:this.w[i].fliph,flipv:this.w[i].flipv});
}
+ if (this.w[i].widget=="gauge") {
+ var ts=gbox.getTiles(this.w[i].tileset);
+ gbox.blitTile(gbox.getCanvasContext(this.surfaceid),{tileset:this.w[i].tileset,tile:0,dx:this.w[i].dx,dy:this.w[i].dy});
+ gbox.blitTile(gbox.getCanvasContext(this.surfaceid),{tileset:this.w[i].tileset,tile:1,dx:this.w[i].dx,dy:this.w[i].dy,w:(this.w[i].value*ts.tilew)/this.w[i].maxvalue});
+ }
}
},
@@ -1310,19 +1345,35 @@ var toys={
},
fullscreen:{
fadeout:function(th,id,tox,data) {
- if (toys._maketoy(th,id)||data.resetfade) th.toys[id].fade=0;
+ if (toys._maketoy(th,id)||data.resetfade) {
+ th.toys[id].fade=0;
+ if (data.audiofade) th.toys[id].stv=gbox.getAudioVolume(data.audiofade);
+ if (data.audiochannelfade) th.toys[id].chv=gbox.getChannelVolume(data.audiochannelfade);
+ }
th.toys[id].fade+=data.fadespeed;
if (th.toys[id].fade>1) th.toys[id].fade=1;
data.alpha=th.toys[id].fade;
gbox.blitFade(tox,data);
+ if (data.audiofade) gbox.setAudioVolume(data.audiofade,th.toys[id].stv*(1-data.alpha));
+ if (data.audiochannelfade)
+ if (data.alpha==1)
+ gbox.stopChannel(data.audiochannelfade);
+ else
+ gbox.setChannelVolume(data.audiochannelfade,th.toys[id].chv*(1-data.alpha));
return toys._toyfrombool(th,id,th.toys[id].fade==1)
},
fadein:function(th,id,tox,data) {
- if (toys._maketoy(th,id)||data.resetfade) th.toys[id].fade=1;
+ if (toys._maketoy(th,id)||data.resetfade) {
+ th.toys[id].fade=1;
+ if (data.audiofade) th.toys[id].stv=gbox.getAudioVolume(data.audiofade);
+ if (data.audiochannelfade) th.toys[id].chv=gbox.getChannelDefaultVolume(data.audiochannelfade);
+ }
th.toys[id].fade-=data.fadespeed;
if (th.toys[id].fade<0) th.toys[id].fade=0;
if (th.toys[id].fade) {
data.alpha=th.toys[id].fade;
+ if (data.audiofade) gbox.setAudioVolume(data.audiofade,th.toys[id].stv*(1-data.alpha));
+ if (data.audiochannelfade) gbox.setChannelVolume(data.audiochannelfade,th.toys[id].chv*(1-data.alpha));
gbox.blitFade(tox,data);
}
return toys._toyfrombool(th,id,th.toys[id].fade==0);
@@ -1358,14 +1409,33 @@ var toys={
if (toys._maketoy(th,id)) {
th.toys[id].x=data.sx;
th.toys[id].y=data.sy;
+ th.toys[id].every=data.every;
+ th.toys[id].played=false;
}
- if ((data.x!=th.toys[id].x)||(data.y!=th.toys[id].y))
- if ((Math.abs(data.x-th.toys[id].x)<=data.speed)&&(Math.abs(data.y-th.toys[id].y)<=data.speed)) {
- th.toys[id].x=data.x;
- th.toys[id].y=data.y;
- } else
- trigo.translate(th.toys[id],trigo.getAngle(th.toys[id],data),data.speed);
- gbox.blitAll(gbox.getBufferContext(),gbox.getImage(data.image),{dx:th.toys[id].x,dy:th.toys[id].y});
+ if (!th.toys[id].every) {
+ if ((data.x!=th.toys[id].x)||(data.y!=th.toys[id].y))
+ if ((Math.abs(data.x-th.toys[id].x)<=data.speed)&&(Math.abs(data.y-th.toys[id].y)<=data.speed)) {
+ th.toys[id].x=data.x;
+ th.toys[id].y=data.y;
+ } else
+ trigo.translate(th.toys[id],trigo.getAngle(th.toys[id],data),data.speed);
+ else
+ if (!th.toys[id].played) {
+ if (data.audioreach) gbox.hitAudio(data.audioreach);
+ th.toys[id].played=true;
+ }
+ th.toys[id].every=data.every;
+ } else th.toys[id].every--;
+ if (data.text)
+ gbox.blitText(gbox.getBufferContext(),{
+ font:data.font,
+ dx:th.toys[id].x,dy:th.toys[id].y,
+ text:data.text
+ });
+ else if (data.tileset)
+ gbox.blitTile(gbox.getBufferContext(),{tileset:data.tileset,tile:data.tile,dx:th.toys[id].x,dy:th.toys[id].y,camera:data.camera,fliph:data.fliph,flipv:data.flipv,alpha:data.alpha});
+ else
+ gbox.blitAll(gbox.getBufferContext(),gbox.getImage(data.image),{dx:th.toys[id].x,dy:th.toys[id].y,alpha:data.alpha});
return toys._toyfrombool(th,id,(data.x==th.toys[id].x)&&(data.y==th.toys[id].y));
},
crossed:function(th,id,data) {
@@ -1381,6 +1451,10 @@ var toys={
gbox.blitAll(gbox.getBufferContext(),gbox.getImage(data.image),{dx:data.x+th.toys[id].gapx,dy:data.y,alpha:data.alpha});
return toys._toybusy(th,id);
} else {
+ if (!th.toys[id].done) {
+ th.toys[id].done=true;
+ if (data.audioreach) gbox.hitAudio(data.audioreach);
+ }
gbox.blitAll(gbox.getBufferContext(),gbox.getImage(data.image),{dx:data.x,dy:data.y});
return toys._toydone(th,id);
}
@@ -1393,7 +1467,10 @@ var toys={
}
if (th.toys[id].zoom!=1) {
th.toys[id].zoom-=data.speed;
- if (th.toys[id].zoom<1) th.toys[id].zoom=1;
+ if (th.toys[id].zoom<=1) {
+ th.toys[id].zoom=1;
+ if (data.audioreach) gbox.hitAudio(data.audioreach);
+ }
gbox.blit(gbox.getBufferContext(),gbox.getImage(data.image),{h:th.toys[id].img.height,w:th.toys[id].img.width,dx:data.x-Math.floor(th.toys[id].img.width*(th.toys[id].zoom-1)/2),dy:data.y-Math.floor(th.toys[id].img.height*(th.toys[id].zoom-1)/2),dh:Math.floor(th.toys[id].img.height*th.toys[id].zoom),dw:Math.floor(th.toys[id].img.width*th.toys[id].zoom),alpha:1/th.toys[id].zoom});
return toys._toybusy(th,id);
} else {
@@ -1413,7 +1490,8 @@ var toys={
if (th.toys[id].cnt>th.toys[id].lh) th.toys[id].gapx=th.toys[id].lh;
gbox.blit(gbox.getBufferContext(),gbox.getImage(data.image),{dh:th.toys[id].cnt,dw:th.toys[id].lw,dx:data.x,dy:data.y+th.toys[id].lh-th.toys[id].cnt,alpha:data.alpha});
if (data.reflex) gbox.blit(gbox.getBufferContext(),gbox.getImage(data.image),{dh:th.toys[id].cnt,dw:th.toys[id].lw,dx:data.x,dy:data.y+th.toys[id].lh,alpha:data.reflex,flipv:true});
-
+ if (th.toys[id].cnt>=th.toys[id].lh)
+ if (data.audioreach) gbox.hitAudio(data.audioreach);
return toys._toybusy(th,id);
} else {
gbox.blitAll(gbox.getBufferContext(),gbox.getImage(data.image),{dx:data.x,dy:data.y});
@@ -1431,6 +1509,7 @@ var toys={
}
if (!th.toys[id].done) {
if (th.toys[id].y+th.toys[id].h>=data.floory) {
+ if (data.audiobounce) gbox.hitAudio(data.audiobounce);
th.toys[id].y=data.floory-th.toys[id].h;
th.toys[id].accy=-Math.ceil(th.toys[id].accy/(data.heavy?data.heavy:2));
th.toys[id].done=(th.toys[id].accy==0);
@@ -1488,6 +1567,7 @@ var toys={
if (th.toys[id].scene.bonus) {
gbox.createCanvas("bonus-"+id,{w:th.toys[id].sceneW,h:(th.toys[id].scene.bonus.length)*(th.toys[id].fd.tileh+th.toys[id].scene.spacing)});
}
+ if (th.toys[id].scene.audiomusic) gbox.hitAudio(th.toys[id].scene.audiomusic);
}
}
if (!th.toys[id].ended) {
@@ -1510,6 +1590,7 @@ var toys={
if (th.toys[id].counter==th.toys[id].scene.speed) {
th.toys[id].letter++;
th.toys[id].counter=0;
+ if (th.toys[id].scene.audio&&!(th.toys[id].letter%3)) gbox.hitAudio(th.toys[id].scene.audio);
var tmp=th.toys[id].letter;
var row=0;
while (tmp>th.toys[id].scene.talk[row].length) {
@@ -1740,6 +1821,55 @@ var toys={