map.js 6.5 KB

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