circleOne.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038
  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(660+p*37, 10, 'block');
  203. block.scale.setTo(2.5, 1); //Scaling to double width
  204. }
  205. game.add.text(820, 10, percentText+'%', styleMenu);
  206. game.add.text(650, 10, lang.difficulty + ' ' + oneDifficulty, styleMenu).anchor.setTo(1,0);
  207. game.add.image(660, 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 lang_str = "pt_BR"; //TODO NAO esta pegando a lingua definida pelo usuario!
  757. var hr = new XMLHttpRequest();
  758. // Create some variables we need to send to our PHP file
  759. var url = "assets/cn/save.php";
  760. var vars = "s_ip=" + hip + "&s_name=" + username + "&s_lang=" + lang + "&s_game=" + oneShape + "&s_mode=" + oneType;
  761. vars += "&s_oper=" + oneOperator + "&s_leve=" + oneDifficulty + "&s_posi=" + onePosition + "&s_resu=" + result + "&s_time=" + totalTime + "&s_deta=" + abst;
  762. hr.open("POST", url, true);
  763. hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  764. hr.onreadystatechange = function() {
  765. console.log(hr);
  766. if(hr.readyState == 4 && hr.status == 200) {
  767. var return_data = hr.responseText;
  768. console.log(return_data);
  769. }
  770. }
  771. // Send the data to PHP now... and wait for response to update the status div
  772. hr.send(vars); // Actually execute the request
  773. console.log("processing...");
  774. },
  775. viewHelp: function(){
  776. if(!clicked){
  777. var pointer;
  778. if(oneType=='A'){
  779. var pointer = game.add.image(endPosition, 490, 'pointer');
  780. }else{
  781. var pointer = game.add.image(blocks.children[endIndex-1].x, blocks.children[endIndex-1].y-blockSize/2, 'pointer');
  782. }
  783. pointer.anchor.setTo(0.5, 0);
  784. pointer.alpha = 0.7;
  785. }
  786. },
  787. checkOverlap: function (spriteA, spriteB) {
  788. var xA = spriteA.x;
  789. var xB = spriteB.x;
  790. if(Math.abs(xA-xB)>14){
  791. return false;
  792. }else{
  793. return true;
  794. }
  795. }
  796. };
  797. /****************************** END ****************************/
  798. var endCircleOne = {
  799. create: function() {
  800. // Creating sound variable
  801. beepSound = game.add.audio('sound_beep');
  802. okSound = game.add.audio('sound_ok');
  803. errorSound = game.add.audio('sound_error');
  804. // Background
  805. game.add.image(0, 0, 'bgimage');
  806. //Clouds
  807. game.add.image(300, 100, 'cloud');
  808. game.add.image(660, 80, 'cloud');
  809. game.add.image(110, 85, 'cloud').scale.setTo(0.8);
  810. // Styles for labels
  811. var stylePlace = { font: '26px Arial', fill: '#400080', align: 'center'};
  812. var styleLabel = { font: '26px Arial', fill: '#000080', align: 'center'};
  813. var styleMenu = { font: '30px Arial', fill: '#000000', align: 'center'};
  814. //Floor
  815. for(var i=0;i<9;i++){
  816. game.add.image(i*100, 501, 'floor');
  817. }
  818. // Progress bar
  819. for(var p=1;p<=5;p++){
  820. var block = game.add.image(660+(p-1)*30, 10, 'block');
  821. block.scale.setTo(2, 1); //Scaling to double width
  822. }
  823. game.add.text(820, 10, '100%', styleMenu);
  824. game.add.text(650, 10, lang.difficulty + ' ' + oneDifficulty, styleMenu).anchor.setTo(1,0);
  825. game.add.image(660, 10, 'pgbar');
  826. //School and trees
  827. game.add.sprite(600, 222 , 'school').scale.setTo(0.7);
  828. game.add.sprite(30, 280 , 'tree4');
  829. game.add.sprite(360, 250 , 'tree2');
  830. //kid
  831. this.kid = game.add.sprite(0, -152 , 'kid_run');
  832. this.kid.anchor.setTo(0.5,0.5);
  833. this.kid.scale.setTo(0.7);
  834. var walk = this.kid.animations.add('walk', [0,1,2,3,4,5,6,7,8,9,10,11]);
  835. //globo
  836. this.balloon = game.add.sprite(0, -260, 'balloon');
  837. this.balloon.anchor.setTo(0.5,0.5);
  838. this.basket = game.add.sprite(0, -150, 'balloon_basket');
  839. this.basket.anchor.setTo(0.5,0.5);
  840. },
  841. update: function() {
  842. if(this.kid.y>=460){
  843. this.kid.animations.play('walk', 6, true);
  844. if(this.kid.x<=700){
  845. this.kid.x += 2;
  846. }else{
  847. if(oneMenu){
  848. game.state.start('menu');
  849. }else{
  850. this.kid.animations.stop();
  851. }
  852. }
  853. }else{
  854. this.balloon.y += 2;
  855. this.basket.y += 2;
  856. this.kid.y +=2;
  857. this.balloon.x += 1;
  858. this.basket.x += 1;
  859. this.kid.x +=1;
  860. }
  861. },
  862. verPrincipal: function(){
  863. game.state.start('welcome');
  864. },
  865. verMenu: function(){
  866. if(oneMenu){
  867. game.state.start('menu');
  868. }
  869. }
  870. };