map.js 5.8 KB

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