difficulty.js 10 KB

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