circleOne.js 37 KB

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