circleOne.js 37 KB

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