main.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /**
  2. * See LICENSE file.
  3. *
  4. * Entry point.
  5. */
  6. function __CAAT__loadingScene(director) {
  7. var scene= director.createScene();
  8. var TIME= 2000;
  9. var time= new Date().getTime();
  10. var background= new CAAT.ActorContainer().
  11. setBackgroundImage( director.getImage('splash1'), true).
  12. addBehavior(
  13. new CAAT.GenericBehavior().
  14. setFrameTime(TIME/2, 0).
  15. setValues( 1, 0, null, null, function(value,target,actor) {
  16. actor.setBackgroundImage( director.getImage('splash1'), true )
  17. })
  18. );
  19. scene.addChild(background);
  20. var lading= new CAAT.Actor().
  21. setBackgroundImage( director.getImage('lading'), true).
  22. enableEvents(false);
  23. lading.setLocation( director.width-lading.width-10, director.height-lading.height-30 );
  24. scene.addChild(lading);
  25. var sitelogo= new CAAT.Actor().
  26. setBackgroundImage( director.getImage('logo_menu'), true).
  27. enableEvents(true);
  28. sitelogo.setLocation( director.width-sitelogo.width-30, director.height-sitelogo.height-30 );
  29. scene.addChild(sitelogo);
  30. sitelogo.mouseClick= function( e ) {
  31. CreateLinksInGame('Math-Plus','loading','logo');
  32. };
  33. var rueda= new CAAT.Actor().
  34. setBackgroundImage( director.getImage('rueda'), true).
  35. setLocation( lading.x+20, lading.y+10 ).
  36. enableEvents(false);
  37. scene.addChild(rueda);
  38. var rrb= new CAAT.RotateBehavior().
  39. setValues(0,2*Math.PI).
  40. setFrameTime(0,1000);
  41. rueda.addBehavior( rrb.setCycle(true) );
  42. scene.loadedImage = function(count, images) {
  43. if ( count==images.length ) {
  44. var difftime= new Date().getTime()-time;
  45. if ( difftime<TIME ){
  46. difftime= Math.abs(TIME-difftime);
  47. if ( difftime>TIME ) {
  48. difftime= TIME;
  49. }
  50. scene.createTimer(
  51. scene.time,
  52. difftime,
  53. function() {
  54. lading.setOutOfFrameTime();
  55. rueda.setOutOfFrameTime();
  56. __end_loading(director, images);
  57. }
  58. );
  59. } else {
  60. __end_loading(director, images);
  61. }
  62. }
  63. };
  64. return scene;
  65. }
  66. function __end_loading(director, images) {
  67. director.emptyScenes();
  68. director.setImagesCache(images);
  69. var gardenScene= new HN.GardenScene().create(
  70. director,
  71. (director.getRenderType()==='CANVAS') ? 120 : 0);
  72. var gameScene= new HN.GameScene().create(director, HN.GameModes.respawn );
  73. gardenScene.gameScene= gameScene;
  74. gameScene.addGameListener( gardenScene );
  75. director.easeIn(
  76. 0,
  77. CAAT.Scene.prototype.EASE_TRANSLATE,
  78. 1000,
  79. false,
  80. CAAT.Actor.prototype.ANCHOR_TOP,
  81. new CAAT.Interpolator().createExponentialInOutInterpolator(5,false) );
  82. }
  83. function createCSS() {
  84. var director;
  85. if ( window.innerWidth>window.innerHeight ) {
  86. director= new CAAT.Director().initialize(700,500,document.getElementById('game')).setClear( false );
  87. } else {
  88. director= new CAAT.Director().initialize(500,750,document.getElementById('game')).setClear(false);
  89. }
  90. return director;
  91. }
  92. function createCanvas() {
  93. var director;
  94. director= new CAAT.Director().initialize(500,700).setClear(false);
  95. return director;
  96. }
  97. function createGL() {
  98. var director;
  99. if ( window.innerWidth>window.innerHeight ) {
  100. director= new CAAT.Director().initializeGL(700,500).setClear( false );
  101. } else {
  102. director= new CAAT.Director().initializeGL(500,750).setClear(false);
  103. }
  104. return director;
  105. }
  106. function __Hypernumbers_init() {
  107. // uncomment to avoid decimal point coordinates.
  108. // Runs faster on anything but latest chrome.
  109. // CAAT.setCoordinateClamping(false);
  110. // uncomment to show CAAT's debug bar
  111. //CAAT.DEBUG=1;
  112. var director= createCanvas();
  113. // Uncomment to make the game conform to window's size.
  114. director.enableResizeEvents(CAAT.Director.prototype.RESIZE_PROPORTIONAL);
  115. HN.director= director;
  116. var prefix= typeof __RESOURCE_URL!=='undefined' ? __RESOURCE_URL : '';
  117. new CAAT.ImagePreloader().loadImages(
  118. [
  119. {id:'stars', url: prefix + 'res/img/stars.png'},
  120. {id:'logo_menu', url: prefix + 'res/img/logo_menu.png'},
  121. {id:'splash1', url: prefix + 'res/splash/splash1-i.png'},
  122. {id:'lading', url: prefix + 'res/splash/lading.png'},
  123. {id:'rueda', url: prefix + 'res/splash/rueda.png'}
  124. ],
  125. function( counter, images ) {
  126. if ( counter==images.length ) {
  127. director.setImagesCache(images);
  128. var scene_loading= __CAAT__loadingScene(director);
  129. new CAAT.ImagePreloader().loadImages(
  130. [
  131. {id:'smoke', url: prefix + 'res/img/humo.png'},
  132. {id:'stars', url: prefix + 'res/img/stars.png'},
  133. {id:'bricks', url: prefix + 'res/img/bricks.png'},
  134. {id:'buttons', url: prefix + 'res/img/botones.png'},
  135. {id:'numbers', url: prefix + 'res/img/numbers.png'},
  136. {id:'numberssmall', url: prefix + 'res/img/numbers_s.png'},
  137. {id:'madewith', url: prefix + 'res/img/madewith.png'},
  138. {id:'background-1', url: prefix + 'res/img/fondo1.png'},
  139. {id:'background-2', url: prefix + 'res/img/fondo2inv.png'},
  140. {id:'background_op', url: prefix + 'res/img/gameover.png'},
  141. {id:'cloud0', url: prefix + 'res/img/nube1.png'},
  142. {id:'cloud1', url: prefix + 'res/img/nube2.png'},
  143. {id:'cloud2', url: prefix + 'res/img/nube3.png'},
  144. {id:'cloud3', url: prefix + 'res/img/nube4.png'},
  145. {id:'cloudb0', url: prefix + 'res/img/nubefondo1.png'},
  146. {id:'cloudb1', url: prefix + 'res/img/nubefondo2.png'},
  147. {id:'cloudb2', url: prefix + 'res/img/nubefondo3.png'},
  148. {id:'cloudb3', url: prefix + 'res/img/nubefondo4.png'},
  149. {id:'level', url: prefix + 'res/img/level.png'},
  150. {id:'level-small', url: prefix + 'res/img/levelsmall.png'},
  151. {id:'boton-salir', url: prefix + 'res/img/boton_salir.png'},
  152. {id:'points', url: prefix + 'res/img/score.png'},
  153. {id:'time', url: prefix + 'res/img/time.png'},
  154. {id:'timeprogress', url: prefix + 'res/img/time_progress.png'},
  155. {id:'multiplier', url: prefix + 'res/img/xsmall.png'},
  156. {id:'multiplier-star', url: prefix + 'res/img/multiplicador.png'},
  157. {id:'ovni', url: prefix + 'res/img/ovni.png'},
  158. {id:'logo', url: prefix + 'res/img/logo_menu.png'},
  159. {id:'sitelogo', url: prefix + 'res/img/sitelogo.png'},
  160. {id:'levelclear', url: prefix + 'res/img/levelcleared.png'},
  161. {id:'msg1', url: prefix + 'res/img/7.png'},
  162. {id:'msg2', url: prefix + 'res/img/6.png'},
  163. {id:'msg3', url: prefix + 'res/img/5.png'},
  164. {id:'msg4', url: prefix + 'res/img/4.png'},
  165. {id:'msg5', url: prefix + 'res/img/3.png'},
  166. {id:'msg6', url: prefix + 'res/img/2.png'},
  167. {id:'msg7', url: prefix + 'res/img/1.png'},
  168. {id:'info_howto', url: prefix + 'res/img/info.png'},
  169. {id:'sound', url: prefix + 'res/img/sound.png'},
  170. {id:'mode-respawn', url: prefix + 'res/img/respawn.png'},
  171. {id:'mode-progressive', url: prefix + 'res/img/progresive.png'},
  172. {id:'mode-classic', url: prefix + 'res/img/normal_mode.png'},
  173. {id:'mode-text', url: prefix + 'res/img/textos.png'},
  174. {id:'rclock-bg', url: prefix + 'res/img/rclock_bg.png'},
  175. {id:'rclock-tick', url: prefix + 'res/img/rclock_tick.png'},
  176. {id:'rclock-arrow', url: prefix + 'res/img/rclock_arrow.png'},
  177. {id:'bolas', url: prefix + 'res/img/bolas.png'},
  178. {id:'info', url: prefix + 'res/big/about-i.jpg'},
  179. {id:'howto', url: prefix + 'res/big/tutorial-i.jpg'},
  180. {id:'target-number', url: prefix + 'res/img/target.png'}
  181. ],
  182. function( counter, images ) {
  183. if ( counter===images.length ) {
  184. director.
  185. addAudio("01", prefix+"res/sound/01.mp3").
  186. addAudio("10", prefix+"res/sound/10.mp3").
  187. addAudio("11", prefix+"res/sound/11.mp3").
  188. addAudio("12", prefix+"res/sound/12.mp3").
  189. addAudio("sumamal", prefix+"res/sound/suma_mal.mp3").
  190. addAudio("mostrarpanel", prefix+"res/sound/mostrarpanel.mp3").
  191. addAudio("deseleccionar", prefix+"res/sound/deseleccionar.mp3").
  192. addAudio("music", prefix+"res/sound/music.mp3");
  193. }
  194. scene_loading.loadedImage(counter, images);
  195. }
  196. );
  197. }
  198. }
  199. );
  200. CAAT.loop(60);
  201. }
  202. window.addEventListener('load', __Hypernumbers_init, false);