1
0

circleOne.js 41 KB

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