circleOne.js 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051
  1. /*
  2. var menuCircleOne = {
  3. create: function(){},
  4. ---------------------------- end of phaser functions
  5. loadMap: function(){}
  6. };
  7. var mapCircleOne = {
  8. create: function(){},
  9. update: function(){},
  10. ---------------------------- end of phaser functions
  11. loadGame: function()
  12. };
  13. var gameCircleOne = {
  14. create: function(){},
  15. update: function(){},
  16. ---------------------------- end of phaser functions
  17. updateCounter: function(){},
  18. overCircle: function(){},
  19. outCircle: function(){},
  20. clickCircle: function(){},
  21. setPlace: function(){},
  22. postScore: function(){},
  23. viewHelp: function(){},
  24. checkOverlap: function(_,_){}
  25. //getRndDivisor: function(){}
  26. };
  27. var endCircleOne = {
  28. create: function(){},
  29. update: function(){},
  30. ---------------------------- end of phaser functions
  31. verPrincipal: function(){},
  32. verMenu: function(){}
  33. };
  34. */
  35. // Kid and Circle states, games 1 and 2
  36. /****************************** MENU ****************************/
  37. var stairsPlus, stairsMinus, stairsMixed;
  38. var menuCircleOne = {
  39. create: function() {
  40. // Creating sound variable
  41. var beepSound = game.add.audio('sound_beep');
  42. // Menu options
  43. buttonSettings["addButtons"](1,1,
  44. 0,1,0,
  45. 1,0,
  46. 0,0);
  47. // Setting title
  48. var style = { font: '28px Arial', fill: '#00804d'};
  49. var title = game.add.text(game.world.centerX, 40, lang.game_menu_title, style);
  50. title.anchor.setTo(0.5, 0.5);
  51. //Showing Games and Levels
  52. var maxHeight = 120; //Max height of a stair
  53. var stairHeight = 29; //height growth of a stair
  54. var stairWidth = 85; //Width of a stair
  55. var startStair = 240;
  56. var startSymbol = 150;
  57. var startCircle = (startSymbol/2)+startStair+stairWidth*5;
  58. //First stairs, plus, 5 levels, blue circle
  59. var blueCircle = game.add.graphics(startCircle, 195);
  60. blueCircle.anchor.setTo(0.5,0.5);
  61. blueCircle.lineStyle(2, 0x31314e);
  62. blueCircle.beginFill(0xefeff5);
  63. blueCircle.drawCircle(0, 0, 60);
  64. blueCircle.endFill();
  65. var r_arrow = game.add.sprite(startSymbol+40, 195, 'h_arrow');
  66. r_arrow.scale.setTo(0.35);
  67. r_arrow.anchor.setTo(0.5,0.5);
  68. r_arrow.alpha = 0.8;
  69. var r_arrow2 = game.add.sprite(startSymbol, 195, 'kid_walk');
  70. r_arrow2.scale.setTo(0.6);
  71. r_arrow2.anchor.setTo(0.5,0.5);
  72. r_arrow2.alpha = 0.8;
  73. stairsPlus = [];
  74. for(var i=1;i<=5;i++){
  75. //stair
  76. var x1 = startStair+(stairWidth*(i-1));
  77. var y1 = 135+maxHeight-i*stairHeight;
  78. var x2 = stairWidth;//x1 + 40;
  79. var y2 = stairHeight*i;//y1 + 24;
  80. stairsPlus[i] = game.add.graphics(0, 0);
  81. stairsPlus[i].lineStyle(1, 0xFFFFFF, 1);
  82. stairsPlus[i].beginFill(0x99b3ff);
  83. stairsPlus[i].drawRect(x1, y1, x2, y2);
  84. stairsPlus[i].endFill();
  85. //event
  86. stairsPlus[i].inputEnabled = true;
  87. stairsPlus[i].input.useHandCursor = true;
  88. stairsPlus[i].events.onInputDown.add(this.loadMap, {beep: beepSound, difficulty: i, operator: 'Plus' });
  89. stairsPlus[i].events.onInputOver.add(function (item) { item.alpha=0.5; }, this);
  90. stairsPlus[i].events.onInputOut.add(function (item) { item.alpha=1; }, this);
  91. //label
  92. var xl = x1+stairWidth/2; //x label
  93. var yl = y1+(stairHeight*i)/2; //y label
  94. var label = game.add.text(xl, yl, i, { font: '25px Arial', fill: '#ffffff', align: 'center' });
  95. label.anchor.setTo(0.5, 0.4);
  96. }
  97. //Second stairs, minus, 5 levels, red circle
  98. var redCircle = game.add.graphics(startCircle, 350);
  99. redCircle.anchor.setTo(0.5,0.5);
  100. redCircle.lineStyle(2, 0xb30000);
  101. redCircle.beginFill(0xefeff5);
  102. redCircle.drawCircle(0, 0, 60);
  103. redCircle.endFill();
  104. var l_arrow2 = game.add.sprite(startSymbol, 350, 'h_arrow');
  105. l_arrow2.scale.setTo(-0.35, 0.35);
  106. l_arrow2.anchor.setTo(0.5,0.5);
  107. l_arrow2.alpha = 0.8;
  108. var l_arrow = game.add.sprite(startSymbol+40, 350, 'kid_walk');
  109. l_arrow.scale.setTo(-0.6, 0.6);
  110. l_arrow.anchor.setTo(0.5,0.5);
  111. l_arrow.alpha = 0.8;
  112. var stairsMinus = [];
  113. for(var i=1;i<=5;i++){
  114. //stair
  115. var x1 = startStair+(stairWidth*(i-1));
  116. var y1 = 285+maxHeight-i*stairHeight;
  117. var x2 = stairWidth;//x1 + 40;
  118. var y2 = stairHeight*i;//y1 + 24;
  119. stairsMinus[i] = game.add.graphics(0, 0);
  120. stairsMinus[i].lineStyle(1, 0xFFFFFF, 1);
  121. stairsMinus[i].beginFill(0xff6666);
  122. stairsMinus[i].drawRect(x1, y1, x2, y2);
  123. stairsMinus[i].endFill();
  124. //event
  125. stairsMinus[i].inputEnabled = true;
  126. stairsMinus[i].input.useHandCursor = true;
  127. stairsMinus[i].events.onInputDown.add(this.loadMap, {beep: beepSound, difficulty: i, operator: 'Minus' });
  128. stairsMinus[i].events.onInputOver.add(function (item) { item.alpha=0.5; }, this);
  129. stairsMinus[i].events.onInputOut.add(function (item) { item.alpha=1; }, this);
  130. //label
  131. var xl = x1+stairWidth/2; //x label
  132. var yl = y1+(stairHeight*i)/2; //y label
  133. var label = game.add.text(xl, yl, i, { font: '25px Arial', fill: '#ffffff', align: 'center' });
  134. label.anchor.setTo(0.5, 0.4);
  135. }
  136. //Thrid stairs, mixed, 5 levels, two circles
  137. var bCircle = game.add.graphics(startCircle-30, 500);
  138. bCircle.anchor.setTo(0.5,0.5);
  139. bCircle.lineStyle(2, 0x31314e);
  140. bCircle.beginFill(0xefeff5);
  141. bCircle.drawCircle(0, 0, 60);
  142. bCircle.endFill();
  143. var rCircle = game.add.graphics(startCircle+40, 500);
  144. rCircle.anchor.setTo(0.5,0.5);
  145. rCircle.lineStyle(2, 0xb30000);
  146. rCircle.beginFill(0xefeff5);
  147. rCircle.drawCircle(0, 0, 60);
  148. rCircle.endFill();
  149. var d_arrow = game.add.sprite(startSymbol, 500, 'h_double');
  150. d_arrow.scale.setTo(0.5);
  151. d_arrow.anchor.setTo(0.5,0.5);
  152. d_arrow.alpha = 0.8;
  153. var stairsMixed = [];
  154. for(var i=1;i<=5;i++){
  155. //stair
  156. var x1 = startStair+(stairWidth*(i-1));
  157. var y1 = 435+maxHeight-i*stairHeight;
  158. var x2 = stairWidth;//x1 + 40;
  159. var y2 = stairHeight*i;//y1 + 24;
  160. stairsMixed[i] = game.add.graphics(0, 0);
  161. stairsMixed[i].lineStyle(1, 0xFFFFFF, 1);
  162. stairsMixed[i].beginFill(0xb366ff);
  163. stairsMixed[i].drawRect(x1, y1, x2, y2);
  164. stairsMixed[i].endFill();
  165. //event
  166. stairsMixed[i].inputEnabled = true;
  167. stairsMixed[i].input.useHandCursor = true;
  168. stairsMixed[i].events.onInputDown.add(this.loadMap, {beep: beepSound, difficulty: i, operator: 'Mixed' });
  169. stairsMixed[i].events.onInputOver.add(function (item) { item.alpha=0.5; }, this);
  170. stairsMixed[i].events.onInputOut.add(function (item) { item.alpha=1; }, this);
  171. //label
  172. var xl = x1+stairWidth/2; //x label
  173. var yl = y1+(stairHeight*i)/2; //y label
  174. var label = game.add.text(xl, yl, i, { font: '25px Arial', fill: '#ffffff', align: 'center' });
  175. label.anchor.setTo(0.5, 0.4);
  176. }
  177. },
  178. //MapLoading function
  179. loadMap: function(){
  180. if(audioStatus){
  181. this.beep.play();
  182. }
  183. onePosition = 0; //Map position
  184. oneMove = true; //Move no next point
  185. oneDifficulty = this.difficulty; //Number of difficulty (1 to 5)
  186. oneOperator = this.operator; //Operator of game
  187. if(onePosition<5){
  188. game.state.start('mapCOne');
  189. }else{
  190. game.state.start('unofinal');
  191. }
  192. }
  193. };
  194. /****************************** MAP *****************************/
  195. var mapCircleOne = {
  196. create: function() {
  197. // Creating sound variable
  198. beepSound = game.add.audio('sound_beep');
  199. // Background
  200. game.add.image(0, 40, 'bgmap');
  201. // Menu options
  202. buttonSettings["addButtons"](1,0,
  203. 1,1,0,
  204. 0,0,
  205. "menuCOne",0);
  206. // Styles for labels
  207. var stylePlace = { font: '26px Arial', fill: '#ffffff', align: 'center'};
  208. var styleMenu = { font: '30px Arial', fill: '#000000', align: 'center'};
  209. // Progress bar
  210. var percentText = onePosition*25;
  211. var percentBlocks = onePosition;
  212. for(var p=0;p<percentBlocks;p++){
  213. var block = game.add.image(660+p*37, 10, 'block');
  214. block.scale.setTo(2.5, 1); //Scaling to double width
  215. }
  216. game.add.text(820, 10, percentText+'%', styleMenu);
  217. game.add.text(650, 10, lang.difficulty + ' ' + oneDifficulty, styleMenu).anchor.setTo(1,0);
  218. game.add.image(660, 10, 'pgbar');
  219. //Road
  220. this.points = {
  221. 'x': [ 90, 204, 318, 432, 546, 660 ],
  222. 'y': [ 486, 422, 358, 294, 230, 166 ]
  223. };
  224. //House
  225. var house = game.add.image(this.points.x[0], this.points.y[0], 'house');
  226. house.scale.setTo(0.7);
  227. house.anchor.setTo(0.7, 0.8);
  228. //School
  229. var school = game.add.image(this.points.x[5], this.points.y[5], 'school');
  230. school.scale.setTo(0.35);
  231. school.anchor.setTo(0.2, 0.7);
  232. //Trees and Rocks
  233. this.rocks = {
  234. 'x': [156, 275, 276, 441, 452, 590, 712],
  235. 'y': [309, 543, 259, 156, 419, 136, 316]
  236. }
  237. this.r_types = [1, 1, 2, 1, 2, 2, 2];
  238. for(var i=0; i<this.r_types.length; i++){
  239. if(this.r_types[i]==1){
  240. var sprite = game.add.image(this.rocks.x[i], this.rocks.y[i], 'rock');
  241. sprite.scale.setTo(0.32);
  242. sprite.anchor.setTo(0.5, 0.95);
  243. }else if(this.r_types[i]==2){
  244. var sprite = game.add.image(this.rocks.x[i], this.rocks.y[i], 'birch');
  245. sprite.scale.setTo(0.4);
  246. sprite.anchor.setTo(0.5, 0.95);
  247. }
  248. }
  249. this.trees = {
  250. 'x': [105, 214, 354, 364, 570, 600, 740, 779],
  251. 'y': [341, 219, 180, 520, 550, 392, 488, 286]
  252. }
  253. this.t_types = [2, 4, 3, 4, 1, 2, 4, 4];
  254. for(var i=0; i<this.t_types.length; i++){
  255. var sprite = game.add.image(this.trees.x[i], this.trees.y[i], 'tree'+this.t_types[i]);
  256. sprite.scale.setTo(0.6);
  257. sprite.anchor.setTo(0.5, 0.95);
  258. }
  259. // places
  260. for (var p = 1; p < this.points.x.length -1; p++){
  261. var place;
  262. if(p<onePosition)
  263. place = game.add.image(this.points.x[p], this.points.y[p], 'place_b');
  264. else if (oneMove && p==onePosition)
  265. place = game.add.image(this.points.x[p], this.points.y[p], 'place_b');
  266. else
  267. place = game.add.image(this.points.x[p], this.points.y[p], 'place_a');
  268. place.anchor.setTo(0.5, 0.5);
  269. place.scale.setTo(0.3);
  270. var sign = game.add.image(this.points.x[p]-20, this.points.y[p]-60, 'sign');
  271. sign.anchor.setTo(0.5, 1);
  272. sign.scale.setTo(0.4);
  273. if(p>0 && p<this.points.x.length-1){
  274. var text = game.add.text(this.points.x[p]-23, this.points.y[p]-84, p, stylePlace);
  275. text.anchor.setTo(0.35, 0.5);
  276. }
  277. }
  278. // Kid start position
  279. this.kid = game.add.sprite(this.points.x[onePosition], this.points.y[onePosition], 'kid_run');
  280. this.kid.anchor.setTo(0.5,1);
  281. this.kid.scale.setTo(0.5);
  282. game.physics.arcade.enable(this.kid);
  283. this.kid.animations.add('run');
  284. this.kid.animations.play('run', 6, true);
  285. // Delay to next level
  286. this.count = 0;
  287. this.wait = 60;
  288. },
  289. update: function() {
  290. // Wait 2 seconds before moving or staring a game
  291. this.count ++;
  292. if(this.count<=this.wait) return;
  293. // If movement is stopped or position is 6 (final), load game
  294. if(onePosition==6){
  295. oneMove = false;
  296. }
  297. if(!oneMove){
  298. this.loadGame();
  299. }
  300. // If momevent is enabled, move to next point from actual
  301. if(oneMove){
  302. game.physics.arcade.moveToXY(
  303. this.kid,
  304. this.points.x[onePosition+1],
  305. this.points.y[onePosition+1],
  306. 100
  307. );
  308. // I kid reached the end, stop movement
  309. if(Math.ceil(this.kid.x)==this.points.x[onePosition+1] || Math.ceil(this.kid.y)==this.points.y[onePosition+1]){
  310. oneMove=false;
  311. onePosition += 1; //Update position
  312. }
  313. }
  314. },
  315. //MapLoading function
  316. loadGame: function(){
  317. if(audioStatus){
  318. beepSound.play();
  319. }
  320. if(onePosition<5){
  321. game.state.start('gameCOne');
  322. }else{
  323. game.state.start('endCOne');
  324. }
  325. }
  326. };
  327. /****************************** GAME ****************************/
  328. var startX; //start position
  329. var clicked, hideLabels, animate, checkCollide, result, hasFigure; //control variables
  330. var detail;
  331. var endPosition;
  332. var fractionClicked, fractionIndex;
  333. //Balloon and blocks control
  334. var blocks, maxBlocks, numBlocks, curBlock, blockDirection, blockDistance, blockLabel, blockSeparator;
  335. var blockSize, blockAngle, blockTraceColor;
  336. var fly, flyCounter, flyend; //flyvariables
  337. var trace; //circle trace
  338. var numPlus, endIndex;
  339. var kid_walk, balloon, basket;
  340. var balloonPlace;
  341. var gameCircleOne = {
  342. create: function() {
  343. //timer
  344. totalTime = 0;
  345. timer = game.time.create(false);
  346. timer.loop(1000, this.updateCounter, this);
  347. timer.start();
  348. detail="";
  349. // Creating sound variable
  350. beepSound = game.add.audio('sound_beep');
  351. okSound = game.add.audio('sound_ok');
  352. errorSound = game.add.audio('sound_error');
  353. // Background
  354. game.add.image(0, 0, 'bgimage');
  355. // Menu options
  356. buttonSettings["addButtons"](1,1,
  357. 1,1,1,
  358. 1,0,
  359. "menuCOne", this.viewHelp);
  360. //Clouds
  361. game.add.image(300, 100, 'cloud');
  362. game.add.image(660, 80, 'cloud');
  363. game.add.image(110, 85, 'cloud').scale.setTo(0.8);
  364. // Styles for labels
  365. var stylePlace = { font: '26px Arial', fill: '#400080', align: 'center'};
  366. var styleLabel = { font: '26px Arial', fill: '#000080', align: 'center'};
  367. var styleMenu = { font: '30px Arial', fill: '#000000', align: 'center'};
  368. //Floor and road
  369. startX = 66; //Initial kid and place position
  370. if(oneOperator=='Minus') startX = 66+5*156;
  371. placeDistance = 156; //Distance between places
  372. blockSize = 60;
  373. for(var i=0;i<9;i++){
  374. game.add.image(i*100, 501, 'floor');
  375. }
  376. var road = game.add.image(47, 515, 'road');
  377. road.scale.setTo(1.01,0.94);
  378. if(oneType=='A'){
  379. road.inputEnabled = true;
  380. road.events.onInputDown.add(this.setPlace, {beep: beepSound}); //enabling input for tablets
  381. }
  382. for(var p=0;p<=5;p++){// Places
  383. var place = game.add.image(66+p*placeDistance, 526, 'place_a');
  384. place.anchor.setTo(0.5);
  385. place.scale.setTo(0.3);
  386. game.add.text(66+p*placeDistance, 560, p , stylePlace).anchor.setTo(0.5);
  387. }
  388. //Control variables
  389. clicked = false; //Air ballon positioned
  390. hideLabels = false; //Labels animations
  391. animate = false; //Start move animation
  392. checkCollide = false; //Check kid inside ballon's basket
  393. result = false; //Game is correct
  394. fly = false; //Start ballon fly animation
  395. flyCounter = 0; //Fly counter
  396. flyEnd = 140; //Fly end counter
  397. hasFigure = false; //If has level figure
  398. //trace
  399. trace = this.add.bitmapData(this.game.width, this.game.height);
  400. trace.addToWorld();
  401. trace.clear();
  402. //generator
  403. //Circles and fractions
  404. var maxBlocks = onePosition+1; //Maximum blocks according to difficulty
  405. if(oneType=='B' || oneOperator=='Mixed') maxBlocks = 6;
  406. blocks = game.add.group(); //Fraction arrays
  407. numBlocks = game.rnd.integerInRange(onePosition, maxBlocks); //Number of blocks
  408. curBlock = 0; //Actual index block
  409. blockDirection = []; //Directions right(plus), left (minus)
  410. blockDistance = []; //Displacement distance of the blocks
  411. blockLabel = game.add.group(); //Labels of the blocks
  412. blockSeparator = game.add.group(); //Separator of the labels
  413. blockAngle = []; //Angles of blocks
  414. blockTraceColor = []; //Trace colors
  415. endPosition = startX; //Ending position, accumulative
  416. //Game B exclusive variables
  417. balloonPlace = this.game.world.centerX; //Fixed place for ballon (game B)
  418. fractionClicked = false; //If clicked a fraction (game B)
  419. fractionIndex = -1; //Index of clicked fraction (game B)
  420. numPlus = game.rnd.integerInRange(1, numBlocks-1);
  421. for(var p=0;p<numBlocks;p++){
  422. var portion = game.rnd.integerInRange(1, oneDifficulty); //Portion of the circle, according to difficulty
  423. detail += portion+",";
  424. if(portion==oneDifficulty){
  425. hasFigure = true;
  426. }
  427. var direction = '';
  428. var lineColor = '';
  429. if(oneOperator=='Mixed'){
  430. if(p<=numPlus){
  431. direction = 'Right';
  432. lineColor = 0x31314e;
  433. }else{
  434. direction = 'Left';
  435. lineColor = 0xb30000;
  436. }
  437. /*var directions = ['Right','Left'];
  438. var rndIndex = game.rnd.integerInRange(0, 1);
  439. direction = directions[rndIndex];
  440. if(rndIndex==0) lineColor = 0x31314e;
  441. else lineColor = 0xb30000;*/
  442. }else if(oneOperator=='Plus'){
  443. direction = 'Right';
  444. lineColor = 0x31314e;
  445. }else if(oneOperator=='Minus'){
  446. direction = 'Left';
  447. lineColor = 0xb30000;
  448. }
  449. blockTraceColor[p] = lineColor;
  450. var block = game.add.graphics(startX, 490-p*blockSize);
  451. block.anchor.setTo(0.5,0.5);
  452. block.lineStyle(2, lineColor);
  453. block.beginFill(0xefeff5);
  454. if (direction == 'Right') block.scale.y *= -1;
  455. blockDirection[p] = direction;
  456. if(portion==1){
  457. block.drawCircle(0, 0, blockSize);
  458. blockDistance.push(placeDistance);
  459. blockAngle.push(360);
  460. if(oneLabel){
  461. var labelX = startX;
  462. if(oneOperator=='Minus') labelX -= 65;
  463. else labelX += 65;
  464. var label = game.add.text(labelX, 490-p*blockSize, portion , styleLabel);
  465. label.anchor.setTo(0.5, 0.5);
  466. blockLabel.add(label);
  467. }
  468. }else{
  469. var distance = 360/portion+5;
  470. block.arc(0, 0, blockSize/2, game.math.degToRad(distance), 0, true);
  471. blockDistance.push(Math.floor(placeDistance/portion));
  472. blockAngle.push(distance);
  473. if(oneLabel){
  474. var labelX = startX;
  475. if(oneOperator=='Minus') labelX -= 65;
  476. else labelX += 65;
  477. var separator = game.add.sprite(labelX, 485-p*blockSize, 'separator');
  478. separator.anchor.setTo(0.5, 0.5);
  479. blockSeparator.add(separator);
  480. var label = game.add.text(labelX, 488-p*blockSize, '1\n'+portion , styleLabel);
  481. label.anchor.setTo(0.5, 0.5);
  482. blockLabel.add(label);
  483. }
  484. }
  485. if(direction=='Right'){
  486. endPosition += Math.floor(placeDistance/portion);
  487. }else if(direction=='Left'){
  488. endPosition -= Math.floor(placeDistance/portion);
  489. }
  490. block.endFill();
  491. block.angle +=90;
  492. //If game is type B, (select fractions, adding event)
  493. if(oneType=='B'){
  494. block.alpha = 0.5;
  495. block.inputEnabled = true;
  496. block.input.useHandCursor = true;
  497. block.events.onInputDown.add(this.clickCircle, {indice: p});
  498. block.events.onInputOver.add(this.overCircle, {indice: p});
  499. block.events.onInputOut.add(this.outCircle, {indice: p});
  500. }
  501. blocks.add(block);
  502. }
  503. //Calculate next block
  504. if(blockDirection[curBlock]=='Right'){
  505. nextEnd = startX+blockDistance[curBlock];
  506. }else{
  507. nextEnd = startX-blockDistance[curBlock];
  508. }
  509. //If game is type B, selectiong a random balloon place
  510. if(oneType=='B'){
  511. balloonPlace = startX;
  512. endIndex = game.rnd.integerInRange(numPlus, numBlocks);
  513. for(var i=0;i<endIndex;i++){
  514. if(blockDirection[i]=='Right')
  515. balloonPlace += blockDistance[i];
  516. else if(blockDirection[i]=='Left')
  517. balloonPlace -= blockDistance[i];
  518. }
  519. if(balloonPlace<66 || balloonPlace>66+5*placeDistance || !hasFigure){
  520. game.state.start('gameCOne');
  521. }
  522. }
  523. //If end position is out of bounds, restart
  524. if (endPosition<66 || endPosition>66+3*260 || !hasFigure){
  525. game.state.start('gameCOne');
  526. }
  527. //kid
  528. kid_walk = game.add.sprite(startX, 495-numBlocks*blockSize, 'kid_walk');
  529. kid_walk.anchor.setTo(0.5, 0.8);
  530. kid_walk.scale.setTo(0.8);
  531. kid_walk.animations.add('right',[0,1,2,3,4,5,6,7,8,9,10,11]);
  532. kid_walk.animations.add('left',[23,22,21,20,19,18,17,16,15,14,13,12]);
  533. if(oneOperator=='Minus'){
  534. kid_walk.animations.play('left', 6, true);
  535. kid_walk.animations.stop();
  536. }
  537. //globo
  538. balloon = game.add.sprite(balloonPlace, 350, 'balloon');
  539. balloon.anchor.setTo(0.5, 0.5);
  540. balloon.alpha = 0.5;
  541. basket = game.add.sprite(balloonPlace, 472, 'balloon_basket');
  542. basket.anchor.setTo(0.5, 0.5);
  543. //ok and error images
  544. okImg = game.add.image(game.world.centerX, game.world.centerY, 'h_ok');
  545. okImg.anchor.setTo(0.5);
  546. okImg.alpha = 0;
  547. errorImg = game.add.image(game.world.centerX, game.world.centerY, 'h_error');
  548. errorImg.anchor.setTo(0.5);
  549. errorImg.alpha = 0;
  550. },
  551. update: function() {
  552. if (game.input.activePointer.isDown && !fly && !clicked){
  553. //Positionate balloon - Game A
  554. if(oneType=='A'){
  555. if(game.input.mousePointer.y>60){ //Dead zone for click
  556. balloon.x = game.input.mousePointer.x;
  557. balloon.alpha = 1;
  558. clicked = true;
  559. animate = true;
  560. if(audioStatus){
  561. beepSound.play();
  562. }
  563. if(blockDirection[curBlock]=='Right'){
  564. kid_walk.animations.play('right', 6, true);
  565. }else{
  566. kid_walk.animations.play('left', 6, true);
  567. }
  568. if(oneLabel){ //Hiding labels
  569. blockLabel.visible = false;
  570. blockSeparator.visible = false;
  571. }
  572. }
  573. }
  574. }
  575. if(!clicked){
  576. if(!fly){
  577. if(oneType=="A"){
  578. //Follow mouse
  579. if (game.physics.arcade.distanceToPointer(balloon, game.input.activePointer) > 8){
  580. balloon.x = game.input.mousePointer.x;
  581. basket.x = game.input.mousePointer.x;
  582. }
  583. }
  584. }
  585. }
  586. //Start animation
  587. if(animate){
  588. var color = '';
  589. if(blockDirection[curBlock]=='Right'){
  590. kid_walk.x+=2;
  591. color = 'rgba(0, 51, 153, 1)';
  592. }else if(blockDirection[curBlock]=='Left'){
  593. kid_walk.x-=2;
  594. color = 'rgba(179, 0, 0, 1)';
  595. }
  596. trace.rect(kid_walk.x, 526, 2, 2, color);
  597. for(var i=0;i<numBlocks;i++){ //Moving every block
  598. if(blockDirection[curBlock]=='Right'){
  599. blocks.children[i].x +=2;
  600. }else{
  601. blocks.children[i].x -=2;
  602. }
  603. }
  604. blockAngle[curBlock] -= 4.6;
  605. blocks.children[curBlock].clear();
  606. blocks.children[curBlock].lineStyle(2, blockTraceColor[curBlock]);
  607. blocks.children[curBlock].beginFill(0xefeff5);
  608. blocks.children[curBlock].arc(0, 0, blockSize/2, game.math.degToRad(blockAngle[curBlock]), 0, true);
  609. blocks.children[curBlock].endFill();
  610. if(blockDirection[curBlock]=='Right'){
  611. if(blocks.children[curBlock].x>=nextEnd){
  612. blocks.children[curBlock].visible = false;
  613. blocks.y += blockSize;
  614. kid_walk.y += blockSize;
  615. curBlock+=1;
  616. if(blockDirection[curBlock]=='Right'){
  617. nextEnd += blockDistance[curBlock];
  618. kid_walk.animations.play('right', 6, true);
  619. }else if(blockDirection[curBlock]=='Left'){
  620. nextEnd -= blockDistance[curBlock];
  621. kid_walk.animations.play('left', 6, true);
  622. }
  623. }
  624. }else{
  625. if(blocks.children[curBlock].x<=nextEnd){
  626. blocks.children[curBlock].visible = false;
  627. blocks.y += blockSize;
  628. kid_walk.y += blockSize;
  629. curBlock+=1;
  630. if(blockDirection[curBlock]=='Right'){
  631. nextEnd += blockDistance[curBlock];
  632. kid_walk.animations.play('right', 6, true);
  633. }else if(blockDirection[curBlock]=='Left'){
  634. nextEnd -= blockDistance[curBlock];
  635. kid_walk.animations.play('left', 6, true);
  636. }
  637. }
  638. }
  639. if(curBlock==numBlocks ){ //Final position
  640. animate= false;
  641. checkCollide = true;
  642. }
  643. }
  644. //Check if kid is inside the basket
  645. if(checkCollide){
  646. kid_walk.animations.stop();
  647. timer.stop();
  648. if(this.checkOverlap(basket,kid_walk)){
  649. if(kid_walk.frame < 12)
  650. kid_walk.frame = 24;
  651. else
  652. kid_walk.frame = 25;
  653. result = true;
  654. }else{
  655. result = false;
  656. }
  657. this.postScore();
  658. fly = true;
  659. checkCollide = false;
  660. }
  661. //Fly animation
  662. if(fly){
  663. if(flyCounter==0){
  664. if(result){
  665. if(audioStatus){
  666. okSound.play();
  667. }
  668. okImg.alpha = 1;
  669. }else{
  670. if(audioStatus){
  671. errorSound.play();
  672. }
  673. errorImg.alpha = 1;
  674. }
  675. }
  676. flyCounter += 1;
  677. balloon.y -= 2;
  678. basket.y -= 2;
  679. if(result){
  680. kid_walk.y -=2;
  681. }
  682. if(flyCounter>=flyEnd){
  683. if(result){
  684. oneMove = true;
  685. }else{
  686. oneMove = false;
  687. }
  688. game.state.start('mapCOne');
  689. }
  690. }
  691. },
  692. updateCounter: function() {
  693. totalTime++;
  694. },
  695. overCircle: function(){
  696. if(!clicked){
  697. for(var i=0;i<numBlocks;i++){
  698. if(i<=this.indice){
  699. blocks.children[i].alpha = 1;
  700. }else{
  701. blocks.children[i].alpha = 0.5;
  702. }
  703. }
  704. }
  705. },
  706. outCircle: function(){
  707. if(!clicked){
  708. for(var i=0;i<=this.indice;i++){
  709. blocks.children[i].alpha = 0.5;
  710. }
  711. }
  712. },
  713. clickCircle: function(){
  714. if(!clicked){
  715. var minusBlocks = 0;
  716. for(var i=0;i<numBlocks;i++){
  717. if(i<=this.indice){
  718. fractionIndex = this.indice;
  719. blocks.children[i].alpha = 1;
  720. }else{
  721. blocks.children[i].visible = false; //Delete unselected block
  722. minusBlocks +=1; //number of blocks to reduce
  723. kid_walk.y += blockSize; //Lowering kid
  724. }
  725. }
  726. numBlocks -= minusBlocks; //Final reduced blocks
  727. balloon.alpha = 1;
  728. clicked = true;
  729. animate = true;
  730. if(audioStatus){
  731. beepSound.play();
  732. }
  733. if(blockDirection[curBlock]=='Right'){
  734. kid_walk.animations.play('right', 6, true);
  735. }else{
  736. kid_walk.animations.play('left', 6, true);
  737. }
  738. if(oneLabel){ //Hiding labels
  739. blockLabel.visible = false;
  740. blockSeparator.visible = false;
  741. }
  742. }
  743. },
  744. setPlace: function(){
  745. if(!clicked){
  746. balloon.x = game.input.x;
  747. basket.x = game.input.x;
  748. balloon.alpha = 1;
  749. clicked = true;
  750. animate = true;
  751. if(audioStatus){
  752. beepSound.play();
  753. }
  754. if(blockDirection[curBlock]=='Right'){
  755. kid_walk.animations.play('right', 6, true);
  756. }else{
  757. kid_walk.animations.play('left', 6, true);
  758. }
  759. if(oneLabel){ //Hiding labels
  760. blockLabel.visible = false;
  761. blockSeparator.visible = false;
  762. }
  763. }
  764. },
  765. postScore: function (){
  766. var abst = "numCircles:"+numBlocks+", valCircles: " + detail+" balloonX: " + basket.x + ", selIndex: " + fractionIndex;
  767. var lang_str = "pt_BR"; //TODO NAO esta pegando a lingua definida pelo usuario!
  768. var hr = new XMLHttpRequest();
  769. // Create some variables we need to send to our PHP file
  770. var url = "assets/cn/save.php";
  771. var vars = "s_ip=" + hip + "&s_name=" + username + "&s_lang=" + lang + "&s_game=" + oneShape + "&s_mode=" + oneType;
  772. vars += "&s_oper=" + oneOperator + "&s_leve=" + oneDifficulty + "&s_posi=" + onePosition + "&s_resu=" + result + "&s_time=" + totalTime + "&s_deta=" + abst;
  773. hr.open("POST", url, true);
  774. hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  775. hr.onreadystatechange = function() {
  776. if(debugmode) console.log(hr);
  777. if(hr.readyState == 4 && hr.status == 200) {
  778. var return_data = hr.responseText;
  779. if(debugmode) console.log(return_data);
  780. }
  781. }
  782. // Send the data to PHP now... and wait for response to update the status div
  783. hr.send(vars); // Actually execute the request
  784. if(debugmode) console.log("processing...");
  785. },
  786. viewHelp: function(){
  787. if(!clicked){
  788. var pointer;
  789. if(oneType=='A'){
  790. var pointer = game.add.image(endPosition, 490, 'pointer');
  791. }else{
  792. var pointer = game.add.image(blocks.children[endIndex-1].x, blocks.children[endIndex-1].y-blockSize/2, 'pointer');
  793. }
  794. pointer.anchor.setTo(0.5, 0);
  795. pointer.alpha = 0.7;
  796. }
  797. },
  798. checkOverlap: function (spriteA, spriteB) {
  799. var xA = spriteA.x;
  800. var xB = spriteB.x;
  801. if(Math.abs(xA-xB)>14){
  802. return false;
  803. }else{
  804. return true;
  805. }
  806. }
  807. };
  808. /****************************** END ****************************/
  809. var endCircleOne = {
  810. create: function() {
  811. // Creating sound variable
  812. beepSound = game.add.audio('sound_beep');
  813. okSound = game.add.audio('sound_ok');
  814. errorSound = game.add.audio('sound_error');
  815. // Background
  816. game.add.image(0, 0, 'bgimage');
  817. //Clouds
  818. game.add.image(300, 100, 'cloud');
  819. game.add.image(660, 80, 'cloud');
  820. game.add.image(110, 85, 'cloud').scale.setTo(0.8);
  821. // Styles for labels
  822. var stylePlace = { font: '26px Arial', fill: '#400080', align: 'center'};
  823. var styleLabel = { font: '26px Arial', fill: '#000080', align: 'center'};
  824. var styleMenu = { font: '30px Arial', fill: '#000000', align: 'center'};
  825. //Floor
  826. for(var i=0;i<9;i++){
  827. game.add.image(i*100, 501, 'floor');
  828. }
  829. // Progress bar
  830. for(var p=1;p<=5;p++){
  831. var block = game.add.image(660+(p-1)*30, 10, 'block');
  832. block.scale.setTo(2, 1); //Scaling to double width
  833. }
  834. game.add.text(820, 10, '100%', styleMenu);
  835. game.add.text(650, 10, lang.difficulty + ' ' + oneDifficulty, styleMenu).anchor.setTo(1,0);
  836. game.add.image(660, 10, 'pgbar');
  837. //School and trees
  838. game.add.sprite(600, 222 , 'school').scale.setTo(0.7);
  839. game.add.sprite(30, 280 , 'tree4');
  840. game.add.sprite(360, 250 , 'tree2');
  841. //kid
  842. this.kid = game.add.sprite(0, -152 , 'kid_run');
  843. this.kid.anchor.setTo(0.5,0.5);
  844. this.kid.scale.setTo(0.7);
  845. var walk = this.kid.animations.add('walk', [0,1,2,3,4,5,6,7,8,9,10,11]);
  846. //globo
  847. this.balloon = game.add.sprite(0, -260, 'balloon');
  848. this.balloon.anchor.setTo(0.5,0.5);
  849. this.basket = game.add.sprite(0, -150, 'balloon_basket');
  850. this.basket.anchor.setTo(0.5,0.5);
  851. },
  852. update: function() {
  853. if(this.kid.y>=460){
  854. this.kid.animations.play('walk', 6, true);
  855. if(this.kid.x<=700){
  856. this.kid.x += 2;
  857. }else{
  858. if(oneMenu){
  859. game.state.start('menu');
  860. }else{
  861. this.kid.animations.stop();
  862. }
  863. }
  864. }else{
  865. this.balloon.y += 2;
  866. this.basket.y += 2;
  867. this.kid.y +=2;
  868. this.balloon.x += 1;
  869. this.basket.x += 1;
  870. this.kid.x +=1;
  871. }
  872. },
  873. verPrincipal: function(){
  874. game.state.start('welcome');
  875. },
  876. verMenu: function(){
  877. if(oneMenu){
  878. game.state.start('menu');
  879. }
  880. }
  881. };