circleOne.js 41 KB

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