menu.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. let menuState = {
  3. create: function(){},
  4. ---------------------------- end of phaser functions
  5. func_loadGame: function(){},
  6. func_showTitle: function(){},
  7. func_clearTitle: function(){},
  8. }
  9. */
  10. let menuState = {
  11. inputStartPosition: null,
  12. inputEndPosition: null,
  13. isCameraMoving: false,
  14. extraWidth: null,
  15. title: null,
  16. lbl_game: null,
  17. player_info: null,
  18. // creating game menu screen assets
  19. create: function() {
  20. if(loadAssets.levelSpriteList.length > 8){
  21. let aux = loadAssets.levelSpriteList.length-8;
  22. this.extraWidth = (aux%2==0) ? (aux/2)*235 : ((aux+1)/2)*235;
  23. }else{
  24. this.extraWidth = 0;
  25. }
  26. // CAMERA
  27. this.game.world.setBounds(0, 0, this.game.world.width + this.extraWidth, this.game.world.height);
  28. // Floor
  29. for(let i=0;i<this.game.world.width/100;i++){
  30. game.add.image(i*100, 501, 'floor');
  31. }
  32. // LABELS
  33. // Player name
  34. this.player_info = game.add.text(this.game.world.centerX - this.extraWidth/2, 40, lang.welcome + ", " + username + "!", { font: "20px Arial", fill: "#330000", align: "center" });
  35. this.player_info.anchor.setTo(0.5,0.5);
  36. // Title : Select a game
  37. const style = { font: "32px Arial", fill: "#00804d", align: "center" };
  38. this.title = game.add.text(this.game.world.centerX - this.extraWidth/2, 80, lang.menu_title, style);
  39. this.title.anchor.setTo(0.5,0.5);
  40. // Subtitle : Game mode
  41. const style_game = { font: "27px Arial", fill: "#003cb3", align: "center" };
  42. this.lbl_game = game.add.text(this.game.world.centerX - this.extraWidth/2, 110, "", style_game);
  43. this.lbl_game.anchor.setTo(0.5,0.5);
  44. // BUTTONS
  45. // Calls function that loads navigation icons
  46. iconSettings["func_addButtons"](false,true,
  47. false,false,false,
  48. true,true,
  49. false,false);
  50. // Game buttons
  51. let x = -350;
  52. let y = -70;
  53. let menuObjList = [];
  54. for(let i=0; i<loadAssets.levelSpriteList.length; i++){
  55. menuObjList[i] = game.add.sprite(defaultWidth/2 + x, this.game.world.centerY + y, 'game'+i);
  56. menuObjList[i].anchor.setTo(0.5, 0.5);
  57. menuObjList[i].inputEnabled = true;
  58. menuObjList[i].input.useHandCursor = true;
  59. menuObjList[i].events.onInputDown.add(this.func_loadGame,{levelType: loadAssets.levelTypeList[i], beep: beepSound, shape: loadAssets.levelShapeList[i], label : true, game: this.game, extraWidth: this.extraWidth});
  60. menuObjList[i].events.onInputOver.add(this.func_showTitle,{levelType: loadAssets.levelTypeList[i], beep: beepSound, shape : loadAssets.levelShapeList[i], label : true, menu: menuObjList[i], lbl_game: this.lbl_game});
  61. menuObjList[i].events.onInputOut.add(this.func_clearTitle, {menu: menuObjList[i], lbl_game: this.lbl_game});
  62. if((i+1)%2==1){
  63. y=90;
  64. }else{
  65. y=-70;
  66. x+=235;
  67. }
  68. }
  69. // TURNING MOUSE INPUT CAPTURE ON TO MANAGE PAGE SCROLL
  70. this.input.mouse.capture = true;
  71. },
  72. update: function(){
  73. if(this.input.activePointer.leftButton.isUp){
  74. this.inputUp();
  75. }
  76. if(this.input.activePointer.leftButton.isDown){
  77. this.inputDown();
  78. }
  79. if(this.isCameraMoving){
  80. this.camera.x += (this.inputStartPosition.x - this.input.activePointer.x)/50;
  81. this.title.x = (this.game.world.centerX - this.extraWidth/2) + this.camera.x;
  82. this.lbl_game.x = (this.game.world.centerX - this.extraWidth/2) + this.camera.x;
  83. this.player_info.x = (this.game.world.centerX - this.extraWidth/2) + this.camera.x;
  84. iconSettings["changeRightButtonX"]((defaultWidth) + this.camera.x);
  85. }
  86. },
  87. inputDown: function(){
  88. if(!this.isCameraMoving){
  89. this.inputStartPosition = new Phaser.Point(this.input.activePointer.x, this.input.activePointer.y);
  90. }
  91. this.isCameraMoving = true;
  92. },
  93. inputUp: function(){
  94. this.isCameraMoving = false;
  95. },
  96. //calls the selected game menu screen
  97. func_loadGame: function(){
  98. if(debugMode) console.log("antes: "+this.game.world.width);
  99. this.game.world.setBounds(0, 0, defaultWidth, this.game.world.height);
  100. if(debugMode) console.log("depois: "+this.game.world.width);
  101. if(audioStatus){
  102. this.beep.play();
  103. }
  104. levelShape = this.shape;
  105. levelLabel = this.label;
  106. if (this.levelType==1) levelType = "A";
  107. else if(this.levelType==2) levelType = "B";
  108. else if(this.levelType==3) levelType = "C";
  109. if(levelType=="C"){
  110. gameStateString = "game"+levelShape+"Two";
  111. if(debugMode) console.log(levelShape+" Two, "+levelType);
  112. }else{
  113. gameStateString = "game"+levelShape+"One";
  114. if(debugMode) console.log(levelShape+" One, "+levelType);
  115. }
  116. // Calls level difficulty screen
  117. game.state.start('difficulty');
  118. },
  119. func_showTitle: function(){
  120. let title = "";
  121. let type = "";
  122. if(this.levelType==1){
  123. type = "I";
  124. }
  125. if(this.levelType==2){
  126. type = "II";
  127. }
  128. if(this.levelType==3){
  129. type = "III";
  130. }
  131. if(this.shape=="Circle"){
  132. title += lang.circle_name;
  133. }else if(this.shape=="Square"){
  134. title += lang.square_name;
  135. }
  136. if(type!=""){
  137. //circ/quad I/II/III
  138. title += " " + type;
  139. }
  140. this.lbl_game.text = title;
  141. this.menu.scale.setTo(1.05);
  142. },
  143. func_clearTitle: function(){
  144. this.lbl_game.text = "";
  145. this.menu.scale.setTo(1);
  146. }
  147. };