circleOne.js 41 KB

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