map.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. var mapState = {
  2. create: function() {
  3. if(levelType=="C"){
  4. this.gameStateString = "game"+levelShape+"Two";
  5. this.endStateString = "end"+levelShape+"Two";
  6. this.menuStateString = "menu"+levelShape+"Two";
  7. }else{
  8. this.gameStateString = "game"+levelShape+"One";
  9. this.endStateString = "end"+levelShape+"One";
  10. this.menuStateString = "menu"+levelShape+"One";
  11. }
  12. // Background
  13. game.add.image(0, 40, 'bgmap');
  14. // Navigation buttons
  15. buttonSettings["func_addButtons"](1,0,
  16. 1,1,0,
  17. 0,0,
  18. this.menuStateString,0);
  19. // Styles for labels
  20. var stylePlace = { font: '26px Arial', fill: '#ffffff', align: 'center'};
  21. var styleMenu = { font: '30px Arial', fill: '#000000', align: 'center'};
  22. // Progress bar
  23. var percentText = passedLevels*25;
  24. var percentBlocks = passedLevels;
  25. for(var p=0;p<percentBlocks;p++){
  26. var block = game.add.image(660+p*37.5, 10, 'block');
  27. block.scale.setTo(2.6, 1);
  28. }
  29. game.add.text(820, 10, percentText+'%', styleMenu);
  30. game.add.text(650, 10, lang.difficulty + ' ' + levelDifficulty, styleMenu).anchor.setTo(1,0);
  31. game.add.image(660, 10, 'pgbar');
  32. //Road
  33. this.points = {
  34. 'x': [ 90, 204, 318, 432, 546, 660 ],
  35. 'y': [ 486, 422, 358, 294, 230, 166 ]
  36. };
  37. if(this.gameStateString=="gameSquareOne"){
  38. //Garage
  39. var garage = game.add.image(this.points.x[0], this.points.y[0], 'garage');
  40. garage.scale.setTo(0.4);
  41. garage.anchor.setTo(0.5, 1);
  42. //Farm
  43. var farm = game.add.image(this.points.x[5], this.points.y[5], 'farm');
  44. farm.scale.setTo(0.6);
  45. farm.anchor.setTo(0.1, 0.7);
  46. }else{
  47. //House
  48. var house = game.add.image(this.points.x[0], this.points.y[0], 'house');
  49. house.scale.setTo(0.7);
  50. house.anchor.setTo(0.7, 0.8);
  51. //School
  52. var school = game.add.image(this.points.x[5], this.points.y[5], 'school');
  53. school.scale.setTo(0.35);
  54. school.anchor.setTo(0.2, 0.7);
  55. }
  56. //Trees and Rocks
  57. this.rocks = {
  58. 'x': [156, 275, 276, 441, 452, 590, 712],
  59. 'y': [309, 543, 259, 156, 419, 136, 316]
  60. }
  61. this.r_types = [1, 1, 2, 1, 2, 2, 2];
  62. for(var i=0; i<this.r_types.length; i++){
  63. if(this.r_types[i]==1){
  64. var sprite = game.add.image(this.rocks.x[i], this.rocks.y[i], 'rock');
  65. sprite.scale.setTo(0.32);
  66. sprite.anchor.setTo(0.5, 0.95);
  67. }else if(this.r_types[i]==2){
  68. var sprite = game.add.image(this.rocks.x[i], this.rocks.y[i], 'birch');
  69. sprite.scale.setTo(0.4);
  70. sprite.anchor.setTo(0.5, 0.95);
  71. }
  72. }
  73. this.trees = {
  74. 'x': [105, 214, 354, 364, 570, 600, 740, 779],
  75. 'y': [341, 219, 180, 520, 550, 392, 488, 286]
  76. }
  77. this.t_types = [2, 4, 3, 4, 1, 2, 4, 4];
  78. for(var i=0; i<this.t_types.length; i++){
  79. var sprite = game.add.image(this.trees.x[i], this.trees.y[i], 'tree'+this.t_types[i]);
  80. sprite.scale.setTo(0.6);
  81. sprite.anchor.setTo(0.5, 0.95);
  82. }
  83. // places
  84. for (var p = 1; p < this.points.x.length -1; p++){
  85. var place;
  86. if(p<levelPosition){
  87. place = game.add.image(this.points.x[p], this.points.y[p], 'place_b');
  88. }else if (levelMove && p==levelPosition){
  89. place = game.add.image(this.points.x[p], this.points.y[p], 'place_b');
  90. }else{
  91. place = game.add.image(this.points.x[p], this.points.y[p], 'place_a');
  92. }
  93. place.anchor.setTo(0.5, 0.5);
  94. place.scale.setTo(0.3);
  95. var sign = game.add.image(this.points.x[p]-20, this.points.y[p]-60, 'sign');
  96. sign.anchor.setTo(0.5, 1);
  97. sign.scale.setTo(0.4);
  98. if(p>0 && p<this.points.x.length-1){
  99. var text = game.add.text(this.points.x[p]-23, this.points.y[p]-84, p, stylePlace);
  100. text.anchor.setTo(0.35, 0.5);
  101. }
  102. }
  103. if(this.gameStateString=="gameSquareOne"){
  104. this.character = game.add.sprite(this.points.x[levelPosition], this.points.y[levelPosition], 'tractor');
  105. var walk = this.character.animations.add('walk',[0,1,2,3,4]);
  106. this.character.animations.play('walk', 5, true);
  107. this.character.angle -= 25;
  108. }else{
  109. this.character = game.add.sprite(this.points.x[levelPosition], this.points.y[levelPosition], 'kid_run');
  110. this.character.animations.add('run');
  111. this.character.animations.play('run', 6, true);
  112. }
  113. this.character.anchor.setTo(0.5, 1);
  114. this.character.scale.setTo(0.5);
  115. game.physics.arcade.enable(this.character);
  116. // Delay to next level
  117. this.count = 0;
  118. this.wait = 60;
  119. },
  120. update: function() {
  121. // Wait 2 seconds before moving or staring a game
  122. this.count ++;
  123. if(this.count<=this.wait) return;
  124. // If movement is stopped or position is 6 (final), load game
  125. if(this.gameStateString=="gameSquareOne"){
  126. if(levelPosition==8){
  127. levelMove = false;
  128. }
  129. }else if(this.gameStateString=="gameCircleOne"){
  130. if(levelPosition==6){
  131. levelMove = false;
  132. }
  133. }else if(this.gameStateString=="gameSquareTwo"){
  134. if(levelPosition==5){
  135. levelMove = false;
  136. }
  137. }
  138. if(!levelMove){
  139. this.func_loadGame();
  140. }
  141. // If momevent is enabled, move to next point from actual
  142. if(levelMove){
  143. game.physics.arcade.moveToXY(
  144. this.character,
  145. this.points.x[levelPosition+1],
  146. this.points.y[levelPosition+1],
  147. 100
  148. );
  149. // I kid/tractor reached the end, stop movement
  150. if(Math.ceil(this.character.x)==this.points.x[levelPosition+1] || Math.ceil(this.character.y)==this.points.y[levelPosition+1]){
  151. levelMove=false;
  152. levelPosition += 1; //Update position
  153. }
  154. }
  155. },
  156. //MapLoading function
  157. func_loadGame: function(){
  158. if(audioStatus){
  159. beepSound.play();
  160. }
  161. if(levelPosition<5){
  162. game.state.start(this.gameStateString);
  163. }else{
  164. game.state.start(this.endStateString);
  165. }
  166. }
  167. };