circleOne.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864
  1. /*
  2. let menuCircleOne = {
  3. create: function(){},
  4. ---------------------------- end of phaser functions
  5. func_loadMap: function(){}
  6. };
  7. let gameCircleOne = {
  8. create: function(){},
  9. update: function(){},
  10. ---------------------------- end of phaser functions
  11. func_updateCounter: function(){},
  12. func_overCircle: function(){},
  13. func_outCircle: function(){},
  14. func_clickCircle: function(){},
  15. func_setPlace: function(){},
  16. func_postScore: function(){},
  17. func_viewHelp: function(){},
  18. func_checkOverlap: function(_,_){}
  19. //func_getRndDivisor: function(){}
  20. };
  21. let endCircleOne = {
  22. create: function(){},
  23. update: function(){},
  24. ---------------------------- end of phaser functions
  25. func_verPrincipal: function(){},
  26. };
  27. */
  28. // Kid and Circle states, games 1 and 2
  29. /****************************** MENU ****************************/
  30. let menuCircleOne = {
  31. create: function() {
  32. // Navigation buttons
  33. buttonSettings["func_addButtons"](true,true,
  34. false,true,false,
  35. true,false,
  36. false,false);
  37. // Title
  38. const style = { font: '28px Arial', fill: '#00804d'};
  39. let 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. let maxHeight = 120; //Max height of a stair
  43. let stairHeight = 29; //height growth of a stair
  44. let stairWidth = 85; //Width of a stair
  45. let startStair = 240;
  46. let startSymbol = 150;
  47. let startCircle = (startSymbol/2)+startStair+stairWidth*5;
  48. //First stairs, plus, 5 levels, blue circle
  49. let blueCircle = game.add.graphics(startCircle, 195);
  50. blueCircle.anchor.setTo(0.5,0.5);
  51. blueCircle.lineStyle(2, 0x31314e);
  52. blueCircle.beginFill(0xefeff5);
  53. blueCircle.drawCircle(0, 0, 60);
  54. blueCircle.endFill();
  55. let plusArrowIcon = game.add.sprite(startSymbol+40, 195, 'h_arrow');
  56. plusArrowIcon.scale.setTo(0.35);
  57. plusArrowIcon.alpha = 0.8;
  58. plusArrowIcon.anchor.setTo(0.5,0.5);
  59. let plusKidIcon = game.add.sprite(startSymbol, 195, 'kid_walk');
  60. plusKidIcon.scale.setTo(0.6);
  61. plusKidIcon.alpha = 0.8;
  62. plusKidIcon.anchor.setTo(0.5,0.5);
  63. let stairsPlus = [];
  64. for(let i=1;i<=5;i++){
  65. //stair
  66. let x1 = startStair+(stairWidth*(i-1));
  67. let y1 = 135+maxHeight-i*stairHeight;
  68. let x2 = stairWidth;//x1 + 40;
  69. let y2 = stairHeight*i;//y1 + 24;
  70. stairsPlus[i] = game.add.graphics(0, 0);
  71. stairsPlus[i].lineStyle(1, 0xFFFFFF, 1);
  72. stairsPlus[i].beginFill(0x99b3ff);
  73. stairsPlus[i].drawRect(x1, y1, x2, y2);
  74. stairsPlus[i].endFill();
  75. //event
  76. stairsPlus[i].inputEnabled = true;
  77. stairsPlus[i].input.useHandCursor = true;
  78. stairsPlus[i].events.onInputDown.add(this.func_loadMap, {beep: beepSound, difficulty: i, operator: 'Plus' });
  79. stairsPlus[i].events.onInputOver.add(function (item) { item.alpha=0.5; }, this);
  80. stairsPlus[i].events.onInputOut.add(function (item) { item.alpha=1; }, this);
  81. //label
  82. let xl = x1+stairWidth/2; //x label
  83. let yl = y1+(stairHeight*i)/2; //y label
  84. let label = game.add.text(xl, yl, i, { font: '25px Arial', fill: '#ffffff', align: 'center' });
  85. label.anchor.setTo(0.5, 0.4);
  86. }
  87. //Second stairs, minus, 5 levels, red circle
  88. let redCircle = game.add.graphics(startCircle, 350);
  89. redCircle.anchor.setTo(0.5,0.5);
  90. redCircle.lineStyle(2, 0xb30000);
  91. redCircle.beginFill(0xefeff5);
  92. redCircle.drawCircle(0, 0, 60);
  93. redCircle.endFill();
  94. let minusArrowIcon = game.add.sprite(startSymbol, 350, 'h_arrow');
  95. minusArrowIcon.scale.setTo(-0.35, 0.35);
  96. minusArrowIcon.alpha = 0.8;
  97. minusArrowIcon.anchor.setTo(0.5,0.5);
  98. let minusKidIcon = game.add.sprite(startSymbol+40, 350, 'kid_walk');
  99. minusKidIcon.scale.setTo(-0.6, 0.6);
  100. minusKidIcon.alpha = 0.8;
  101. minusKidIcon.anchor.setTo(0.5,0.5);
  102. let stairsMinus = [];
  103. for(let i=1;i<=5;i++){
  104. //stair
  105. let x1 = startStair+(stairWidth*(i-1));
  106. let y1 = 285+maxHeight-i*stairHeight;
  107. let x2 = stairWidth;//x1 + 40;
  108. let y2 = stairHeight*i;//y1 + 24;
  109. stairsMinus[i] = game.add.graphics(0, 0);
  110. stairsMinus[i].lineStyle(1, 0xFFFFFF, 1);
  111. stairsMinus[i].beginFill(0xff6666);
  112. stairsMinus[i].drawRect(x1, y1, x2, y2);
  113. stairsMinus[i].endFill();
  114. //event
  115. stairsMinus[i].inputEnabled = true;
  116. stairsMinus[i].input.useHandCursor = true;
  117. stairsMinus[i].events.onInputDown.add(this.func_loadMap, {beep: beepSound, difficulty: i, operator: 'Minus' });
  118. stairsMinus[i].events.onInputOver.add(function (item) { item.alpha=0.5; }, this);
  119. stairsMinus[i].events.onInputOut.add(function (item) { item.alpha=1; }, this);
  120. //label
  121. let xl = x1+stairWidth/2; //x label
  122. let yl = y1+(stairHeight*i)/2; //y label
  123. let label = game.add.text(xl, yl, i, { font: '25px Arial', fill: '#ffffff', align: 'center' });
  124. label.anchor.setTo(0.5, 0.4);
  125. }
  126. //Thrid stairs, mixed, 5 levels, two circles
  127. let blueCircle2 = game.add.graphics(startCircle-30, 500);
  128. blueCircle2.anchor.setTo(0.5,0.5);
  129. blueCircle2.lineStyle(2, 0x31314e);
  130. blueCircle2.beginFill(0xefeff5);
  131. blueCircle2.drawCircle(0, 0, 60);
  132. blueCircle2.endFill();
  133. let redCircle2 = game.add.graphics(startCircle+40, 500);
  134. redCircle2.anchor.setTo(0.5,0.5);
  135. redCircle2.lineStyle(2, 0xb30000);
  136. redCircle2.beginFill(0xefeff5);
  137. redCircle2.drawCircle(0, 0, 60);
  138. redCircle2.endFill();
  139. let doubleArrowIcon = game.add.sprite(startSymbol, 500, 'h_double');
  140. doubleArrowIcon.scale.setTo(0.5);
  141. doubleArrowIcon.anchor.setTo(0.5,0.5);
  142. doubleArrowIcon.alpha = 0.8;
  143. let stairsMixed = [];
  144. for(let i=1;i<=5;i++){
  145. //stair
  146. let x1 = startStair+(stairWidth*(i-1));
  147. let y1 = 435+maxHeight-i*stairHeight;
  148. let x2 = stairWidth;//x1 + 40;
  149. let y2 = stairHeight*i;//y1 + 24;
  150. stairsMixed[i] = game.add.graphics(0, 0);
  151. stairsMixed[i].lineStyle(1, 0xFFFFFF, 1);
  152. stairsMixed[i].beginFill(0xb366ff);
  153. stairsMixed[i].drawRect(x1, y1, x2, y2);
  154. stairsMixed[i].endFill();
  155. //event
  156. stairsMixed[i].inputEnabled = true;
  157. stairsMixed[i].input.useHandCursor = true;
  158. stairsMixed[i].events.onInputDown.add(this.func_loadMap, {beep: beepSound, difficulty: i, operator: 'Mixed' });
  159. stairsMixed[i].events.onInputOver.add(function (item) { item.alpha=0.5; }, this);
  160. stairsMixed[i].events.onInputOut.add(function (item) { item.alpha=1; }, this);
  161. //label
  162. let xl = x1+stairWidth/2; //x label
  163. let yl = y1+(stairHeight*i)/2; //y label
  164. let label = game.add.text(xl, yl, i, { font: '25px Arial', fill: '#ffffff', align: 'center' });
  165. label.anchor.setTo(0.5, 0.4);
  166. }
  167. },
  168. //MapLoading function
  169. func_loadMap: function(){
  170. if(audioStatus){
  171. this.beep.play();
  172. }
  173. levelPosition = 0; //Map position
  174. levelMove = true; //Move no next point
  175. levelDifficulty = this.difficulty; //Number of difficulty (1 to 5)
  176. levelOperator = this.operator; //Operator of game
  177. passedLevels = 0; //reset the game progress when entering a new level
  178. game.state.start('map');
  179. }
  180. };
  181. /****************************** GAME ****************************/
  182. let gameCircleOne = {
  183. create: function() {
  184. //timer
  185. totalTime = 0;
  186. timer = game.time.create(false);
  187. timer.loop(1000, this.func_updateCounter, this);
  188. timer.start();
  189. detail="";
  190. // Background
  191. game.add.image(0, 0, 'bgimage');
  192. // Navigation buttons
  193. buttonSettings["func_addButtons"](true,true,
  194. true,true,true,
  195. true,false,
  196. "menuCircleOne", this.func_viewHelp);
  197. //Clouds
  198. game.add.image(300, 100, 'cloud');
  199. game.add.image(660, 80, 'cloud');
  200. game.add.image(110, 85, 'cloud').scale.setTo(0.8);
  201. // Styles for labels
  202. let stylePlace = { font: '26px Arial', fill: '#400080', align: 'center'};
  203. let styleLabel = { font: '26px Arial', fill: '#000080', align: 'center'};
  204. let styleMenu = { font: '30px Arial', fill: '#000000', align: 'center'};
  205. //Floor and road
  206. startX = 66; //Initial kid and place position
  207. if(levelOperator=='Minus') startX = 66+5*156;
  208. placeDistance = 156; //Distance between places
  209. blockSize = 60;
  210. for(let i=0;i<9;i++){
  211. game.add.image(i*100, 501, 'floor');
  212. }
  213. let road = game.add.image(47, 515, 'road');
  214. road.scale.setTo(1.01,0.94);
  215. if(levelType=='A'){
  216. road.inputEnabled = true;
  217. road.events.onInputDown.add(this.func_setPlace, {beep: beepSound}); //enabling input for tablets
  218. }
  219. for(let p=0;p<=5;p++){// Places
  220. let place = game.add.image(66+p*placeDistance, 526, 'place_a');
  221. place.anchor.setTo(0.5);
  222. place.scale.setTo(0.3);
  223. game.add.text(66+p*placeDistance, 560, p , stylePlace).anchor.setTo(0.5);
  224. }
  225. //Control variables
  226. clicked = false; //Air ballon positioned
  227. hideLabels = false; //Labels animations
  228. animate = false; //Start move animation
  229. checkCollide = false; //Check kid inside ballon's basket
  230. result = false; //Game is correct
  231. fly = false; //Start ballon fly animation
  232. flyCounter = 0; //Fly counter
  233. flyEnd = 140; //Fly end counter
  234. hasFigure = false; //If has level figure
  235. //trace
  236. trace = this.add.bitmapData(this.game.width, this.game.height);
  237. trace.addToWorld();
  238. trace.clear();
  239. //generator
  240. //Circles and fractions
  241. let maxBlocks = levelPosition+1; //Maximum blocks according to difficulty
  242. if(levelType=='B' || levelOperator=='Mixed') maxBlocks = 6;
  243. blocks = game.add.group(); //Fraction arrays
  244. numBlocks = game.rnd.integerInRange(levelPosition, maxBlocks); //Number of blocks
  245. curBlock = 0; //Actual index block
  246. blockDirection = []; //Directions right(plus), left (minus)
  247. blockDistance = []; //Displacement distance of the blocks
  248. blockLabel = game.add.group(); //Labels of the blocks
  249. blockSeparator = game.add.group(); //Separator of the labels
  250. blockAngle = []; //Angles of blocks
  251. blockTraceColor = []; //Trace colors
  252. endPosition = startX; //Ending position, accumulative
  253. //Game B exclusive variables
  254. balloonPlace = this.game.world.centerX; //Fixed place for ballon (game B)
  255. fractionClicked = false; //If clicked a fraction (game B)
  256. fractionIndex = -1; //Index of clicked fraction (game B)
  257. numPlus = game.rnd.integerInRange(1, numBlocks-1);
  258. for(let p=0;p<numBlocks;p++){
  259. let portion = game.rnd.integerInRange(1, levelDifficulty); //Portion of the circle, according to difficulty
  260. detail += portion+",";
  261. if(portion==levelDifficulty){
  262. hasFigure = true;
  263. }
  264. let direction = '';
  265. let lineColor = '';
  266. if(levelOperator=='Mixed'){
  267. if(p<=numPlus){
  268. direction = 'Right';
  269. lineColor = 0x31314e;
  270. }else{
  271. direction = 'Left';
  272. lineColor = 0xb30000;
  273. }
  274. /*let directions = ['Right','Left'];
  275. let rndIndex = game.rnd.integerInRange(0, 1);
  276. direction = directions[rndIndex];
  277. if(rndIndex==0) lineColor = 0x31314e;
  278. else lineColor = 0xb30000;*/
  279. }else if(levelOperator=='Plus'){
  280. direction = 'Right';
  281. lineColor = 0x31314e;
  282. }else if(levelOperator=='Minus'){
  283. direction = 'Left';
  284. lineColor = 0xb30000;
  285. }
  286. blockTraceColor[p] = lineColor;
  287. let block = game.add.graphics(startX, 490-p*blockSize);
  288. block.anchor.setTo(0.5,0.5);
  289. block.lineStyle(2, lineColor);
  290. block.beginFill(0xefeff5);
  291. if (direction == 'Right') block.scale.y *= -1;
  292. blockDirection[p] = direction;
  293. if(portion==1){
  294. block.drawCircle(0, 0, blockSize);
  295. blockDistance.push(placeDistance);
  296. blockAngle.push(360);
  297. if(levelLabel){
  298. let labelX = startX;
  299. if(levelOperator=='Minus') labelX -= 65;
  300. else labelX += 65;
  301. let label = game.add.text(labelX, 490-p*blockSize, portion , styleLabel);
  302. label.anchor.setTo(0.5, 0.5);
  303. blockLabel.add(label);
  304. }
  305. }else{
  306. let distance = 360/portion+5;
  307. block.arc(0, 0, blockSize/2, game.math.degToRad(distance), 0, true);
  308. blockDistance.push(Math.floor(placeDistance/portion));
  309. blockAngle.push(distance);
  310. if(levelLabel){
  311. let labelX = startX;
  312. if(levelOperator=='Minus') labelX -= 65;
  313. else labelX += 65;
  314. let separator = game.add.sprite(labelX, 485-p*blockSize, 'separator');
  315. separator.anchor.setTo(0.5, 0.5);
  316. blockSeparator.add(separator);
  317. let label = game.add.text(labelX, 488-p*blockSize, '1\n'+portion , styleLabel);
  318. label.anchor.setTo(0.5, 0.5);
  319. blockLabel.add(label);
  320. }
  321. }
  322. if(direction=='Right'){
  323. endPosition += Math.floor(placeDistance/portion);
  324. }else if(direction=='Left'){
  325. endPosition -= Math.floor(placeDistance/portion);
  326. }
  327. block.endFill();
  328. block.angle +=90;
  329. //If game is type B, (select fractions, adding event)
  330. if(levelType=='B'){
  331. block.alpha = 0.5;
  332. block.inputEnabled = true;
  333. block.input.useHandCursor = true;
  334. block.events.onInputDown.add(this.func_clickCircle, {indice: p});
  335. block.events.onInputOver.add(this.func_overCircle, {indice: p});
  336. block.events.onInputOut.add(this.func_outCircle, {indice: p});
  337. }
  338. blocks.add(block);
  339. }
  340. //Calculate next block
  341. if(blockDirection[curBlock]=='Right'){
  342. nextEnd = startX+blockDistance[curBlock];
  343. }else{
  344. nextEnd = startX-blockDistance[curBlock];
  345. }
  346. //If game is type B, selectiong a random balloon place
  347. if(levelType=='B'){
  348. balloonPlace = startX;
  349. endIndex = game.rnd.integerInRange(numPlus, numBlocks);
  350. for(let i=0;i<endIndex;i++){
  351. if(blockDirection[i]=='Right')
  352. balloonPlace += blockDistance[i];
  353. else if(blockDirection[i]=='Left')
  354. balloonPlace -= blockDistance[i];
  355. }
  356. if(balloonPlace<66 || balloonPlace>66+5*placeDistance || !hasFigure){
  357. game.state.start('gameCircleOne');
  358. }
  359. }
  360. //If end position is out of bounds, restart
  361. if (endPosition<66 || endPosition>66+3*260 || !hasFigure){
  362. game.state.start('gameCircleOne');
  363. }
  364. //kid
  365. kid_walk = game.add.sprite(startX, 495-numBlocks*blockSize, 'kid_walk');
  366. kid_walk.anchor.setTo(0.5, 0.8);
  367. kid_walk.scale.setTo(0.8);
  368. kid_walk.animations.add('right',[0,1,2,3,4,5,6,7,8,9,10,11]);
  369. kid_walk.animations.add('left',[23,22,21,20,19,18,17,16,15,14,13,12]);
  370. if(levelOperator=='Minus'){
  371. kid_walk.animations.play('left', 6, true);
  372. kid_walk.animations.stop();
  373. }
  374. //globo
  375. balloon = game.add.sprite(balloonPlace, 350, 'balloon');
  376. balloon.anchor.setTo(0.5, 0.5);
  377. balloon.alpha = 0.5;
  378. basket = game.add.sprite(balloonPlace, 472, 'balloon_basket');
  379. basket.anchor.setTo(0.5, 0.5);
  380. //ok and error images
  381. okImg = game.add.image(game.world.centerX, game.world.centerY, 'h_ok');
  382. okImg.anchor.setTo(0.5);
  383. okImg.alpha = 0;
  384. errorImg = game.add.image(game.world.centerX, game.world.centerY, 'h_error');
  385. errorImg.anchor.setTo(0.5);
  386. errorImg.alpha = 0;
  387. },
  388. update: function() {
  389. if (game.input.activePointer.isDown && !fly && !clicked){
  390. //Positionate balloon - Game A
  391. if(levelType=='A'){
  392. if(game.input.mousePointer.y>60){ //Dead zone for click
  393. balloon.x = game.input.mousePointer.x;
  394. balloon.alpha = 1;
  395. clicked = true;
  396. animate = true;
  397. if(audioStatus){
  398. beepSound.play();
  399. }
  400. if(blockDirection[curBlock]=='Right'){
  401. kid_walk.animations.play('right', 6, true);
  402. }else{
  403. kid_walk.animations.play('left', 6, true);
  404. }
  405. if(levelLabel){ //Hiding labels
  406. blockLabel.visible = false;
  407. blockSeparator.visible = false;
  408. }
  409. }
  410. }
  411. }
  412. if(!clicked){
  413. if(!fly){
  414. if(levelType=="A"){
  415. //Follow mouse
  416. if (game.physics.arcade.distanceToPointer(balloon, game.input.activePointer) > 8){
  417. balloon.x = game.input.mousePointer.x;
  418. basket.x = game.input.mousePointer.x;
  419. }
  420. }
  421. }
  422. }
  423. //Start animation
  424. if(animate){
  425. let color = '';
  426. if(blockDirection[curBlock]=='Right'){
  427. kid_walk.x+=2;
  428. color = 'rgba(0, 51, 153, 1)';
  429. }else if(blockDirection[curBlock]=='Left'){
  430. kid_walk.x-=2;
  431. color = 'rgba(179, 0, 0, 1)';
  432. }
  433. trace.rect(kid_walk.x, 526, 2, 2, color);
  434. for(let i=0;i<numBlocks;i++){ //Moving every block
  435. if(blockDirection[curBlock]=='Right'){
  436. blocks.children[i].x +=2;
  437. }else{
  438. blocks.children[i].x -=2;
  439. }
  440. }
  441. blockAngle[curBlock] -= 4.6;
  442. blocks.children[curBlock].clear();
  443. blocks.children[curBlock].lineStyle(2, blockTraceColor[curBlock]);
  444. blocks.children[curBlock].beginFill(0xefeff5);
  445. blocks.children[curBlock].arc(0, 0, blockSize/2, game.math.degToRad(blockAngle[curBlock]), 0, true);
  446. blocks.children[curBlock].endFill();
  447. if(blockDirection[curBlock]=='Right'){
  448. if(blocks.children[curBlock].x>=nextEnd){
  449. blocks.children[curBlock].visible = false;
  450. blocks.y += blockSize;
  451. kid_walk.y += blockSize;
  452. curBlock+=1;
  453. if(blockDirection[curBlock]=='Right'){
  454. nextEnd += blockDistance[curBlock];
  455. kid_walk.animations.play('right', 6, true);
  456. }else if(blockDirection[curBlock]=='Left'){
  457. nextEnd -= blockDistance[curBlock];
  458. kid_walk.animations.play('left', 6, true);
  459. }
  460. }
  461. }else{
  462. if(blocks.children[curBlock].x<=nextEnd){
  463. blocks.children[curBlock].visible = false;
  464. blocks.y += blockSize;
  465. kid_walk.y += blockSize;
  466. curBlock+=1;
  467. if(blockDirection[curBlock]=='Right'){
  468. nextEnd += blockDistance[curBlock];
  469. kid_walk.animations.play('right', 6, true);
  470. }else if(blockDirection[curBlock]=='Left'){
  471. nextEnd -= blockDistance[curBlock];
  472. kid_walk.animations.play('left', 6, true);
  473. }
  474. }
  475. }
  476. if(curBlock==numBlocks ){ //Final position
  477. animate= false;
  478. checkCollide = true;
  479. }
  480. }
  481. //Check if kid is inside the basket
  482. if(checkCollide){
  483. kid_walk.animations.stop();
  484. timer.stop();
  485. if(this.func_checkOverlap(basket,kid_walk)){
  486. if(kid_walk.frame < 12)
  487. kid_walk.frame = 24;
  488. else
  489. kid_walk.frame = 25;
  490. result = true;
  491. }else{
  492. result = false;
  493. }
  494. this.func_postScore();
  495. fly = true;
  496. checkCollide = false;
  497. }
  498. //Fly animation
  499. if(fly){
  500. if(flyCounter==0){
  501. if(result){
  502. if(audioStatus){
  503. okSound.play();
  504. }
  505. passedLevels++;
  506. if(debugMode) console.log("passedLevels = "+passedLevels);
  507. okImg.alpha = 1;
  508. }else{
  509. if(audioStatus){
  510. errorSound.play();
  511. }
  512. errorImg.alpha = 1;
  513. }
  514. }
  515. flyCounter += 1;
  516. balloon.y -= 2;
  517. basket.y -= 2;
  518. if(result){
  519. kid_walk.y -=2;
  520. }
  521. if(flyCounter>=flyEnd){
  522. if(result){
  523. levelMove = true;
  524. }else{
  525. levelMove = false;
  526. }
  527. game.state.start('map');
  528. }
  529. }
  530. },
  531. func_updateCounter: function() {
  532. totalTime++;
  533. },
  534. func_overCircle: function(){
  535. if(!clicked){
  536. for(let i=0;i<numBlocks;i++){
  537. if(i<=this.indice){
  538. blocks.children[i].alpha = 1;
  539. }else{
  540. blocks.children[i].alpha = 0.5;
  541. }
  542. }
  543. }
  544. },
  545. func_outCircle: function(){
  546. if(!clicked){
  547. for(let i=0;i<=this.indice;i++){
  548. blocks.children[i].alpha = 0.5;
  549. }
  550. }
  551. },
  552. func_clickCircle: function(){
  553. if(!clicked){
  554. let minusBlocks = 0;
  555. for(let i=0;i<numBlocks;i++){
  556. if(i<=this.indice){
  557. fractionIndex = this.indice;
  558. blocks.children[i].alpha = 1;
  559. }else{
  560. blocks.children[i].visible = false; //Delete unselected block
  561. minusBlocks +=1; //number of blocks to reduce
  562. kid_walk.y += blockSize; //Lowering kid
  563. }
  564. }
  565. numBlocks -= minusBlocks; //Final reduced blocks
  566. balloon.alpha = 1;
  567. clicked = true;
  568. animate = true;
  569. if(audioStatus){
  570. beepSound.play();
  571. }
  572. if(blockDirection[curBlock]=='Right'){
  573. kid_walk.animations.play('right', 6, true);
  574. }else{
  575. kid_walk.animations.play('left', 6, true);
  576. }
  577. if(levelLabel){ //Hiding labels
  578. blockLabel.visible = false;
  579. blockSeparator.visible = false;
  580. }
  581. }
  582. },
  583. func_setPlace: function(){
  584. if(!clicked){
  585. balloon.x = game.input.x;
  586. basket.x = game.input.x;
  587. balloon.alpha = 1;
  588. clicked = true;
  589. animate = true;
  590. if(audioStatus){
  591. beepSound.play();
  592. }
  593. if(blockDirection[curBlock]=='Right'){
  594. kid_walk.animations.play('right', 6, true);
  595. }else{
  596. kid_walk.animations.play('left', 6, true);
  597. }
  598. if(levelLabel){ //Hiding labels
  599. blockLabel.visible = false;
  600. blockSeparator.visible = false;
  601. }
  602. }
  603. },
  604. func_postScore: function (){
  605. let abst = "numCircles:" + numBlocks + ", valCircles: " + detail + " balloonX: " + basket.x + ", selIndex: " + fractionIndex;
  606. let lang_str = "pt_BR"; //TODO NAO esta pegando a lingua definida pelo usuario!
  607. let hr = new XMLHttpRequest();
  608. // Create some variables we need to send to our PHP file
  609. let url = "php/save.php";
  610. let vars = "s_ip=" + hip + "&s_name=" + username + "&s_lang=" + lang + "&s_game=" + levelShape + "&s_mode=" + levelType;
  611. vars += "&s_oper=" + levelOperator + "&s_leve=" + levelDifficulty + "&s_posi=" + levelPosition + "&s_resu=" + result + "&s_time=" + totalTime + "&s_deta=" + abst;
  612. hr.open("POST", url, true);
  613. hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  614. hr.onreadystatechange = function() {
  615. if(debugMode) console.log(hr);
  616. if(hr.readyState == 4 && hr.status == 200) {
  617. let return_data = hr.responseText;
  618. if(debugMode) console.log(return_data);
  619. }
  620. }
  621. // Send the data to PHP now... and wait for response to update the status div
  622. hr.send(vars); // Actually execute the request
  623. if(debugMode) console.log("processing...");
  624. },
  625. func_viewHelp: function(){
  626. if(!clicked){
  627. let pointer;
  628. if(levelType=='A'){
  629. let pointer = game.add.image(endPosition, 490, 'pointer');
  630. }else{
  631. let pointer = game.add.image(blocks.children[endIndex-1].x, blocks.children[endIndex-1].y-blockSize/2, 'pointer');
  632. }
  633. pointer.anchor.setTo(0.5, 0);
  634. pointer.alpha = 0.7;
  635. }
  636. },
  637. func_checkOverlap: function (spriteA, spriteB) {
  638. let xA = spriteA.x;
  639. let xB = spriteB.x;
  640. if(Math.abs(xA-xB)>14){
  641. return false;
  642. }else{
  643. return true;
  644. }
  645. }
  646. };
  647. /****************************** END ****************************/
  648. let endCircleOne = {
  649. create: function() {
  650. // Background
  651. game.add.image(0, 0, 'bgimage');
  652. //Clouds
  653. game.add.image(300, 100, 'cloud');
  654. game.add.image(660, 80, 'cloud');
  655. game.add.image(110, 85, 'cloud').scale.setTo(0.8);
  656. // Styles for labels
  657. let stylePlace = { font: '26px Arial', fill: '#400080', align: 'center'};
  658. let styleLabel = { font: '26px Arial', fill: '#000080', align: 'center'};
  659. let styleMenu = { font: '30px Arial', fill: '#000000', align: 'center'};
  660. //Floor
  661. for(let i=0;i<9;i++){
  662. game.add.image(i*100, 501, 'floor');
  663. }
  664. // Progress bar
  665. for(let p=1;p<=5;p++){
  666. let block = game.add.image(660+(p-1)*30, 10, 'block');
  667. block.scale.setTo(2, 1); //Scaling to double width
  668. }
  669. game.add.text(820, 10, '100%', styleMenu);
  670. game.add.text(650, 10, lang.difficulty + ' ' + levelDifficulty, styleMenu).anchor.setTo(1,0);
  671. game.add.image(660, 10, 'pgbar');
  672. //School and trees
  673. game.add.sprite(600, 222 , 'school').scale.setTo(0.7);
  674. game.add.sprite(30, 280 , 'tree4');
  675. game.add.sprite(360, 250 , 'tree2');
  676. //kid
  677. this.kid = game.add.sprite(0, -152 , 'kid_run');
  678. this.kid.anchor.setTo(0.5,0.5);
  679. this.kid.scale.setTo(0.7);
  680. let walk = this.kid.animations.add('walk', [0,1,2,3,4,5,6,7,8,9,10,11]);
  681. //globo
  682. this.balloon = game.add.sprite(0, -260, 'balloon');
  683. this.balloon.anchor.setTo(0.5,0.5);
  684. this.basket = game.add.sprite(0, -150, 'balloon_basket');
  685. this.basket.anchor.setTo(0.5,0.5);
  686. },
  687. update: function() {
  688. if(this.kid.y>=460){
  689. this.kid.animations.play('walk', 6, true);
  690. if(this.kid.x<=700){
  691. this.kid.x += 2;
  692. }else{
  693. if(levelMenu){
  694. passedLevels = 0;
  695. game.state.start('menu');
  696. }else{
  697. this.kid.animations.stop();
  698. }
  699. }
  700. }else{
  701. this.balloon.y += 2;
  702. this.basket.y += 2;
  703. this.kid.y +=2;
  704. this.balloon.x += 1;
  705. this.basket.x += 1;
  706. this.kid.x +=1;
  707. }
  708. },
  709. func_verPrincipal: function(){
  710. game.state.start('welcome');
  711. },
  712. };