map.js 7.0 KB

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