squareTwo.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. /*
  2. var menuSquareTwo = {
  3. create: function(){},
  4. ---------------------------- end of phaser functions
  5. func_loadMap: function(){}
  6. };
  7. var gameSquareTwo = {
  8. create: function(){},
  9. update: function(){},
  10. ---------------------------- end of phaser functions
  11. func_updateCounter: function(){},
  12. func_overSquare: function(){},
  13. func_outSquare: function(){},
  14. func_clickSquare: function(){},
  15. //func_setPlace: function(){},
  16. func_postScore: function(){},
  17. //func_viewHelp: function(){},
  18. //func_checkOverlap: function(){}
  19. func_getRndDivisor: function(){}
  20. };
  21. var endSquareTwo = {
  22. create: function(){},
  23. update: function(){},
  24. ---------------------------- end of phaser functions
  25. func_verPrincipal: function(){},
  26. };
  27. */
  28. // Fractions Comparison Square states
  29. /****************************** MENU ****************************/
  30. var menuSquareTwo = {
  31. create: function() {
  32. // Navigation buttons
  33. buttonSettings["func_addButtons"](1,1,
  34. 0,1,0,
  35. 1,0,
  36. 0,0);
  37. // Setting title
  38. var style = { font: '28px Arial', fill: '#00804d'};
  39. var title = game.add.text(game.world.centerX, 40, lang.game_menu_title, style);
  40. title.anchor.setTo(0.5, 0.5);
  41. //SETTING DIFFICULTY LEVELS
  42. var maxHeight = 120; //Max height of a stair
  43. var stairHeight = 29; //height growth of a stair
  44. var stairWidth = 80; //Width of a stair
  45. var startStair = 240;
  46. var startSymbol = 150;
  47. var startSquare = (startSymbol/2)+startStair+stairWidth*5;
  48. var equalsIcon = game.add.sprite(startSymbol, 300, 'equal');
  49. equalsIcon.frame = 0;
  50. equalsIcon.scale.setTo(0.7);
  51. equalsIcon.anchor.setTo(0.5,0.5);
  52. //First stairs, More divisions to less divisions 1, 5 levels
  53. var stairsMoreToLess1 = [];
  54. for(var i=1;i<=5;i++){
  55. //stair
  56. var x1 = startStair+(stairWidth*(i-1));
  57. var y1 = 100+maxHeight-i*stairHeight;
  58. var x2 = stairWidth;//x1 + 40;
  59. var y2 = stairHeight*i;//y1 + 24;
  60. stairsMoreToLess1[i] = game.add.graphics(0, 0);
  61. stairsMoreToLess1[i].lineStyle(1, 0xFFFFFF, 1);
  62. stairsMoreToLess1[i].beginFill(0x99b3ff);
  63. stairsMoreToLess1[i].drawRect(x1, y1, x2, y2);
  64. stairsMoreToLess1[i].endFill();
  65. //event
  66. stairsMoreToLess1[i].inputEnabled = true;
  67. stairsMoreToLess1[i].input.useHandCursor = true;
  68. stairsMoreToLess1[i].events.onInputDown.add(this.func_loadMap, {beep: beepSound, difficulty: i, operator: 'A' });
  69. stairsMoreToLess1[i].events.onInputOver.add(function (item) { item.alpha=0.5; }, this);
  70. stairsMoreToLess1[i].events.onInputOut.add(function (item) { item.alpha=1; }, this);
  71. //label
  72. var xl = x1+stairWidth/2; //x label
  73. var yl = y1+(stairHeight*i)/2; //y label
  74. var label = game.add.text(xl, yl, i, { font: '25px Arial', fill: '#ffffff', align: 'center' });
  75. label.anchor.setTo(0.5, 0.4);
  76. }
  77. //Second stairs, More divisions to less divisions 2, 5 levels
  78. var stairsMoreToLess2 = [];
  79. for(var i=1;i<=5;i++){
  80. //stair
  81. var x1 = startStair+(stairWidth*(i-1));
  82. var y1 = 270+maxHeight-i*stairHeight;
  83. var x2 = stairWidth;//x1 + 40;
  84. var y2 = stairHeight*i;//y1 + 24;
  85. stairsMoreToLess2[i] = game.add.graphics(0, 0);
  86. stairsMoreToLess2[i].lineStyle(1, 0xFFFFFF, 1);
  87. stairsMoreToLess2[i].beginFill(0xff6666);
  88. stairsMoreToLess2[i].drawRect(x1, y1, x2, y2);
  89. stairsMoreToLess2[i].endFill();
  90. //event
  91. stairsMoreToLess2[i].inputEnabled = true;
  92. stairsMoreToLess2[i].input.useHandCursor = true;
  93. stairsMoreToLess2[i].events.onInputDown.add(this.func_loadMap, {beep: beepSound, difficulty: i, operator: 'B' });
  94. stairsMoreToLess2[i].events.onInputOver.add(function (item) { item.alpha=0.5; }, this);
  95. stairsMoreToLess2[i].events.onInputOut.add(function (item) { item.alpha=1; }, this);
  96. //label
  97. var xl = x1+stairWidth/2; //x label
  98. var yl = y1+(stairHeight*i)/2; //y label
  99. var label = game.add.text(xl, yl, i, { font: '25px Arial', fill: '#ffffff', align: 'center' });
  100. label.anchor.setTo(0.5, 0.4);
  101. }
  102. //Third stairs, Less divisions to more divisions, 5 levels
  103. var stairsLessToMore = [];
  104. for(var i=1;i<=5;i++){
  105. //stair
  106. var x1 = startStair+(stairWidth*(i-1));
  107. var y1 = 440+maxHeight-i*stairHeight;
  108. var x2 = stairWidth;//x1 + 40;
  109. var y2 = stairHeight*i;//y1 + 24;
  110. stairsLessToMore[i] = game.add.graphics(0, 0);
  111. stairsLessToMore[i].lineStyle(1, 0xFFFFFF, 1);
  112. stairsLessToMore[i].beginFill(0xb366ff);
  113. stairsLessToMore[i].drawRect(x1, y1, x2, y2);
  114. stairsLessToMore[i].endFill();
  115. //event
  116. stairsLessToMore[i].inputEnabled = true;
  117. stairsLessToMore[i].input.useHandCursor = true;
  118. stairsLessToMore[i].events.onInputDown.add(this.func_loadMap, {beep: beepSound, difficulty: i, operator: 'C' });
  119. stairsLessToMore[i].events.onInputOver.add(function (item) { item.alpha=0.5; }, this);
  120. stairsLessToMore[i].events.onInputOut.add(function (item) { item.alpha=1; }, this);
  121. //label
  122. var xl = x1+stairWidth/2; //x label
  123. var yl = y1+(stairHeight*i)/2; //y label
  124. var label = game.add.text(xl, yl, i, { font: '25px Arial', fill: '#ffffff', align: 'center' });
  125. label.anchor.setTo(0.5, 0.4);
  126. }
  127. },
  128. //MapLoading function
  129. func_loadMap: function(){
  130. if(audioStatus){
  131. this.beep.play();
  132. }
  133. levelPosition = 0; //Map position
  134. levelMove = true; //Move no next point
  135. levelDifficulty = this.difficulty; //Number of difficulty (1 to 5)
  136. leveloperator = this.operator; //Type of game
  137. passedLevels = 0; //reset the game progress when entering a new level
  138. game.state.start('map');
  139. },
  140. };
  141. /****************************** GAME ****************************/
  142. var gameSquareTwo = {
  143. create: function() {
  144. //timer
  145. totalTime = 0;
  146. timer = game.time.create(false);
  147. timer.loop(1000, this.func_updateCounter, this);
  148. timer.start();
  149. points = [2,4,6,8,9,10,12,14,15,16,18,20];
  150. // Background
  151. game.add.image(0, 0, 'bgimage');
  152. // Navigation buttons
  153. buttonSettings["func_addButtons"](1,1,
  154. 1,1,0,
  155. 1,0,
  156. "menuSquareTwo", 0);
  157. //Clouds
  158. game.add.image(300, 100, 'cloud');
  159. game.add.image(660, 80, 'cloud');
  160. game.add.image(110, 85, 'cloud').scale.setTo(0.8);
  161. // Styles for labels
  162. var stylePlace = { font: '26px Arial', fill: '#400080', align: 'center'};
  163. var styleLabel = { font: '26px Arial', fill: '#000080', align: 'center'};
  164. var styleFraction = { font: '20px Arial', fill: '#000080', align: 'center'};
  165. var styleMenu = { font: '30px Arial', fill: '#000000', align: 'center'};
  166. //Floor
  167. for(var i=0;i<9;i++){
  168. game.add.image(i*100, 501, 'floor');
  169. }
  170. //kid
  171. kid = game.add.sprite(100, 470, 'kid_lost');
  172. kid.anchor.setTo(0.5, 0.7);
  173. kid.scale.setTo(0.8);
  174. //kid.animations.add('right',[0,1,2,3,4,5,6,7,8,9,10,11]);
  175. //kid.animations.add('left',[23,22,21,20,19,18,17,16,15,14,13,12]);
  176. kid.animations.add('front', [3,4,5])
  177. kidDirection = 'front';
  178. kidLeftLimit = 100;
  179. kidRightLimit = 800;
  180. kid.animations.play('front', 6, true);
  181. //Control variables
  182. sizeA = 0; //Size of first block
  183. sizeB = 0; //Size of second block
  184. valueA = 0; //Number of clicked blocks for a
  185. valueB = 0; //Number of clicked blocks for b
  186. clickA = false; //If block A is clicked
  187. clickB = false; //If block B is clicked
  188. animateA = false; //Animate A selected blocks to position
  189. animateB = false; //Animate B selected blocks to position
  190. result = false; //Game is correct
  191. animate = null; //Final animation sequence
  192. //generator
  193. if(debugMode) console.log("----------");
  194. if(debugMode) console.log("Diff " + levelDifficulty + ", ini " + ((levelDifficulty-1)*2+1) + ", end " + ((levelDifficulty-1)*2+3));
  195. var rPoint = game.rnd.integerInRange((levelDifficulty-1)*2+1,(levelDifficulty-1)*2+3);
  196. sizeA = points[rPoint];
  197. if(debugMode) console.log("Rpoint " + rPoint + ", val " + sizeA);
  198. sizeB = this.func_getRndDivisor(sizeA);
  199. blockB = game.rnd.integerInRange(1, sizeB);
  200. blockA = (sizeA/sizeB) * blockB;
  201. if(debugMode) console.log("SA " + sizeA + ", SB " + sizeB + ", BA " + blockA + ", BB " + blockB );
  202. //Blocks and fractions group
  203. blocksA = game.add.group(); //Main blocks A
  204. blocksB = game.add.group(); //Main blocks B
  205. auxblqA = game.add.group(); //Auxiliar blocks A
  206. auxblqB = game.add.group(); //Auxiliar blocks B
  207. //Creating blocks
  208. blockW = 400;
  209. blockH = 50;
  210. if(levelOperator!="C"){
  211. xA=230, yA=90;
  212. xB=xA, yB=yA+3*blockH+30;
  213. }else{
  214. xB=230, yB=90;
  215. xA=xB, yA=yB+3*blockH+30;
  216. }
  217. //Blocks A
  218. var widthA = blockW/sizeA;
  219. var lineColor = 0x1e2f2f;
  220. var fillColor = 0x83afaf;
  221. var fillColorS = 0xe0ebeb;
  222. for(var i=0; i<sizeA; i++){
  223. //if(debugMode) console.log("Block A"+i+": x:"+(xA+i*widthA)+", y:"+yA);
  224. var block = game.add.graphics(xA+i*widthA, yA);
  225. block.anchor.setTo(0.5, 0.5);
  226. block.lineStyle(2, lineColor);
  227. block.beginFill(fillColor);
  228. block.drawRect(0, 0, widthA, blockH);
  229. block.alpha = 0.5;
  230. block.endFill();
  231. block.inputEnabled = true;
  232. block.input.useHandCursor = true;
  233. block.events.onInputDown.add(this.func_clickSquare, {who: 'A',indice: i});
  234. block.events.onInputOver.add(this.func_overSquare, {who: 'A',indice: i});
  235. block.events.onInputOut.add(this.func_outSquare, {who: 'A',indice: i});
  236. blocksA.add(block);
  237. //aux blocks
  238. var xAux = xA+i*widthA, yAux = yA+blockH+10;
  239. if(levelOperator == 'C') yAux = yA;
  240. var block = game.add.graphics(xAux, yAux );
  241. block.anchor.setTo(0.5, 0.5);
  242. block.lineStyle(1, lineColor);
  243. block.beginFill(fillColorS);
  244. block.drawRect(0, 0, widthA, blockH);
  245. if(levelOperator!='A') block.alpha = 0;
  246. else block.alpha = 0.2;
  247. auxblqA.add(block);
  248. }
  249. //label block A
  250. var labelX = xA+blockW+30;
  251. var labelY = yA+blockH/2;
  252. labelA = game.add.text(labelX, labelY, sizeA , styleFraction);
  253. labelA.anchor.setTo(0.5, 0.41);
  254. //label fraction
  255. labelX = xA+(blockA*widthA)+40;
  256. labelY = yA+blockH+34;
  257. fractionA = game.add.text(labelX, labelY, "0\n"+sizeA , styleFraction);
  258. fractionA.anchor.setTo(0.5, 0.41);
  259. separatorA = game.add.sprite(labelX, labelY, 'separator');
  260. separatorA.anchor.setTo(0.5, 0.5);
  261. fractionA.alpha = 0;
  262. separatorA.alpha = 0;
  263. //Blocks B
  264. var widthB = blockW/sizeB;
  265. lineColor = 0x260d0d;
  266. fillColor = 0xd27979;
  267. fillColorS = 0xf2d9d9;
  268. for(var i=0; i<sizeB; i++){
  269. var block = game.add.graphics(xB+i*widthB, yB);
  270. block.anchor.setTo(0.5, 0.5);
  271. block.lineStyle(2, lineColor);
  272. block.beginFill(fillColor);
  273. block.drawRect(0, 0, widthB, blockH);
  274. block.endFill();
  275. block.inputEnabled = true;
  276. block.input.useHandCursor = true;
  277. block.events.onInputDown.add(this.func_clickSquare, {who: 'B',indice: i});
  278. block.events.onInputOver.add(this.func_overSquare, {who: 'B',indice: i});
  279. block.events.onInputOut.add(this.func_outSquare, {who: 'B',indice: i});
  280. blocksB.add(block);
  281. //aux blocks
  282. var xAux = xB+i*widthB, yAux = yB+blockH+10;
  283. if(levelOperator == 'C') yAux = yB;
  284. var block = game.add.graphics(xAux, yAux);
  285. block.anchor.setTo(0.5, 0.5);
  286. block.lineStyle(1, lineColor);
  287. block.beginFill(fillColorS);
  288. block.drawRect(0, 0, widthB, blockH);
  289. if(levelOperator!='A') block.alpha = 0;
  290. else block.alpha = 0.2;
  291. auxblqB.add(block);
  292. }
  293. //label block B
  294. labelX = xA+blockW+30;
  295. labelY = yB+blockH/2;
  296. labelB = game.add.text(labelX, labelY, sizeB , styleFraction);
  297. labelB.anchor.setTo(0.5, 0.41);
  298. //label fraction
  299. labelX = xA+(blockB*widthB)+40;
  300. labelY = yB+blockH+34;
  301. fractionB = game.add.text(labelX, labelY, "0\n"+sizeB , styleFraction);
  302. fractionB.anchor.setTo(0.5, 0.41);
  303. separatorB = game.add.sprite(labelX, labelY, 'separator');
  304. separatorB.anchor.setTo(0.5, 0.5);
  305. fractionB.alpha = 0;
  306. separatorB.alpha = 0;
  307. //ok and error images
  308. okImg = game.add.image(game.world.centerX, game.world.centerY, 'h_ok');
  309. okImg.anchor.setTo(0.5);
  310. okImg.alpha = 0;
  311. errorImg = game.add.image(game.world.centerX, game.world.centerY, 'h_error');
  312. errorImg.anchor.setTo(0.5);
  313. errorImg.alpha = 0;
  314. //error text
  315. errorTextA = game.add.text(game.world.centerX, game.world.centerY-225, "", {font: "20px Arial", fill: "#330000", align: "center" });
  316. errorTextA.anchor.setTo(0.5, 0.5);
  317. errorTextB = game.add.text(game.world.centerX, game.world.centerY-45, "", {font: "20px Arial", fill: "#330000", align: "center" });
  318. errorTextB.anchor.setTo(0.5, 0.5);
  319. counter = 0;
  320. endCounter = 100;
  321. cDelay = 0;
  322. eDelay = 60;
  323. },
  324. update: function() {
  325. if (game.physics.arcade.distanceToPointer(kid, game.input.activePointer) > 20 ){
  326. var xPos = game.input.mousePointer.x;
  327. /*if (xPos < kid.x + 10){
  328. kidDirection='right';
  329. kid.animations.play('right', 8, true);
  330. }else if (xPos > kid.x){
  331. kidDirection='right';
  332. kid.animations.play('right', 8, true);
  333. }*/
  334. //set limit to the arrow
  335. if (xPos < kidLeftLimit){
  336. xPos = kidLeftLimit;
  337. }
  338. if (xPos > kidRightLimit){
  339. xPos = kidRightLimit;
  340. }
  341. kid.x = xPos;
  342. }
  343. //If clicked A only, animate
  344. if(animateA){
  345. for(var i=0;i<valueA;i++){
  346. blocksA.children[i].y +=2;
  347. }
  348. if(blocksA.children[0].y>=auxblqA.children[0].y){
  349. animateA = false;
  350. fractionA.alpha = 1;
  351. fractionA.setText(valueA+"\n"+sizeA);
  352. separatorA.alpha = 1;
  353. }
  354. }
  355. //If clicked B only, animate
  356. if(animateB){
  357. for(var i=0;i<valueB;i++){
  358. blocksB.children[i].y +=2;
  359. }
  360. if(blocksB.children[0].y>=auxblqB.children[0].y){
  361. animateB = false;
  362. fractionB.alpha = 1;
  363. fractionB.setText(valueB+"\n"+sizeB);
  364. separatorB.alpha = 1;
  365. }
  366. }
  367. //if clicked A and B
  368. if(clickA && clickB && !this.animate){
  369. //Check result
  370. timer.stop();
  371. cDelay++;
  372. if(cDelay>=eDelay){
  373. //fractions are equivalent : correct
  374. if((valueA/sizeA) == (valueB/sizeB)){
  375. result = true;
  376. levelMove = true;
  377. if(audioStatus){
  378. okSound.play();
  379. }
  380. kid.animations.stop();
  381. passedLevels++;
  382. if(debugMode) console.log("passedLevels = " + passedLevels);
  383. okImg.alpha = 1;
  384. //fractions are not equivalent
  385. }else{
  386. result = false;
  387. levelMove = false;
  388. if(audioStatus){
  389. errorSound.play();
  390. }
  391. kid.animations.stop();
  392. errorImg.alpha = 1;
  393. }
  394. this.func_postScore();
  395. clickA = false;
  396. clickB = false;
  397. animate = true;
  398. }
  399. }
  400. if(animate){
  401. counter++;
  402. if(result){
  403. // kid.x += 2;
  404. // kidDirection='right';
  405. // kid.animations.play('right', 8, true);
  406. }
  407. if(counter>endCounter){
  408. game.state.start('map');
  409. }
  410. }
  411. },
  412. func_updateCounter: function() {
  413. totalTime++;
  414. },
  415. func_overSquare: function(){
  416. if(!clickA && this.who=="A"){
  417. if(this.indice == sizeA-1){
  418. if(yA==90){
  419. errorTextA.setText(lang.error_msg);
  420. errorTextB.setText("");
  421. }else{
  422. errorTextA.setText("");
  423. errorTextB.setText(lang.error_msg);
  424. }
  425. }else{
  426. errorTextA.setText("");
  427. errorTextB.setText("");
  428. for(var i=0;i<sizeA;i++){
  429. if(i<=this.indice){
  430. blocksA.children[i].alpha = 1;
  431. }else{
  432. blocksA.children[i].alpha = 0.5;
  433. }
  434. }
  435. fractionA.x = xA+((this.indice +1)*(blockW/sizeA))+40;
  436. fractionA.alpha = 1;
  437. fractionA.setText(this.indice +1);
  438. }
  439. }
  440. if(!clickB && this.who=="B"){
  441. if(this.indice == sizeB-1){
  442. if(yA==90){
  443. errorTextA.setText("");
  444. errorTextB.setText(lang.error_msg);
  445. }else{
  446. errorTextA.setText(lang.error_msg);
  447. errorTextB.setText("");
  448. }
  449. }else{
  450. errorTextA.setText("");
  451. errorTextB.setText("");
  452. for(var i=0;i<sizeB;i++){
  453. if(i<=this.indice){
  454. blocksB.children[i].alpha = 1;
  455. }else{
  456. blocksB.children[i].alpha = 0.5;
  457. }
  458. }
  459. fractionB.x = xB+((this.indice +1)*(blockW/sizeB))+40;
  460. fractionB.alpha = 1;
  461. fractionB.setText(this.indice +1);
  462. }
  463. }
  464. },
  465. func_outSquare: function(){
  466. if(!clickA && this.who=="A"){
  467. for(var i=0;i<=this.indice;i++){
  468. blocksA.children[i].alpha = 0.5;
  469. }
  470. fractionA.alpha = 0;
  471. }
  472. if(!clickB && this.who=="B"){
  473. for(var i=0;i<=this.indice;i++){
  474. blocksB.children[i].alpha = 0.5;
  475. }
  476. fractionB.alpha = 0;
  477. }
  478. },
  479. func_clickSquare: function(){
  480. if(!clickA && this.who=="A" && this.indice!=sizeA-1){
  481. for(var i=0;i<sizeA;i++){
  482. blocksA.children[i].inputEnabled = false;
  483. if(i<=this.indice){
  484. blocksA.children[i].alpha = 1;
  485. }else{
  486. blocksA.children[i].alpha = 0.5;
  487. auxblqA.children[i].alpha = 0;
  488. }
  489. }
  490. labelA.alpha = 0;
  491. if(audioStatus){
  492. beepSound.play();
  493. }
  494. clickA = true;
  495. valueA = this.indice+1;
  496. fractionA.x = xA+(valueA*(blockW/sizeA))+40;
  497. separatorA.x = fractionA.x
  498. animateA = true;
  499. }
  500. if(!clickB && this.who=="B" && this.indice!=sizeB-1){
  501. for(var i=0;i<sizeB;i++){
  502. blocksB.children[i].inputEnabled = false;
  503. if(i<=this.indice){
  504. blocksB.children[i].alpha = 1;
  505. }else{
  506. blocksB.children[i].alpha = 0.5;
  507. auxblqB.children[i].alpha = 0;
  508. }
  509. }
  510. labelB.alpha = 0;
  511. if(audioStatus){
  512. beepSound.play();
  513. }
  514. clickB = true;
  515. valueB = this.indice+1;
  516. fractionB.x = xB+(valueB*(blockW/sizeB))+40;
  517. separatorB.x = fractionB.x
  518. animateB = true;
  519. }
  520. },
  521. func_postScore: function (){
  522. var abst = "numBlocksA:" + sizeA + ", valueA: " + valueA +", numBlocksB: " + sizeB + ", valueB: " + valueB;
  523. var hr = new XMLHttpRequest();
  524. // Create some variables we need to send to our PHP file
  525. var url = "php/save.php";
  526. var vars = "s_ip="+hip+"&s_name=" + username + "&s_lang=" + lang + "&s_game=" + levelShape + "&s_mode=" + levelType;
  527. vars += "&s_oper=Equal&s_leve=" + levelDifficulty + "&s_posi=" + levelPosition + "&s_resu=" + result + "&s_time=" + totalTime + "&s_deta=" + abst;
  528. hr.open("POST", url, true);
  529. hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  530. hr.onreadystatechange = function() {
  531. if(debugMode) console.log(hr);
  532. if(hr.readyState == 4 && hr.status == 200) {
  533. var return_data = hr.responseText;
  534. if(debugMode) console.log(return_data);
  535. }
  536. }
  537. // Send the data to PHP now... and wait for response to update the status div
  538. hr.send(vars); // Actually execute the request
  539. if(debugMode) console.log("processing...");
  540. },
  541. //Calculation help functions
  542. func_getRndDivisor: function(number){ //Get random divisor for a number
  543. var div = []; //Divisors found
  544. var p = 0; //current dividor index
  545. for(var i=2; i<number;i++){
  546. if(number%i==0){
  547. div[p] = i;
  548. p++;
  549. }
  550. }
  551. var x = game.rnd.integerInRange(0,p-1);
  552. return div[x];
  553. },
  554. };
  555. /****************************** END ****************************/
  556. var endSquareTwo = {
  557. create: function() {
  558. // Background
  559. game.add.image(0, 0, 'bgimage');
  560. //Clouds
  561. game.add.image(300, 100, 'cloud');
  562. game.add.image(660, 80, 'cloud');
  563. game.add.image(110, 85, 'cloud').scale.setTo(0.8);
  564. // Styles for labels
  565. var stylePlace = { font: '26px Arial', fill: '#400080', align: 'center'};
  566. var styleLabel = { font: '26px Arial', fill: '#000080', align: 'center'};
  567. var styleMenu = { font: '30px Arial', fill: '#000000', align: 'center'};
  568. //Floor
  569. for(var i=0;i<9;i++){
  570. game.add.image(i*100, 501, 'floor');
  571. }
  572. // Progress bar
  573. for(var p=1;p<=5;p++){
  574. var block = game.add.image(660+(p-1)*30, 10, 'block');
  575. block.scale.setTo(2, 1); //Scaling to double width
  576. }
  577. game.add.text(820, 10, '100%', styleMenu);
  578. game.add.text(650, 10, lang.difficulty + ' ' + levelDifficulty, styleMenu).anchor.setTo(1,0);
  579. game.add.image(660, 10, 'pgbar');
  580. //School and trees
  581. game.add.sprite(600, 222 , 'school').scale.setTo(0.7);
  582. game.add.sprite(30, 280 , 'tree4');
  583. game.add.sprite(360, 250 , 'tree2');
  584. //kid
  585. this.kid = game.add.sprite(0, 460 , 'kid_run');
  586. this.kid.anchor.setTo(0.5,0.5);
  587. this.kid.scale.setTo(0.7);
  588. this.kid.animations.add('walk', [0,1,2,3,4,5,6,7,8,9,10,11]);
  589. this.kid.animations.play('walk', 6, true);
  590. },
  591. update: function() {
  592. if(this.kid.x<=700){
  593. this.kid.x += 2;
  594. }else{
  595. if(levelMenu){
  596. passedLevels = 0;
  597. game.state.start('menu');
  598. }else{
  599. this.kid.animations.stop();
  600. }
  601. }
  602. },
  603. func_verPrincipal: function(){
  604. game.state.start('welcome');
  605. },
  606. };