difficulty.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /*
  2. let difficultyState = {
  3. create: function(){},
  4. func_loadMap: function()
  5. ---------------------------- end of phaser functions
  6. };
  7. */
  8. let difficultyState = {
  9. create: function() {
  10. // Calls function that loads navigation icons
  11. iconSettings.func_addIcons(true,true,
  12. false,true,false,
  13. true,false,
  14. false,false);
  15. // TITLE
  16. const title = game.add.text(game.world.centerX, 40, lang.game_menu_title, textStyles.title2);
  17. title.anchor.setTo(0.5, 0.5);
  18. // LABEL SETTINGS
  19. // Text : 'with/without' labeling the fractions
  20. let labelText = game.add.text(game.world.centerX - 110, 80, "", textStyles.subtitle2);
  21. levelLabel ? labelText.text = lang.with_name + " " + lang.label_name : labelText.text = lang.without_name + " " + lang.label_name;
  22. labelText.anchor.setTo(0,0.5);
  23. // Selection box
  24. let selectionBox = game.add.sprite(game.world.centerX - 110 - 30, 75, 'select');
  25. levelLabel ? selectionBox.frame=1 : selectionBox.frame=0;
  26. selectionBox.anchor.setTo(0.5, 0.5);
  27. selectionBox.scale.setTo(0.12);
  28. selectionBox.inputEnabled = true;
  29. selectionBox.input.useHandCursor = true;
  30. selectionBox.events.onInputDown.add(function(){
  31. if(levelLabel){
  32. levelLabel = false;
  33. this.selectionBox.frame = 0;
  34. this.labelText.text = lang.without_name + " " + lang.label_name;
  35. if(audioStatus) beepSound.play();
  36. }else{
  37. levelLabel = true;
  38. this.selectionBox.frame = 1;
  39. this.labelText.text = lang.with_name + " " + lang.label_name;
  40. if(audioStatus) beepSound.play();
  41. }
  42. },{selectionBox: selectionBox, labelText: labelText});
  43. // SETTING DIFFICULTY LEVELS
  44. let stairHeight; //height growth of a stair
  45. let stairWidth; //Width of a stair
  46. let startStair;
  47. let startSymbol;
  48. let startGeometricFigure;
  49. const maxHeight = 120; // Maximum height of a stair
  50. if(currentGameState == "gameSquareOne"){
  51. stairHeight = 40;
  52. stairWidth = 100;
  53. startStair = 320;
  54. startSymbol = 180;
  55. startGeometricFigure = (startSymbol/2)+startStair+stairWidth*3;
  56. }else if(currentGameState == "gameSquareTwo" || currentGameState == "gameCircleOne"){
  57. stairHeight = 29;
  58. startStair = 240;
  59. startSymbol = 150;
  60. stairWidth = 85;
  61. startGeometricFigure = (startSymbol/2)+startStair+stairWidth*5;
  62. }else{
  63. console.log("Error! Name of the game state is not valid!");
  64. }
  65. let geometricFigure = [];
  66. let levelThemeIcons = [];
  67. let arrowIcons = [];
  68. let stairs = [];
  69. const aux = {
  70. maxSublevel: null,
  71. maxDifficulty: null,
  72. color: ['0x99b3ff', '0xff6666', '0xb366ff'], // blue, red, purple
  73. base_y1: [135, 285, 435],
  74. sublevel_1: ['Plus', 'Minus', 'Mixed'],
  75. sublevel_2: ['A', 'B', 'C'],
  76. get sublevel() {
  77. if (currentGameState == 'gameSquareTwo') return this.sublevel_2;
  78. else return this.sublevel_1;
  79. },
  80. }
  81. switch(currentGameState){
  82. case "gameSquareOne":
  83. aux.maxSublevel = 2;
  84. aux.maxDifficulty = 3;
  85. // Blue square
  86. geometricFigure[0] = game.add.graphics(startGeometricFigure, 175);
  87. geometricFigure[0].anchor.setTo(0.5,0.5);
  88. geometricFigure[0].lineStyle(2, 0x31314e);
  89. geometricFigure[0].beginFill(0xefeff5);
  90. geometricFigure[0].drawRect(0, 0, 80, 40);
  91. geometricFigure[0].endFill();
  92. // Red square
  93. geometricFigure[1] = game.add.graphics(startGeometricFigure, 330);
  94. geometricFigure[1].anchor.setTo(0.5,0.5);
  95. geometricFigure[1].lineStyle(2, 0xb30000);
  96. geometricFigure[1].beginFill(0xefeff5);
  97. geometricFigure[1].drawRect(0, 0, 80, 40);
  98. geometricFigure[1].endFill();
  99. // Green tractor
  100. levelThemeIcons[0] = game.add.sprite(startSymbol+30, 215, 'tractor_green');
  101. levelThemeIcons[0].scale.setTo(0.5);
  102. levelThemeIcons[0].alpha = 0.9;
  103. levelThemeIcons[0].anchor.setTo(0.5,0.5);
  104. // Red tractor
  105. levelThemeIcons[1] = game.add.sprite(startSymbol+70, 370, 'tractor_red');
  106. levelThemeIcons[1].scale.setTo(0.5);
  107. levelThemeIcons[1].alpha = 0.9;
  108. levelThemeIcons[1].anchor.setTo(0.5,0.5);
  109. // Plus Arrow
  110. arrowIcons[0] = game.add.sprite(startSymbol+100, 215, 'h_arrow');
  111. arrowIcons[0].scale.setTo(0.3);
  112. arrowIcons[0].alpha = 0.9;
  113. arrowIcons[0].anchor.setTo(0.5,0.5);
  114. // Minus Arrow
  115. arrowIcons[1] = game.add.sprite(startSymbol, 370, 'h_arrow');
  116. arrowIcons[1].scale.setTo(0.3);
  117. arrowIcons[1].alpha = 0.9;
  118. arrowIcons[1].anchor.setTo(0.5,0.5);
  119. arrowIcons[1].scale.x *= -1;
  120. break;
  121. case "gameCircleOne":
  122. aux.maxSublevel = 3;
  123. aux.maxDifficulty = 5;
  124. // Blue Circle
  125. geometricFigure[0] = game.add.graphics(startGeometricFigure, 175);
  126. geometricFigure[0].anchor.setTo(0.5,0.5);
  127. geometricFigure[0].lineStyle(2, 0x31314e);
  128. geometricFigure[0].beginFill(0xefeff5);
  129. geometricFigure[0].drawCircle(0, 0, 60);
  130. geometricFigure[0].endFill();
  131. // Red Circle
  132. geometricFigure[1] = game.add.graphics(startGeometricFigure, 330);
  133. geometricFigure[1].anchor.setTo(0.5,0.5);
  134. geometricFigure[1].lineStyle(2, 0xb30000);
  135. geometricFigure[1].beginFill(0xefeff5);
  136. geometricFigure[1].drawCircle(0, 0, 60);
  137. geometricFigure[1].endFill();
  138. // Both blue and red circles
  139. geometricFigure[2] = game.add.graphics(startGeometricFigure-30, 485);
  140. geometricFigure[2].anchor.setTo(0.5,0.5);
  141. geometricFigure[2].lineStyle(2, 0x31314e);
  142. geometricFigure[2].beginFill(0xefeff5);
  143. geometricFigure[2].drawCircle(0, 0, 60);
  144. geometricFigure[2].endFill();
  145. geometricFigure[3] = game.add.graphics(startGeometricFigure+40, 485);
  146. geometricFigure[3].anchor.setTo(0.5,0.5);
  147. geometricFigure[3].lineStyle(2, 0xb30000);
  148. geometricFigure[3].beginFill(0xefeff5);
  149. geometricFigure[3].drawCircle(0, 0, 60);
  150. geometricFigure[3].endFill();
  151. // Kid plus
  152. levelThemeIcons[0] = game.add.sprite(startSymbol, 195, 'kid_walk');
  153. levelThemeIcons[0].scale.setTo(0.6);
  154. levelThemeIcons[0].alpha = 0.8;
  155. levelThemeIcons[0].anchor.setTo(0.5,0.5);
  156. // Kid minus
  157. levelThemeIcons[1] = game.add.sprite(startSymbol+40, 350, 'kid_walk');
  158. levelThemeIcons[1].scale.setTo(-0.6, 0.6);
  159. levelThemeIcons[1].alpha = 0.8;
  160. levelThemeIcons[1].anchor.setTo(0.5,0.5);
  161. // Plus arrow
  162. arrowIcons[0] = game.add.sprite(startSymbol+40, 195, 'h_arrow');
  163. arrowIcons[0].scale.setTo(0.35);
  164. arrowIcons[0].alpha = 0.8;
  165. arrowIcons[0].anchor.setTo(0.5,0.5);
  166. // Minus arrow
  167. arrowIcons[1] = game.add.sprite(startSymbol, 350, 'h_arrow');
  168. arrowIcons[1].scale.setTo(-0.35, 0.35);
  169. arrowIcons[1].alpha = 0.8;
  170. arrowIcons[1].anchor.setTo(0.5,0.5);
  171. // Both plus and minus arrows
  172. arrowIcons[2] = game.add.sprite(startSymbol+20, 500, 'h_double');
  173. arrowIcons[2].scale.setTo(0.5);
  174. arrowIcons[2].alpha = 0.8;
  175. arrowIcons[2].anchor.setTo(0.5,0.5);
  176. break;
  177. case "gameSquareTwo":
  178. aux.maxSublevel = 3;
  179. aux.maxDifficulty = 5;
  180. levelThemeIcons[0] = game.add.sprite(startSymbol, 370, 'equal');
  181. levelThemeIcons[0].scale.setTo(0.7);
  182. levelThemeIcons[0].anchor.setTo(0.5,0.5);
  183. break;
  184. default:
  185. console.log("Error: couldn't finish loading difficulty screen assets");
  186. }
  187. // Pacing difficulty 'stairs'
  188. for(let sublevel=0; sublevel<aux.maxSublevel; sublevel++){
  189. for(let difficulty=1; difficulty<=aux.maxDifficulty; difficulty++){
  190. // Position
  191. let x1 = startStair+(stairWidth*(difficulty-1));
  192. let y1 = aux.base_y1[sublevel]+maxHeight-difficulty*stairHeight;
  193. let x2 = stairWidth;//x1 + 40;
  194. let y2 = stairHeight*difficulty;//y1 + 24;
  195. // Graphics
  196. stairs[difficulty] = game.add.graphics(0, 0);
  197. stairs[difficulty].lineStyle(1, 0xFFFFFF, 1);
  198. stairs[difficulty].beginFill(aux.color[sublevel]);
  199. stairs[difficulty].drawRect(x1, y1, x2, y2);
  200. stairs[difficulty].endFill();
  201. // Events
  202. stairs[difficulty].inputEnabled = true;
  203. stairs[difficulty].input.useHandCursor = true;
  204. stairs[difficulty].events.onInputDown.add(this.func_loadMap, {beep: beepSound, difficulty: difficulty, sublevelType: aux.sublevel[sublevel]});
  205. stairs[difficulty].events.onInputOver.add(function (item) { item.alpha=0.5; }, this);
  206. stairs[difficulty].events.onInputOut.add(function (item) { item.alpha=1; }, this);
  207. // Labels
  208. let xl = x1+stairWidth/2; //x label
  209. let yl = y1+(stairHeight*difficulty)/2; //y label
  210. let label = game.add.text(xl, yl, difficulty, textStyles.difficultyLabel);
  211. label.anchor.setTo(0.5, 0.4);
  212. }
  213. }
  214. },
  215. // Calls map state
  216. func_loadMap: function(){
  217. if(audioStatus) this.beep.play();
  218. levelPosition = 0; //Map position
  219. levelMove = true; //Move no next point
  220. levelDifficulty = this.difficulty; //Number of difficulty (1 to 5)
  221. sublevelType = this.sublevelType; //Type of game
  222. passedLevels = 0; //reset the game progress when entering a new level
  223. game.state.start('map');
  224. },
  225. };