Browse files

committed the 1.1 version from the site. Have fun!

  • Loading branch information...
1 parent c912709 commit 6788a76e69547f51740acfeeed9bf399f83d6031 @kesiev committed Apr 21, 2010
Showing with 15,193 additions and 0 deletions.
  1. +278 −0 GPL-LICENSE.txt
  2. +20 −0 MIT-LICENSE.txt
  3. BIN akihabara/.DS_Store
  4. BIN akihabara/buttons.png
  5. BIN akihabara/debugfont.png
  6. BIN akihabara/dpad.png
  7. BIN akihabara/dpad320.png
  8. +371 −0 akihabara/gamecycle.js
  9. +611 −0 akihabara/gbox.js
  10. +241 −0 akihabara/help.js
  11. +120 −0 akihabara/iphopad.js
  12. BIN akihabara/padbg.png
  13. +109 −0 akihabara/tool.js
  14. +1,735 −0 akihabara/toys.js
  15. +30 −0 akihabara/trigo.js
  16. +686 −0 game-capman.html
  17. +609 −0 game-leavemealone.html
  18. +837 −0 game-solitude.html
  19. +1,247 −0 game-tlol.html
  20. +297 −0 game-tspin.html
  21. BIN resources/.DS_Store
  22. BIN resources/capman/.DS_Store
  23. BIN resources/capman/cels.png
  24. BIN resources/capman/font.png
  25. BIN resources/capman/logo.png
  26. BIN resources/leavemealone/bg1.png
  27. BIN resources/leavemealone/cels.png
  28. BIN resources/leavemealone/ending1.png
  29. BIN resources/leavemealone/font.png
  30. BIN resources/leavemealone/fontbig.png
  31. BIN resources/leavemealone/intro1.png
  32. BIN resources/leavemealone/intro2.png
  33. BIN resources/leavemealone/intro3.png
  34. BIN resources/leavemealone/logo.png
  35. BIN resources/solitude/beach.png
  36. BIN resources/solitude/beach2.png
  37. BIN resources/solitude/cels.png
  38. BIN resources/solitude/font.png
  39. BIN resources/solitude/fontbig.png
  40. BIN resources/solitude/logo.png
  41. BIN resources/solitude/sea.png
  42. BIN resources/solitude/seaside.png
  43. BIN resources/solitude/seaside2.png
  44. BIN resources/tlol/cels.png
  45. BIN resources/tlol/font.png
  46. BIN resources/tlol/fontbig.png
  47. BIN resources/tlol/logo.png
  48. BIN resources/tspin/.DS_Store
  49. BIN resources/tspin/back-01.png
  50. BIN resources/tspin/back-02.png
  51. BIN resources/tspin/back-03.png
  52. BIN resources/tspin/break.png
  53. +2,120 −0 resources/tspin/data/extra/block-resources-allorg.js
  54. +473 −0 resources/tspin/data/extra/dbg-setups.js
  55. +129 −0 resources/tspin/data/rot-ars.js
  56. +30 −0 resources/tspin/data/rot-classic.js
  57. +102 −0 resources/tspin/data/rot-nintendo.js
  58. +47 −0 resources/tspin/data/rot-sega.js
  59. +161 −0 resources/tspin/data/rot-srs.js
  60. +54 −0 resources/tspin/data/rot-tengen.js
  61. +71 −0 resources/tspin/data/sim-gb.js
  62. +77 −0 resources/tspin/data/sim-nes.js
  63. +175 −0 resources/tspin/data/sim-sega.js
  64. +320 −0 resources/tspin/data/sim-tds.js
  65. +101 −0 resources/tspin/data/sim-tengen.js
  66. +177 −0 resources/tspin/data/sim-tgm.js
  67. +737 −0 resources/tspin/data/sim-tgm2.js
  68. +679 −0 resources/tspin/data/sim-tgm3.js
  69. BIN resources/tspin/digits.png
  70. +373 −0 resources/tspin/engine/block-resources.js
  71. +2,176 −0 resources/tspin/engine/block.js
  72. BIN resources/tspin/field-tds.png
  73. BIN resources/tspin/fields.png
  74. BIN resources/tspin/font.png
  75. BIN resources/tspin/font2.png
  76. BIN resources/tspin/font3.png
  77. BIN resources/tspin/gb-blocks-small.png
  78. BIN resources/tspin/gb-blocks.png
  79. BIN resources/tspin/grade.png
  80. BIN resources/tspin/hanabi_blue.png
  81. BIN resources/tspin/hanabi_green.png
  82. BIN resources/tspin/hanabi_orange.png
  83. BIN resources/tspin/hanabi_purple.png
  84. BIN resources/tspin/hanabi_red.png
  85. BIN resources/tspin/hanabi_waterblue.png
  86. BIN resources/tspin/hanabi_yellow.png
  87. BIN resources/tspin/logo.png
  88. BIN resources/tspin/medal.png
  89. BIN resources/tspin/medal_ti.png
  90. BIN resources/tspin/miscblits.png
  91. BIN resources/tspin/nds-blocks-small.png
  92. BIN resources/tspin/nds-blocks.png
  93. BIN resources/tspin/nes-blocks-small.png
  94. BIN resources/tspin/nes-blocks.png
  95. BIN resources/tspin/perase5.png
  96. BIN resources/tspin/sega-blocks-small.png
  97. BIN resources/tspin/sega-blocks.png
  98. BIN resources/tspin/tds-spark.png
  99. BIN resources/tspin/tengen-blocks-small.png
  100. BIN resources/tspin/tengen-blocks.png
  101. BIN resources/tspin/text2.png
  102. BIN resources/tspin/tgm-blocks-small.png
  103. BIN resources/tspin/tgm-blocks.png
  104. BIN resources/tspin/world-blocks-small.png
  105. BIN resources/tspin/world-blocks.png
  106. BIN resources/tspin/wp.png
