circleOne.js 41 KB

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