View
278 GPL-LICENSE.txt
@@ -0,0 +1,278 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
View
20 MIT-LICENSE.txt
@@ -0,0 +1,20 @@
+Copyright (c) 2010 Francesco Cottone, http://www.kesiev.com/
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
BIN akihabara/.DS_Store
Binary file not shown.
View
BIN akihabara/buttons.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN akihabara/debugfont.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN akihabara/dpad.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN akihabara/dpad320.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
371 akihabara/gamecycle.js
@@ -0,0 +1,371 @@
+// ---
+// Copyright (c) 2010 Francesco Cottone, http://www.kesiev.com/
+// ---
+
+ var gamecycle={
+ createMaingame:function(id,group) {
+ return gbox.addObject({
+ id:id,
+ group:group,
+ counter:0,
+ difficulty:0,
+
+ step:100,
+ isready:false,
+
+ hud:{},
+
+ // OVERRIDABLE
+
+ changeLevel:function() { },
+ newLife:function() { },
+
+ // Level intro animation
+
+ gameIntroAnimation:function(reset) {
+ if (reset) {
+ 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});
+ }
+ },
+
+ levelIntroAnimation:function(reset) {
+ if (reset) {
+ toys.resetToy(this,"default-blinker");
+ } else {
+ gbox.blitFade(gbox.getBufferContext(),{alpha:1});
+ return toys.text.blink(this,"default-blinker",gbox.getBufferContext(),{font:"small",text:"GET READY!",valign:gbox.ALIGN_MIDDLE,halign:gbox.ALIGN_CENTER,dx:0,dy:0,dw:gbox.getScreenW(),dh:gbox.getScreenH(),blinkspeed:5,times:6});
+ }
+ },
+
+ // Life intro animation
+ newlifeIntroAnimation:function(reset) {
+ if (reset) {
+ toys.resetToy(this,"default-blinker");
+ } else {
+ gbox.blitFade(gbox.getBufferContext(),{alpha:1});
+ return toys.text.fixed(this,"default-blinker",gbox.getBufferContext(),{font:"small",text:"GET READY!",valign:gbox.ALIGN_MIDDLE,halign:gbox.ALIGN_CENTER,dx:0,dy:0,dw:gbox.getScreenW(),dh:gbox.getScreenH(),time:30});
+ }
+ },
+
+ // gameover animation
+ gameoverIntroAnimation:function(reset) {
+ if (reset) {
+ toys.resetToy(this,"default-blinker");
+ } else {
+ gbox.blitFade(gbox.getBufferContext(),{alpha:1});
+ return toys.text.fixed(this,"default-blinker",gbox.getBufferContext(),{font:"small",text:"GAME OVER",valign:gbox.ALIGN_MIDDLE,halign:gbox.ALIGN_CENTER,dx:0,dy:0,dw:gbox.getScreenW(),dh:gbox.getScreenH(),time:50});
+ }
+ },
+
+ // game title animation
+ gameTitleIntroAnimation:function(reset) {
+ if (!reset) {
+ 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});
+ }
+ },
+
+ // End level animation
+ endlevelIntroAnimation:function(reset) {
+ if (reset) {
+ toys.resetToy(this,"default-blinker");
+ } else {
+ return toys.text.blink(this,"default-blinker",gbox.getBufferContext(),{font:"small",text:"WELL DONE!",valign:gbox.ALIGN_MIDDLE,halign:gbox.ALIGN_CENTER,dx:0,dy:0,dw:gbox.getScreenW(),dh:gbox.getScreenH(),blinkspeed:5,times:10});
+ }
+ },
+
+ // Game ending
+ gameEndingIntroAnimation:function(reset) {
+ if (reset) {
+ toys.resetToy(this,"default-blinker");
+ } else {
+ gbox.blitFade(gbox.getBufferContext(),{alpha:1});
+ return toys.text.blink(this,"default-blinker",gbox.getBufferContext(),{font:"small",text:"CONGRATULATIONS!",valign:gbox.ALIGN_MIDDLE,halign:gbox.ALIGN_CENTER,dx:0,dy:0,dw:gbox.getScreenW(),dh:gbox.getScreenH(),blinkspeed:5,times:10});
+ }
+ },
+
+ // PRESS START
+ pressStartIntroAnimation:function(reset) {
+ if (reset) {
+ toys.resetToy(this,"default-blinker");
+ } else {
+ toys.text.blink(this,"default-blinker",gbox.getBufferContext(),{font:"small",text:"PRESS A TO START",valign:gbox.ALIGN_MIDDLE,halign:gbox.ALIGN_CENTER,dx:0,dy:Math.floor(gbox.getScreenH()/3),dw:gbox.getScreenW(),dh:Math.floor(gbox.getScreenH()/3)*2,blinkspeed:10});
+ return gbox.keyIsHit("a");
+ }
+ },
+
+ // Decides if the game is over
+ gameIsOver:function() { return true; },
+
+ // Actions done during the game (i.e. stage is clear or other ending conditions)
+ gameEvents:function() {
+
+ },
+
+ gameMenu:function(reset) {
+ if (reset) {
+ 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.getToyValue(this,"difficulty","ok") == -1) return -1;
+ else {
+ this.difficulty=toys.getToyValue(this,"difficulty","selected");
+ return true;
+ }
+ }
+ return false;
+ }
+ },
+
+ // CHECK
+
+ gameIsHold:function() { // Use this clause to check collision and kill player: if true the level is changing
+ return (this.step==400)||(this.step==401);
+ },
+
+ isCompleted:function() {
+ return (this.step==800);
+ },
+
+ // GAME CYCLE
+
+ getNextLevel:function() {
+ return this._nextlevel;
+ },
+
+ gotoLevel:function(level) {
+ this._nextlevel=level;
+ this.setStep(400);
+ },
+
+ playerDied:function(data) {
+ this._loselife=data;
+ this.setStep(500);
+ },
+
+ gameIsCompleted:function() {
+ this.setStep(800);
+ },
+
+ // PRIVATES
+
+ setStep:function(st) {
+ this.step=st;
+ this.isready=false;
+ },
+
+ _resetGroups:function() {
+ var g=gbox.getGroups();
+ for (var i=0;i<g.length;i++)
+ if (g[i]!=this.group) gbox.clearGroup(g[i]);
+ gbox.soloGroup(this.group);
+ },
+
+ stepIsReady:function() { this.isready=true; },
+ blit:function() {
+ var ok=false;
+ switch (this.step) {
+ case 100:
+ case 101:
+ case 102: { // Press Start / Menu
+ if (!this.isready&&(this.step==100)) {
+ this._resetGroups();
+ this.gameTitleIntroAnimation(true);
+ }
+ this.gameTitleIntroAnimation(false);
+ switch (this.step) {
+ case 100: { // Press to start
+ if (!this.isready) {
+ this.pressStartIntroAnimation(true);
+ this.stepIsReady();
+ }
+ if (this.pressStartIntroAnimation(false)) this.setStep(101);
+ break;
+ }
+ case 101: { // Game menu
+ if (!this.isready) {
+ this.gameMenu(true);
+ this.stepIsReady();
+ }
+
+ var menu=this.gameMenu(false);
+ if (menu)
+ if (menu == -1) this.setStep(100); else this.setStep(102);
+ break;
+ }
+ case 102: { // Fader
+ if (!this.isready) {
+ this._resetGroups();
+ toys.resetToy(this,"fadeout");
+ this.stepIsReady();
+ }
+ if (toys.fullscreen.fadeout(this,"fadeout",gbox.getBufferContext(),{fadespeed:0.05}))
+ this.setStep(200);
+ break;
+ }
+ break;
+ }
+ break;
+ }
+ case 200:// Game intro animation
+
+ case 300:// Start game
+ case 301:// Game is going
+
+ case 400:// Fade out to change level
+ case 401:// Level animation (levelIntroAnimation)
+ case 402:// Fade in to next level
+
+ case 500:// Wait after dead
+ case 501:// Dead fadeout
+
+ case 600:// Next life intro
+ case 601:// New life fadein
+
+ case 700:// Gameover animation
+
+ case 800:// Fade out game ending
+ case 801:// Game ending
+
+ { // Game playing
+ if (!this.isready) {
+ switch (this.step) {
+ case 200: { // Game intro
+ toys.resetToy(this,"fadein");
+ this.level=null;
+ this._nextlevel=null;
+ this.hud=toys.ui.hud("maingamehud");
+
+ this.initializeGame();
+ this.gameIntroAnimation(true);
+
+ break;
+ }
+ case 300: {
+ // Game start
+ this.level=this._nextlevel;
+ gbox.playAllGroups();
+ this.changeLevel(this._nextlevel);
+ }
+ case 800:
+ case 400:{
+ this.endlevelIntroAnimation(true);
+ toys.resetToy(this,"fadeout");
+ break;
+ }
+ case 501: {
+ toys.resetToy(this,"fadeout");
+ break;
+ }
+ case 401: {
+ gbox.soloGroup(this.group);
+ this.levelIntroAnimation(true);
+ break;
+ }
+ case 402: {
+ toys.resetToy(this,"fadein");
+ this.level=this._nextlevel;
+ gbox.playAllGroups();
+ this.changeLevel(this._nextlevel);
+ break;
+ }
+ case 600: {
+ gbox.soloGroup(this.group);
+ this.newlifeIntroAnimation(true);
+ break;
+ }
+ case 500: {
+ this._loselife.counter=0;
+ break;
+ }
+ case 601: {
+ toys.resetToy(this,"fadein");
+ this.newLife();
+ gbox.playAllGroups();
+ break;
+ }
+ case 700: {
+ gbox.soloGroup(this.group);
+ this.gameoverIntroAnimation(true);
+ break;
+ }
+ case 801: {
+ gbox.soloGroup(this.group);
+ this.gameEndingIntroAnimation(true);
+ break;
+ }
+ }
+ this.stepIsReady();
+ }
+
+ switch (this.step) {
+ case 200: { // Game intro
+ if (this.gameIntroAnimation(false)) this.setStep(300);
+ break;
+ }
+ 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.setStep(301);
+ break;
+ }
+ case 301: { // Ingame stuff
+ this.gameEvents();
+ break;
+ }
+ case 400: { // Fade out before changing the level
+ if (this.endlevelIntroAnimation(false))
+ if (toys.fullscreen.fadeout(this,"fadeout",gbox.getBufferContext(),{fadespeed:0.05})) this.setStep(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.setStep(801);
+ break;
+ }
+ case 501: { // Fade out after dead
+ if (toys.fullscreen.fadeout(this,"fadeout",gbox.getBufferContext(),{fadespeed:0.05}))
+ if (this.gameIsOver())
+ this.setStep(700); // GAME OVER
+ else
+ this.setStep(600);
+ break;
+ }
+ case 401:{ // Level intro animation
+ if (this.levelIntroAnimation(false)) this.setStep(402);
+ break;
+ }
+ case 500: { // Wait after dead
+ this._loselife.counter++;
+ if (this._loselife.counter==this._loselife.wait) this.setStep(501);
+ break;
+ }
+ case 600:{ // New life intro
+ if (this.newlifeIntroAnimation(false)) this.setStep(601);
+ break;
+ }
+ case 700:{ // gameover
+ if (this.gameoverIntroAnimation(false)) this.setStep(100); // Restart game
+ break;
+ }
+ case 801:{ // Game ending
+ if (this.gameEndingIntroAnimation(false)) {
+ this._loselife={ending:true};
+ this.setStep(700); // Game over
+ }
+ break;
+ }
+ }
+
+ this.hud.blit();
+ break;
+ }
+ }
+ }
+ });
+ }
+ }
View
611 akihabara/gbox.js
@@ -0,0 +1,611 @@
+// ---
+// Copyright (c) 2010 Francesco Cottone, http://www.kesiev.com/
+// ---
+
+ var dynalist={
+ create:function() {
+ return {
+ first:null,
+ last:null,
+ data:[],
+ dl:0,
+ gar:[],
+ disconnect:function(obd) {
+ if (this.data[obd].__first!=null) this.data[this.data[obd].__first].__next=this.data[obd].__next; else this.first=this.data[obd].__next;
+ if (this.data[obd].__next!=null) this.data[this.data[obd].__next].__first=this.data[obd].__first; else this.last=this.data[obd].__first;
+ },
+ addObject:function(obj,prio) {
+ var nid=this.gar.pop();
+ if (nid==null) {
+ nid=this.dl;
+ this.dl++;
+ }
+ if (this.first==null) { // First element
+ obj.__next=null;
+ obj.__first=null;
+ this.first=nid;
+ this.last=nid;
+ } else { // Chain next
+ var i=this.first;
+ while (i!=null)
+ if (this.data[i].__prio>prio) break; else i=this.data[i].__next;
+ if (i==null) { // if last, chain in queue
+ obj.__next=null;
+ obj.__first=this.last;
+ this.data[this.last].__next=nid;
+ this.last=nid;
+ } else { // else reconnect objects
+ obj.__first=this.data[i].__first;
+ obj.__next=i;
+ this.data[i].__first=nid;
+ if (obj.__first!=null) this.data[obj.__first].__next=nid; else this.first=nid;
+ }
+
+ }
+ obj.__prio=prio;
+ obj.__id=nid;
+ this.data[nid]=obj;
+ return nid;
+ },
+ setPrio:function(obd,prio) {
+ if (this.data[obd].__prio==prio) return;
+ if (this.first!=this.last)
+ if (this.data[obd].__prio<prio) {
+ if (this.data[obd].__id!=this.last) {
+ var i=this.data[obd].__next;
+ while (i!=null)
+ if (this.data[i].__prio>=prio) break; else i=this.data[i].__next;
+ if ((i==null)||(this.data[i].__first!=this.data[obd].__id)) {
+ // disconnect
+ this.disconnect(obd);
+ // Reconnect
+ if (i==null) {
+ this.data[this.last].__next=this.data[obd].__id;
+ this.data[obd].__first=this.last;
+ this.data[obd].__next=null;
+ this.last=this.data[obd].__id;
+ } else {
+ this.data[obd].__first=this.data[i].__first;
+ this.data[obd].__next=i;
+ this.data[i].__first=this.data[obd].__id;
+ if (this.data[obd].__first!=null) this.data[this.data[obd].__first].__next=this.data[obd].__id; else this.first=this.data[obd].__id;
+ }
+ }
+ }
+ } else {
+ if (this.data[obd].__id!=this.first) {
+ var i=this.data[obd].__first;
+ while (i!=null)
+ if (this.data[i].__prio<=prio) break; else i=this.data[i].__first;
+ if ((i==null)||(this.data[i].__next!=this.data[obd].__id)) {
+ // disconnect
+ this.disconnect(obd);
+ if (i==null) {
+ this.data[this.first].__first=this.data[obd].__id;
+ this.data[obd].__first=null;
+ this.data[obd].__next=this.first;
+ this.first=this.data[obd].__id;
+ } else {
+ this.data[obd].__first=i;
+ this.data[obd].__next=this.data[i].__next;
+ this.data[i].__next=this.data[obd].__id;
+ if (this.data[obd].__next!=null) this.data[this.data[obd].__next].__first=this.data[obd].__id; else this.last=this.data[obd].__id;
+ }
+ }
+ }
+ }
+ this.data[obd].__prio=prio;
+ },
+ remove:function(obd) {
+ this.disconnect(obd);
+ this.gar.push(this.data[obd].__id);
+ delete this.data[this.data[obd].__id];
+ }
+ }
+ }
+
+ }
+
+ var gbox={
+ // CONSTANTS
+ ALIGN_CENTER:0,
+ ALIGN_MIDDLE:0,
+ ALIGN_RIGHT:1,
+ ALIGN_BOTTOM:1,
+ COLOR_BLACK:'rgb(0,0,0)',
+ COLOR_WHITE:'rgb(255,255,255)',
+ ZINDEX_LAYER:-1,
+
+ // VARS
+ _autoid:0,
+ _keyboard:[],
+ _keymap:{
+ up:38,
+ down:40,
+ right:39,
+ left:37,
+ a:90,
+ b:88,
+ c:67
+ },
+ _fonts:{},
+ _count:0,
+ _countloaded:0,
+ _tiles:{},
+ _images:{},
+ _loaded:function() {
+ gbox._countloaded++;
+ },
+ _camera:{},
+ _screen:0,
+ _screenposition:0,
+ _keyboardpicker:0,
+ _screenh:0,
+ _screenw:0,
+ _screenhh:0,
+ _screenhw:0,
+ _zoom:1,
+ _canvas:{},
+ _objects:{},
+ _groups:[],
+ _renderorder:[],
+ _groupplay:{},
+ _actionqueue:["first","then","blit","after"], // initialize is executed once
+ _mspf:0,
+ _fps:0,
+ _gametimer:0,
+ _frameskip:0,
+ _autoskip:{min:0,max:5,lowidle:0,hiidle:5}, // minimum frameskip, maximum frameskip, minimum idle time allowed for increasing frameskip, maximum idle time allowed for decreasing frameskip
+ _fskid:0,
+ _statbar:0,
+ _border:0,
+ _garbage:[],
+ _zindexch:[],
+ _framestart:0,
+ _zindex:dynalist.create(),
+ _db:false,
+ _safedrawimage:function(tox,img,sx,sy,sw,sh,dx,dy,dw,dh) {
+ 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);
+ },
+ _keydown:function(e){
+ var key=(e.fake||window.event?e.keyCode:e.which);
+ if (!gbox._keyboard[key]) gbox._keyboard[key]=1;
+ },
+ _keyup:function(e){
+ var key=(e.fake||window.event?e.keyCode:e.which);
+ gbox._keyboard[key]=-1;
+ },
+ _resetkeys:function() {
+ for (var key in gbox._keymap)
+ gbox._keyup({fake:1,keyCode:gbox._keymap[key]});
+ },
+ _showkeyboardpicker:function(){
+ gbox._keyboardpicker.value="Click/Tap here to enable the keyboard";
+ gbox._keyboardpicker.style.left=(gbox._screenposition.x+5)+"px";
+ gbox._keyboardpicker.style.top=(gbox._screenposition.y+5)+"px";
+ gbox._keyboardpicker.style.width=(gbox._screenposition.w-10)+"px";
+ gbox._keyboardpicker.style.height="30px";
+ this._keyboardpicker.style.border="1px dashed white";
+ this._keyboardpicker.readOnly=null;
+ },
+ _hidekeyboardpicker:function(){
+ this._keyboardpicker.style.zIndex=100;
+ this._keyboardpicker.readOnly="yes";
+ this._keyboardpicker.style.position="absolute";
+ this._keyboardpicker.style.textAlign="center";
+ this._keyboardpicker.style.backgroundColor="#000000";
+ this._keyboardpicker.style.color="#fefefe";
+ this._keyboardpicker.style.cursor="pointer";
+ this._keyboardpicker.value="";
+ this._keyboardpicker.style.left="0px";
+ this._keyboardpicker.style.top="0px";
+ this._keyboardpicker.style.height="0px";
+ this._keyboardpicker.style.width="0px";
+ this._keyboardpicker.style.border="0px";
+ this._keyboardpicker.style.padding="0px";
+ this._keyboardpicker.style.margin="0px";
+ },
+ _domgetabsposition:function(oElement) {
+ var sizes={x:0,y:0,h:0,w:0};
+ sizes.h=oElement.offsetHeight;
+ sizes.w=oElement.offsetWidth;
+ while( oElement != null) {
+ sizes.y += oElement.offsetTop;
+ sizes.x += oElement.offsetLeft;
+ oElement = oElement.offsetParent;
+ }
+ return sizes;
+ },
+ setStatusBar:function(a) { this._statbar=a },
+ setScreenBorder:function(a) { this._border=a},
+ initScreen:function(w,h) {
+ document.body.style.textAlign="center";
+ var container=document.createElement("div");
+ container.style.width="100%";
+ container.style.height="100%";
+ container.style.display="table";
+ this._box=document.createElement("div");
+ this._box.style.display="table-cell";
+ this._box.style.width="100%";
+ this._box.style.textAlign="center";
+ this._box.style.verticalAlign="middle";
+
+ this._screen=document.createElement("canvas");
+ if (this._border) this._screen.style.border="1px solid black";
+ this._screen.setAttribute('height',h);
+ this._screen.setAttribute('width',w);
+ this._screen.style.width=(w*this._zoom)+"px";
+ this._screen.style.height=(h*this._zoom)+"px";
+ this._screenh=h;
+ this._screenw=w;
+ this._screenhh=Math.floor(h/2);
+ this._screenhw=Math.floor(w/2);
+ this._camera.x=0;
+ this._camera.y=0;
+ this._camera.h=h;
+ this._camera.w=w;
+ this._box.appendChild(this._screen);
+ container.appendChild(this._box);
+ document.body.appendChild(container);
+
+ this.createCanvas("_buffer");
+ window.addEventListener('keydown', this._keydown,false);
+ window.addEventListener('keyup', this._keyup,false);
+ if (this._statbar) {
+ this._statbar=document.createElement("div");
+ if (this._border) this._statbar.style.border="1px solid black";
+ this._statbar.style.margin="auto";
+ this._statbar.style.backgroundColor="#ffffff";
+ this._statbar.style.fontSize="10px";
+ this._statbar.style.fontFamily="sans-serif";
+ this._statbar.style.width=(w*this._zoom)+"px";
+ this._box.appendChild(this._statbar);
+ }
+ // Keyboard support on devices that needs focus (like iPad) - actually is not working for a bug on WebKit's "focus" command.
+ this._keyboardpicker=document.createElement("input");
+ this._keyboardpicker.onclick=function(evt) { gbox._hidekeyboardpicker();evt.preventDefault();evt.stopPropagation();};
+ this._hidekeyboardpicker(this._keyboardpicker);
+
+ gbox._box.appendChild(this._keyboardpicker);
+ gbox._screen.ontouchstart=function(evt) { gbox._screenposition=gbox._domgetabsposition(gbox._screen);if (evt.touches[0].pageY-gbox._screenposition.y<30) gbox._showkeyboardpicker();else gbox._hidekeyboardpicker();evt.preventDefault();evt.stopPropagation();};
+ gbox._screen.ontouchend=function(evt) {evt.preventDefault();evt.stopPropagation();};
+ 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();};
+ },
+ setDoubleBuffering:function(db){this._db=db},
+ setStatBar:function(txt){ if (gbox._statbar) this._statbar.innerHTML=(txt?txt:"&nbsp")},
+ setFps:function(f){
+ this._fps=f;
+ this._mspf=Math.floor(1000/f)
+ },
+ getFps:function() { return this._fps },
+ setAutoskip:function(f){this._autoskip=f},
+ setFrameskip:function(f){this._frameskip=f},
+ getScreenH:function(){return this._screenh},
+ getScreenW:function(){return this._screenw},
+ getScreenHH:function(){return this._screenhh},
+ getScreenHW:function(){return this._screenhw},
+ setZoom:function(z) { this._zoom=z},
+ setCallback:function(cb) { this._cb=cb; },
+ _playobject:function(g,obj,a) {
+ if (gbox._objects[g][obj].initialize) {
+ gbox._objects[g][obj].initialize(obj);
+ delete gbox._objects[g][obj].initialize;
+ }
+ 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]]++;
+
+ 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));
+ },
+ debugGetstats:function() {
+ var statline="Idle: "+gbox._framestart+"/"+gbox._mspf+(gbox._frameskip>0?" ("+gbox._frameskip+"skip)":"")+" | ";
+ var cnt=0;
+ for (var g=0;g<gbox._groups.length;g++)
+ if (gbox._groupplay[gbox._groups[g]]) {
+ cnt=0;
+ for (var obj in gbox._objects[gbox._groups[g]]) cnt++;
+ if (cnt) statline+=gbox._groups[g]+"["+cnt+"] ";
+ }
+ /*
+ statline+="<br><br>";
+ var id=gbox._zindex.first;
+ while (id!=null) {
+ if (gbox._groupplay[gbox._zindex.data[id].g]) statline+=gbox._zindex.data[id].g+" | "+gbox._zindex.data[id].o+" ("+gbox._zindex.data[id].__prio+")<br>";
+ id=gbox._zindex.data[id].__next;
+ }
+ */
+ gbox.setStatBar(statline);
+ },
+ setZindex:function(th,z) {
+ if ((th.__zt==null)||(th.zindex!=z)) {
+ th.zindex=z;
+ this._zindexch.push({o:{g:th.group,o:th.id},z:z});
+ }
+ },
+ keyIsHit:function(id) { return this._keyboard[this._keymap[id]]==1},
+ keyIsPressed:function(id) { return this._keyboard[this._keymap[id]]>0},
+ keyIsHold:function(id) { return this._keyboard[this._keymap[id]]>1},
+ keyIsReleased:function(id) { return this._keyboard[this._keymap[id]]==-1},
+ getCamera:function() { return this._camera; },
+ setCameraY:function(y,viewdata) {
+ this._camera.y=y;
+ if (this._camera.y+this._camera.h>viewdata.h) this._camera.y=viewdata.h-this._screenh;
+ if (this._camera.y<0) this._camera.y=0;
+ },
+ setCameraX:function(x,viewdata) {
+ this._camera.x=x;
+ if (this._camera.x+this._camera.w>viewdata.w) this._camera.x=viewdata.w-this._screenw;
+ if (this._camera.x<0) this._camera.x=0;
+ },
+ centerCamera:function(data,viewdata) {
+ 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;
+ this._groupplay[gbox.ZINDEX_LAYER]=true;
+ for (var i=0;i<g.length;i++)
+ if (!this._objects[g[i]]) {
+ this._objects[g[i]]={};
+ this._groupplay[g[i]]=true;
+ this._renderorder[i]=g[i];
+ }
+ },
+ setRenderOrder:function(g) { this._renderorder=g; },
+ playGroup:function(gid){this._groupplay[gid]=true;},
+ stopGroup:function(gid){this._groupplay[gid]=false;},
+ toggleGroup:function(gid){this._groupplay[gid]=!this._groupplay[gid];},
+ soloGroup:function(gid) {
+ for (var i=0;i<this._groups.length;i++)
+ if (this._groups[i]==gid) this.playGroup(this._groups[i]); else this.stopGroup(this._groups[i]);
+ },
+ playAllGroups:function() { for (var i=0;i<this._groups.length;i++) this.playGroup(this._groups[i]); },
+ clearGroup:function(group) {
+ for (var obj in this._objects[group]) {
+ if (this._objects[group][obj].__zt!=null) this._zindex.remove(this._objects[group][obj].__zt);
+ delete this._objects[group][obj];
+ }
+ },
+ playGroups:function(gid){for (var i=0;i<gid.length;i++)this.playGroup(gid[i])},
+ stopGroups:function(gid){for (var i=0;i<gid.length;i++)this.stopGroup(gid[i])},
+ toggleGroups:function(gid){for (var i=0;i<gid.length;i++)this.toggleGroup(gid[i])},
+ getObject:function(group,id) {return this._objects[group][id]},
+ addFont:function(data) {
+ data.tilehh=Math.floor(data.tileh/2);
+ data.tilehw=Math.floor(data.tilew/2);
+ this._fonts[data.id]=data;
+ this._fonts[data.id].firstascii=data.firstletter.charCodeAt(0);
+ },
+ getFont:function(id) {
+ return this._fonts[id];
+ },
+ trashObject:function(obj) {
+ if (!this._garbage[obj.group]) this._garbage[obj.group]={};
+ this._garbage[obj.group][obj.id]=1;
+ obj.__trashing=true;
+ },
+ purgeGarbage:function() {
+ for (var group in this._garbage)
+ for (var id in this._garbage[group]) {
+ if (this._objects[group][id].__zt!=null)
+ this._zindex.remove(this._objects[group][id].__zt)
+ delete this._objects[group][id];
+ }
+ gbox._garbage={};
+ },
+ trashGroup:function(group) {
+ if (!this._garbage[group]) this._garbage[group]={};
+ for (var obj in this._objects[group])
+ this._garbage[group][obj]=1;
+ },
+ objectIsTrash:function(o) { return o.__trashing },
+ addObject:function(data) {
+ // Extras
+ if (!data.id) {
+ data.id="obj-"+this._autoid;
+ this._autoid=(this._autoid+1)%1000;
+ }
+ if (data.tileset) {
+ if (data.h==null) data.h=this._tiles[data.tileset].tileh;
+ if (data.w==null) data.w=this._tiles[data.tileset].tilew;
+ if (data.hw==null) data.hw=this._tiles[data.tileset].tilehw;
+ if (data.hh==null) data.hh=this._tiles[data.tileset].tilehh;
+ }
+ this._objects[data.group][data.id]=data;
+ if (data.zindex!=null)
+ this.setZindex(this._objects[data.group][data.id],data.zindex);
+ return this._objects[data.group][data.id];
+ },
+ 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._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));
+ },
+ 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);
+ },
+ 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] },
+ 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();
+ }
+ },
+ _implicitsargs:function(data) {
+ if (data.camera) {
+ data.dx-=this._camera.x;
+ data.dy-=this._camera.y;
+ }
+ if (data.sourcecamera) {
+ data.x=this._camera.x*(data.parallaxx?data.parallaxx:1);
+ data.y=this._camera.y*(data.parallaxy?data.parallaxy:1);
+ }
+ },
+ blitTile:function(tox,data) {
+ if (tox==null) return;
+ var ts=this._tiles[data.tileset];
+ var img=this.getImage(ts.image);
+ this._implicitsargs(data);
+ tox.save();
+ tox.globalAlpha=(data.alpha?data.alpha:1);
+ tox.translate((data.fliph?ts.tilew:0), (data.flipv?ts.tileh:0)); tox.scale((data.fliph?-1:1), (data.flipv?-1:1));
+ this._safedrawimage(tox,img, ts.gapx+(ts.tilew*(data.tile%ts.tilerow)),ts.gapy+(ts.tileh*Math.floor(data.tile/ts.tilerow)),(data.w==null?ts.tilew:data.w),(data.h==null?ts.tileh:data.h),data.dx*(data.fliph?-1:1),data.dy*(data.flipv?-1:1),(data.w?data.w:ts.tilew),(data.h?data.h:ts.tileh));
+ tox.restore();
+ },
+ blitAll:function(tox,image,data) {
+ if (tox==null) return;
+ this._implicitsargs(data);
+ 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));
+ tox.restore();
+ },
+ blit:function(tox,image,data) {
+ if (tox==null) return;
+ this._implicitsargs(data);
+ tox.save();
+ tox.globalAlpha=(data.alpha?data.alpha:1);
+ tox.translate((data.fliph?data.dw:0), (data.flipv?data.dh:0)); tox.scale((data.fliph?-1:1), (data.flipv?-1:1));
+ this._safedrawimage(tox,image,(data.x?data.x:0), (data.y?data.y:0),(data.w?data.w:data.dw),(data.h?data.h:data.dh),data.dx*(data.fliph?-1:1),data.dy*(data.flipv?-1:1),data.dw,data.dh);
+ tox.restore();
+ },
+ blitTilemap:function(tox,data) {
+ if (tox==null) return;
+ var ts=this._tiles[data.tileset];
+ for (var y=0;y<data.map.length;y++)
+ for (var x=0;x<data.map[y].length;x++)
+ if (data.map[y][x]!=null) this.blitTile(tox,{tileset:data.tileset,tile:data.map[y][x],dx:x*ts.tilew,dy:y*ts.tilew});
+ },
+ blitText:function(tox,data) {
+ if (tox==null) return;
+ data.text+=""; // Convert to string.
+ var fn=this._fonts[data.font];
+ var tile=0;
+ this._implicitsargs(data);
+ var dx=data.dx;
+ var dy=data.dy;
+ if (data.valign==gbox.ALIGN_BOTTOM) dy = dy+data.dh-fn.tileh;
+ else if (data.valign==gbox.ALIGN_MIDDLE) dy = dy+Math.floor(data.dh/2)-fn.tileh;
+ if (data.halign==gbox.ALIGN_RIGHT) dx = dx+data.dw-(data.text.length*fn.tilew);
+ else if (data.halign==gbox.ALIGN_CENTER) dx = dx+Math.floor((data.dw-(data.text.length*fn.tilew))/2);
+ tox.save();
+ tox.globalAlpha=(data.alpha?data.alpha:1);
+ for (var y=0;y<data.text.length;y++) {
+ tile=data.text.charCodeAt(y)-fn.firstascii;
+ if (tile>=0) {
+ if (data.clear) tox.clearRect(dx+(y*fn.tilew),dy,(data.w?data.w:fn.tilew),(data.h?data.h:fn.tileh));
+ this._safedrawimage(tox,this.getImage(fn.image), fn.gapx+(fn.tilew*(tile%fn.tilerow)),
+ fn.gapy+(fn.tileh*Math.floor(tile/fn.tilerow)),fn.tilew,fn.tileh,dx+(y*fn.tilew),dy,(data.w?data.w:fn.tilew),(data.h?data.h:fn.tileh));
+ }
+ }
+ tox.restore();
+ },
+ blitClear:function(image,data) {
+ if (image==null) return;
+ if (data==null) data={x:0,y:0};
+ this._implicitsargs(data);
+ image.clearRect(data.x,data.y,(data.w==null?image.canvas.width:data.w),(data.h==null?image.canvas.height:data.h));
+ },
+ blitImageToScreen:function(image) {
+ this._screen.getContext("2d").drawImage(image,0,0);
+ },
+ blitFade:function(tox,data) {
+ if (tox) this.blitRect(tox,{x:0,y:0,w:tox.canvas.width,h:tox.canvas.height,alpha:data.alpha,color:data.color});
+ },
+ blitRect:function(tox,data) {
+ if (tox==null) return;
+ tox.save();
+ tox.globalAlpha=(data.alpha?data.alpha:1);
+ tox.fillStyle = (data.color?data.color:gbox.COLOR_BLACK);
+ tox.fillRect(data.x,data.y,data.w,data.h);
+ tox.restore();
+ },
+ collides:function(o1,o2,t) {
+ if (!t) t=0;
+ return !((o1.y+o1.h-1-t<o2.y+t) || (o1.y+t> o2.y+o2.h-1-t) || (o1.x+o1.w-1-t<o2.x+t) || (o1.x+t>o2.x+o2.w-1-t));
+ },
+ pixelcollides:function(o1,o2,t) {
+ 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); }
+ };
+
View
241 akihabara/help.js
@@ -0,0 +1,241 @@
+// ---
+// Copyright (c) 2010 Francesco Cottone, http://www.kesiev.com/
+// ---
+
+ var help={
+
+ // generates numbers from st to ed, skipping skip
+ seq:function(st,ed,skip) {
+ var ret=[];
+ for (var i=st;i<ed;i+=(skip==null?1:skip)) ret.push(i);
+ return ret;
+ },
+
+ // Handle a multiplier like counter. that means, 0=1 / 1=1 / 2=2*mul etc...
+ multiplier:function(v,mul) {
+ return (!v||(v<2)?1:v*(!mul?1:mul));
+ },
+
+ // pad str with heading pad until is "len" long
+ prepad:function(str,len,pad) {
+ str+="";
+ while (str.length<len) str=pad+str;
+ return str;
+ },
+
+ // pad str with tail pad until is "len" long
+ postpad:function(str,len,pad) {
+ str+="";
+ while (str.length<len) str+=pad;
+ return str;
+ },
+
+ // true if "th" is squished by "by"
+ isSquished:function(th,by) {
+ return ((by.accy>0)&&gbox.collides(th,by)&&(Math.abs(th.y-(by.y+by.h))<(th.h/2)))
+ },
+ // Random number
+ random:function(min,range) {
+ return min+Math.floor(Math.random()*range);
+ },
+ // Decides an animation frame.
+ // Args: (number,{speed:<animation speed>,frames:<animation sequence>})
+ // Outs: the frame
+ decideFrame:function(cnt,anim) {
+ return anim.frames[Math.floor(cnt/anim.speed)%anim.frames.length];
+ },
+ // 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
+ getTileInMap:function(x,y,map,ifout,mapid) {
+ if (!mapid) mapid="map";
+ var ts=gbox._tiles[map.tileset];
+ var tx=Math.floor(x/ts.tilew);
+ var ty=Math.floor(y/ts.tileh);
+ if ((ty<0)||(ty>=map[mapid].length)) return ifout; else
+ if ((tx<0)||(tx>=map[mapid][ty].length)) return ifout; else
+ return map[mapid][ty][tx];
+ },
+ // Convert an ascii art array of string to a map. The first argument is the map, the second one is the translation map.
+ // i.e. (["---","- -","---"],[[null," "],[1,"-"]]);
+ asciiArtToMap:function(map,tra) {
+ var sz=tra[0][1].length;
+ var ret=[];
+ var xpos;
+ var pie;
+ for (var y=0;y<map.length;y++) {
+ var row=[];
+ xpos=0;
+ while (xpos<map[y].length) {
+ pie=map[y].substr(xpos,sz);
+ for (var t=0;t<tra.length;t++)
+ if (pie==tra[t][1]) {
+ if (t==0) row.push(null); else row.push(tra[t][0]);
+ break;
+ }
+ xpos+=sz;
+ }
+ ret.push(row);
+ }
+ return ret;
+ },
+
+
+ // Finalize a map definition, setting height and width in pixels etc.
+ // Args: (map)
+ // Outs: finalized map
+ finalizeTilemap:function(map) {
+ var ts=gbox._tiles[map.tileset];
+ map.h=map.map.length*ts.tileh;
+ map.w=map.map[0].length*ts.tilew;
+ map.hw=Math.floor(map.w/2);
+ map.hh=Math.floor(map.h/2);
+ return map;
+ },
+ // Converts a x-coord pixel in a x-coord tile
+ xPixelToTileX:function(map,x,gap) {
+ var ts=gbox._tiles[map.tileset];
+ return Math.floor(x/ts.tilew);
+ },
+ // Converts a x-coord pixel in a x-coord tile
+ yPixelToTileY:function(map,y,gap) {
+ var ts=gbox._tiles[map.tileset];
+ return Math.floor(y/ts.tileh);
+ },
+ // Converts a x-coord in pixel to the x-coord of the corresponding tile column in pixels
+ // Args: (map,x,<gap of the position in tiles>)
+ // Outs: the x coord in pixel of the tile column
+ xPixelToTile:function(map,x,gap) {
+ var ts=gbox._tiles[map.tileset];
+ return (Math.floor(x/ts.tilew)+(gap?gap:0))*ts.tilew;
+ },
+ // Converts a y-coord in pixel to the x-coord of the corresponding tile row in pixels
+ // Args: (map,y,<gap of the position in tiles>)
+ // Outs: the y coord in pixel of the tile row
+ yPixelToTile:function(map,y,gap) {
+ var ts=gbox._tiles[map.tileset];
+ return (Math.floor(y/ts.tileh)+(gap?gap:0))*ts.tileh;
+ },
+ // Limit a value between 2 numbers
+ // Args: (value,<minimal limit>,<maximal limit>)
+ // Outs: the value limited
+ limit:function(v,min,max) {
+ if (v<min) return min; else if (v>max) return max; else return v;
+ },
+ // Subtracts or adds 1 to a value to reach 0. i.e passing -3, outs -2. Passing 3, outs 2
+ // Args: (value)
+ // Outs: new value
+ goToZero:function(v) { return (v?v-(v/Math.abs(v)):0); },
+
+ // Copy a model on a data set if a value is not defined
+ mergeWithModel:function(data,model) {
+ if (data==null) data={};
+ if (model!=null)
+ for (var i in model)
+ if (data[i]==null) data[i]=model[i];
+ return data;
+ },
+
+ // Copy a model into data set
+ copyModel:function(data,model) {
+ if (data==null) data={};
+ if (model!=null)
+ for (var i in model) data[i]=model[i];
+ return data;
+ },
+
+ // Create a model from an object (copies attributes)
+ createModel:function(obj,attrs) {
+ var ret={};
+ for (var i=0;i<attrs.length;i++) ret[attrs[i]]=obj[attrs[i]];
+ return ret;
+ },
+
+ // Clones an objecy
+ cloneObject:function(model) {
+ if (!model) return model;
+ var data={};
+ for (var i in model) data[i]=model[i];
+ return data;
+ },
+
+ // Blit a tile in a map and changes a surface accordingly
+ setTileInMap:function(ctx,tilemap,x,y,tile,map) {
+ var ts=gbox.getTiles(tilemap.tileset);
+ tilemap[(map==null?"map":map)][y][x]=tile;
+ if (tile==null)
+ gbox.blitClear(ctx,{x:x*ts.tilew,y:y*ts.tilew,h:ts.tileh,w:ts.tilew});
+ else
+ gbox.blitTile(ctx,{tileset:tilemap.tileset,tile:tile,dx:x*ts.tilew,dy:y*ts.tilew});
+ },
+
+ // Get the item of an array, if available. Else returns the last one
+ getArrayCapped:function(a,id) {
+ if (id>=a.length) return a[a.length-1]; else return a[id];
+ },
+
+ // Get an item of an array of object, using a field as index. is returned the first entry if the field is not valued.
+ getArrayIndexed:function(a,value,field) {
+ if (a[0][field]==null) return a[0];
+ var i=0;
+ while ((value>a[i][field])&&(i!=a.length-1)) i++;
+ return a[i];
+ },
+
+
+ // Convert frames to minutes, seconds and csecs
+ framestotime:function(frames) {
+ var csec=Math.ceil(frames/gbox.getFps()*100);
+ return this.prepad((Math.floor(csec/6000)%60),2,"0")+":"+this.prepad((Math.floor(csec/100)%60),2,"0")+":"+this.prepad(csec%100,2,"0");
+
+ },
+
+ // get an url parameter
+ geturlparameter:function( name ) {
+ name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
+ var regexS = "[\\?&]"+name+"=([^&#]*)";
+ var regex = new RegExp( regexS );
+ var results = regex.exec( window.location.href );
+ if( results == null )
+ return "";
+ else
+ return results[1];
+ },
+
+ // transform simple object in string, for debug
+ objToStr:function(o) {
+ var ret="";
+ for (var n in o) ret+=n+":["+o[n]+"] ";
+ return ret;
+ },
+
+ // The default Akihabara initialization. Low-res, low-framerate, zoomed view
+ akihabaraInit:function(title) {
+ var device=iphopad.getDeviceConfig();
+
+ document.title=(title?title:"Akihabara");
+ 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.geturlparameter("fps")) gbox.setFps(help.geturlparameter("fps")*1);
+ else gbox.setFps(25);
+ if (help.geturlparameter("fskip")) gbox.setFrameskip(help.geturlparameter("fskip"));
+
+
+ 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});
+
+ }
+ }
View
120 akihabara/iphopad.js
@@ -0,0 +1,120 @@
+// ---
+// Copyright (c) 2010 Francesco Cottone, http://www.kesiev.com/
+// ---
+
+ var iphopad={
+ _buttonsize:50,
+ _buttonsize2:100,
+ _buttonsize3:150,
+ _gapx:0,
+ _gapy:0,
+ _width:0,
+ _height:0,
+ _center:{},
+ _cross:{up:false,down:false,left:false,right:false},
+ _buttons:{a:false,b:false,c:false},
+ _transl:(Math.PI*0.125),
+ _brad:(Math.PI*0.25),
+ _positions:[
+ {up:false,down:false,left:false,right:true},
+ {up:false,down:true,left:false,right:true},
+ {up:false,down:true,left:false,right:false},
+ {up:false,down:true,left:true,right:false},
+ {up:false,down:false,left:true,right:false},
+ {up:true,down:false,left:true,right:false},
+ {up:true,down:false,left:false,right:false},
+ {up:true,down:false,left:false,right:true}
+ ],
+ _swap:false,
+ _listen:function(e) {
+ var nc={up:false,down:false,left:false,right:false};
+ var nb={a:false,b:false,c:false};
+ for (var i=0;i<e.touches.length;i++) {
+ rp={x:e.touches[i].pageX-iphopad._gapx,y:e.touches[i].pageY-iphopad._gapy};
+ if (rp.x<iphopad._height)
+ nc=iphopad._positions[Math.floor(trigo.getAngle(iphopad._center,rp,iphopad._transl)/iphopad._brad)];
+ else if (rp.x>iphopad._width-iphopad._buttonsize)
+ nb.a=true;
+ else if (rp.x>iphopad._width-iphopad._buttonsize2)
+ nb.b=true;
+ else if (rp.x>iphopad._width-iphopad._buttonsize3)
+ nb.c=true;
+
+ }
+ this._swap=!this._swap;
+ for (var i in this._cross) {
+ if (nc[i]!=iphopad._cross[i])
+ if (nc[i]) gbox._keydown({fake:true,keyCode:gbox._keymap[i]});
+ else gbox._keyup({fake:true,keyCode:gbox._keymap[i]});
+ }
+ for (var i in this._buttons) {
+ if (nb[i]!=iphopad._buttons[i])
+ if (nb[i]) gbox._keydown({fake:true,keyCode:gbox._keymap[i]});
+ else gbox._keyup({fake:true,keyCode:gbox._keymap[i]});
+ }
+
+ iphopad._cross=nc;
+ iphopad._buttons=nb;
+ },
+ _fakelisten:function(e) {
+ iphopad._listen({
+ touches:[
+ {
+ pageX:e.clientX,
+ pageY:e.clientY
+ }
+ ]
+ });
+ },
+ 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";
+ oElement.style.padding="0px";
+ oElement.style.height=data.h+"px";
+ oElement.style.width="100%";
+ oElement.style.backgroundImage="url("+data.bg+")";
+ oElement.style.backgroundRepeat="repeat-x";
+
+ var tpad=document.createElement("div");
+ tpad.style.cssFloat="left";
+ tpad.style.padding="0px";
+ tpad.style.margin="0px";
+ tpad.style.height=data.h+"px";
+ tpad.style.width=data.h+"px";
+ tpad.style.backgroundImage="url("+data.dpad+")";
+ tpad.style.backgroundRepeat="no-repeat";
+
+ var bpad=document.createElement("div");
+ bpad.style.cssFloat="right";
+ bpad.style.padding="0px";
+ bpad.style.margin="0px";
+ bpad.style.height=data.h+"px";
+ bpad.style.width=iphopad._buttonsize3+"px";
+ bpad.style.backgroundImage="url("+data.buttons+")";
+ bpad.style.backgroundRepeat="no-repeat";
+
+ oElement.appendChild(tpad);
+ oElement.appendChild(bpad);
+ gbox._box.appendChild(oElement);
+
+ oElement.ontouchstart=function(evt) { evt.preventDefault();evt.stopPropagation(); iphopad._listen(evt) };
+ oElement.ontouchend=function(evt) { evt.preventDefault();evt.stopPropagation();iphopad._listen(evt) };
+ oElement.ontouchmove=function(evt) { evt.preventDefault();evt.stopPropagation();iphopad._listen(evt) };
+ //oElement.onmousemove=function(evt) { iphopad._fakelisten(evt) };
+ var sizes=gbox._domgetabsposition(oElement);
+ this._gapx=sizes.x;
+ this._gapy=sizes.y;
+ this._width=sizes.w;
+ this._height=sizes.h;
+ this._center={x:Math.floor(this._height/2),y:Math.floor(this._height/2)};
+ }
+
+ }
View
BIN akihabara/padbg.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
109 akihabara/tool.js
@@ -0,0 +1,109 @@
+// ---
+// Copyright (c) 2010 Francesco Cottone, http://www.kesiev.com/
+// ---
+
+ var tool={
+ _images:[],
+ _loadedflag:[],
+ _data:{},
+ _count:0,
+ _countloaded:0,
+ _loaded:function(id) {
+ this._loadedflag[id]=true;
+ tool._countloaded++;
+ document.title=tool._countloaded+"/"+tool._count;
+ for (var i=0;i<this._images.length;i++)
+ if (!this._loadedflag[i]) document.title+=this._images[i].src+", ";
+ },
+ _loadall:function() {
+ if (tool._count!=tool._countloaded)
+ setTimeout(tool._loadall,1000);
+ else
+ tool._allloaded();
+ },
+ makecels:function(data) {
+ this._data=data;
+ var id=0;
+ for (var r=0;r<data.rows.length;r++) {
+ for (var i=0;i<data.rows[r].length;i++) {
+ this._images[id]=new Image();
+ this._images[id].addEventListener('load', function(){tool._loaded(this.id)},false);
+ this._images[id].setAttribute("id",id);
+ this._images[id].src=data.rows[r][i].img;
+ this._count++;
+ id++;
+ }
+ }
+ this._loadall();
+ },
+ _allloaded:function() {
+ var data=this._data;
+ var wid=0;
+ var hei=0;
+ var curwid=0;
+ var id=0;
+ for (var r=0;r<data.rows.length;r++) {
+ hei+=this._images[id].height*1;
+ curwid=0;
+ for (var i=0;i<data.rows[r].length;i++) { curwid+=this._images[id].width*1; id++}
+ if (wid<curwid) wid=curwid;
+ }
+
+ var cels=document.createElement("canvas");
+ cels.style.border="1px solid red";
+ cels.setAttribute('height',hei);
+ cels.setAttribute('width',wid);
+ document.body.appendChild(cels);
+ var ctx=cels.getContext("2d");
+
+ var curx=0;
+ var cury=0;
+ id=0;
+ for (var r=0;r<data.rows.length;r++) {
+ curx=0;
+ for (var i=0;i<data.rows[r].length;i++) {
+ ctx.drawImage(this._images[id],curx,cury);
+ if (data.rows[r][i].filter) {
+ if (data.rows[r][i].filter) {
+ var imgd = ctx.getImageData(curx, cury, this._images[id].width, this._images[id].height);
+ var pix = imgd.data;
+
+ // Loop over each pixel and invert the color.
+ for (var z = 0, n = pix.length; z < n; z += 4) {
+ if (data.rows[r][i].filter.replace) {
+ for (var w=0;w<data.rows[r][i].filter.replace.length;w++) {
+
+ repl=data.rows[r][i].filter.replace[w].from;
+ to=data.rows[r][i].filter.replace[w].to;
+ if ((pix[z]==repl.r)&&(pix[z+1]==repl.g)&&(pix[z+2]==repl.b)&&(pix[z+3]==repl.a)) {
+ pix[z ] = to.r;
+ pix[z+1] = to.g;
+ pix[z+2] =to.b;
+ pix[z+3] =to.a;
+ }
+ }
+ }
+ if (data.rows[r][i].filter.color&&(pix[z+3]!=0)) {
+ pix[z ] = data.rows[r][i].filter.color.r;
+ pix[z+1] = data.rows[r][i].filter.color.g;
+ pix[z+2] =data.rows[r][i].filter.color.b;
+ pix[z+3] =data.rows[r][i].filter.color.a;
+ }
+
+ // i+3 is alpha (the fourth element)
+ }
+ ctx.putImageData(imgd, curx, cury);
+
+ }
+ }
+ curx+=this._images[id].width*1;
+ id++;
+ }
+ cury+=this._images[id-1].height*1;
+ }
+
+ }
+
+ }
+
+
View
1,735 akihabara/toys.js
@@ -0,0 +1,1735 @@
+// ---
+// Copyright (c) 2010 Francesco Cottone, http://www.kesiev.com/
+// ---
+
+ var toys={
+
+ // CONSTANTS
+ NOOP:function(){},
+ PUSH_NONE:0,
+ PUSH_LEFT:1,
+ PUSH_RIGHT:2,
+ PUSH_UP:3,
+ PUSH_DOWN:4,
+
+ FACES:["up","right","down","left"],
+ FACES_ANGLE:[trigo.ANGLE_UP,trigo.ANGLE_RIGHT,trigo.ANGLE_DOWN,trigo.ANGLE_LEFT],
+ FACE_UP:0,
+ FACE_RIGHT:1,
+ FACE_DOWN:2,
+ FACE_LEFT:3,
+
+ // Top-view (Zelda-alike) specifics
+
+ topview:{
+ collides:function(fr,to,t) { // Special collision. Counts also the Z
+ if (Math.abs(fr.z,to.z)<5) return gbox.collides({x:fr.x+fr.colx,y:fr.y+fr.coly,h:fr.colh,w:fr.colw},{x:to.x+to.colx,y:to.y+to.coly,h:to.colh,w:to.colw},t); else return false;
+ },
+ pixelcollides:function(fr,to,t) { // Special collision. Counts also the Z
+ return gbox.pixelcollides(fr,{x:to.x+to.colx,y:to.y+to.coly,h:to.colh,w:to.colw},t);
+ },
+ initialize:function(th,data) {
+ help.mergeWithModel(
+ th,
+ help.mergeWithModel(
+ data,
+ {
+ x:0, y:0,
+ z:0,
+ accx:0, accy:0, accz:0,
+ frames:{},
+ shadow:null,
+ maxacc:4, controlmaxacc:4,
+ responsive:0, // Responsiveness
+ weapon:0, // Weapon
+ camera:true,
+ flipv:false, fliph:false,
+ facing:toys.FACE_DOWN,
+ flipside:true,
+ haspushing:false,
+ frame:0,
+ colh:gbox.getTiles(th.tileset).tilehh,
+ colw:gbox.getTiles(th.tileset).tilew,
+ colx:0,
+ staticspeed:0,
+ nodiagonals:false,
+ noreset:false
+ }
+ )
+ );
+ if (th.coly==null) th.coly=gbox.getTiles(th.tileset).tileh-th.colh;
+ th.colhh=Math.floor(th.colh/2);
+ th.colhw=Math.floor(th.colw/2);
+
+ toys.topview.spawn(th);
+ },
+ spawn:function(th,data) {
+ th.xpushing=toys.PUSH_NONE; // user is moving side
+ th.vpushing=toys.PUSH_NONE; // user is moving side
+ th.zpushing=toys.PUSH_NONE; // user is moving side
+ th.counter=0; // self counter
+ th.hittimer=0;
+ th.killed=false;
+ help.copyModel(th,data);
+ gbox.setZindex(th,th.y+th.h); // these object follows the z-index and uses ZINDEX_LAYER
+ },
+ controlKeys:function(th,keys) {
+ var cancelx=false;
+ var cancely=false;
+ var idlex=false;
+ var idley=false;
+
+ if (gbox.keyIsPressed(keys.left)||keys.pressleft) {
+ th.xpushing=toys.PUSH_LEFT;
+ th.facing=toys.FACE_LEFT;
+ if (th.accx>th.responsive) th.accx=th.responsive;
+ if (th.staticspeed) th.accx=-th.staticspeed; else th.accx=help.limit(th.accx-1,-th.controlmaxacc,th.controlmaxacc);
+ if (th.nodiagonals) { cancely=true; idley=true }
+ } else if (gbox.keyIsPressed(keys.right)||keys.pressright) {
+ th.xpushing=toys.PUSH_RIGHT;
+ th.facing=toys.FACE_RIGHT;
+ if (th.accx<-th.responsive) th.accx=-th.responsive;
+ if (th.staticspeed) th.accx=th.staticspeed; else th.accx=help.limit(th.accx+1,-th.controlmaxacc,th.controlmaxacc);
+ if (th.nodiagonals) { cancely=true; idley=true }
+ } else idlex=true;
+
+ if (!cancely&&(gbox.keyIsPressed(keys.up)||keys.pressup)) {
+ th.ypushing=toys.PUSH_UP;
+ th.facing=toys.FACE_UP;
+ if (th.accy>th.responsive) th.accy=th.responsive;
+ if (th.staticspeed) th.accy=-th.staticspeed; else th.accy=help.limit(th.accy-1,-th.controlmaxacc,th.controlmaxacc);
+ if (th.nodiagonals) { cancelx=true; idlex=true; }
+ } else if (!cancely&&(gbox.keyIsPressed(keys.down)||keys.pressdown)) {
+ th.ypushing=toys.PUSH_DOWN;
+ th.facing=toys.FACE_DOWN;
+ if (th.accy<-th.responsive) th.accy=-th.responsive;
+ if (th.staticspeed) th.accy=th.staticspeed; else th.accy=help.limit(th.accy+1,-th.controlmaxacc,th.controlmaxacc);
+ if (th.nodiagonals) { cancelx=true; idlex=true; }
+ } else idley=true;
+
+
+
+ if (idlex) {
+ if (cancelx) th.accx=0;
+ if (cancelx||!th.noreset) th.xpushing=toys.PUSH_NONE;
+ }
+ if (idley) {
+ if (cancely) th.accy=0;
+ if (cancely||!th.noreset) th.ypushing=toys.PUSH_NONE;
+ }
+ },
+ getNextX:function(th) { return th.x+help.limit(th.accx,-th.maxacc,th.maxacc); },
+ getNextY:function(th) { return th.y+help.limit(th.accy,-th.maxacc,th.maxacc); },
+ getNextZ:function(th) { return th.z+help.limit(th.accz,-th.maxacc,th.maxacc); },
+ applyForces:function(th) {
+ th.x=toys.topview.getNextX(th);
+ th.y=toys.topview.getNextY(th);
+ },
+ applyGravity:function(th) {
+ th.z=toys.topview.getNextZ(th);
+ },
+ handleAccellerations:function(th) {
+ if (!th.xpushing) th.accx=help.goToZero(th.accx);
+ if (!th.ypushing) th.accy=help.goToZero(th.accy);
+
+ },
+ handleGravity:function(th) {
+ th.accz++;
+ },
+ setFrame:function(th) {
+ var pref="stand";
+ if (th.xpushing||th.ypushing)
+ if (th.haspushing&&(th.toucheddown||th.touchedup||th.touchedleft||th.touchedright)) pref="pushing"; else pref="moving";
+ if (th.flipside)
+ th.fliph=(th.facing==toys.FACE_RIGHT);
+ th.frame=help.decideFrame(th.counter,th.frames[pref+toys.FACES[th.facing]]);
+ },
+ tileCollision:function(th,map,tilemap,defaulttile,data) {
+
+ th.touchedup=false;
+ th.toucheddown=false;
+ th.touchedleft=false;
+ th.touchedright=false;