Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.90 KB | None | 0 0
  1. package ph.sparcsy.summerydays.screen;
  2.  
  3. import com.badlogic.gdx.Gdx;
  4. import com.badlogic.gdx.graphics.Color;
  5. import com.badlogic.gdx.graphics.OrthographicCamera;
  6. import com.badlogic.gdx.graphics.Texture;
  7. import com.badlogic.gdx.math.Vector2;
  8. import com.badlogic.gdx.physics.box2d.World;
  9. import com.badlogic.gdx.scenes.scene2d.Actor;
  10. import com.badlogic.gdx.scenes.scene2d.Stage;
  11. import com.badlogic.gdx.scenes.scene2d.ui.Button;
  12. import com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup;
  13. import com.badlogic.gdx.scenes.scene2d.ui.Label;
  14. import com.badlogic.gdx.scenes.scene2d.ui.Skin;
  15. import com.badlogic.gdx.scenes.scene2d.ui.Table;
  16. import com.badlogic.gdx.utils.Align;
  17. import com.badlogic.gdx.utils.viewport.StretchViewport;
  18.  
  19. import box2dLight.PointLight;
  20. import box2dLight.RayHandler;
  21. import ph.sparcsy.summerydays.SummeryDays;
  22. import ph.sparcsy.summerydays.asset.Asset;
  23. import ph.sparcsy.summerydays.enitity.Parallax;
  24.  
  25. public class MenuScreen extends BaseScreen {
  26.  
  27. private Parallax forestParallax;
  28. private Parallax cloudParallax;
  29.  
  30. private float mover;
  31.  
  32. private Stage stage;
  33. private World world;
  34.  
  35. private RayHandler rayHandler;
  36. private PointLight pointLight;
  37.  
  38. private Skin skin;
  39.  
  40. MenuScreen(SummeryDays game) {
  41. super(game);
  42. }
  43.  
  44. @Override
  45. public void show() {
  46. mover = -1f;
  47.  
  48. skin = asset.get(Asset.Data.UISKIN);
  49. stage = new Stage(new StretchViewport(width, height, new OrthographicCamera(width, height)), batch);
  50.  
  51. buildWorld();
  52. buildParallax();
  53. buildMenuOption();
  54.  
  55. Gdx.input.setInputProcessor(stage);
  56. // Sound.play(asset, Asset.Sound.FANTASY_NIGHT, true);
  57. }
  58.  
  59. private void buildWorld() {
  60. world = new World(new Vector2(0, 0), true);
  61.  
  62. rayHandler = new RayHandler(world);
  63. rayHandler.setAmbientLight(Color.GOLDENROD);
  64. rayHandler.setAmbientLight(0.2f);
  65.  
  66. pointLight = new PointLight(rayHandler, 200);
  67. pointLight.setColor(Color.ORANGE);
  68. pointLight.setDistance(4);
  69. }
  70.  
  71. private Actor buildMenuButton() {
  72. float padY = height * 0.038f;
  73. float padX = width * 0.09f;
  74.  
  75. Button btnExit = new Button(skin, "exit-style");
  76. btnExit.pad(padY, padX, padY, padX);
  77.  
  78. Button btnPlay = new Button(skin, "play-style");
  79. btnPlay.pad(padY, padX, padY, padX);
  80.  
  81. Button btnLoad = new Button(skin, "load-style");
  82. btnLoad.pad(padY, padX, padY, padX);
  83.  
  84. Table menuOption = new Table();
  85. menuOption.add().padLeft(width * 0.3f).row();
  86. menuOption.add(btnPlay).padBottom(padY).left().row();
  87. menuOption.add(btnLoad).padBottom(padY).center().row();
  88. menuOption.add(btnExit).padBottom(padY).right().row();
  89.  
  90.  
  91. return menuOption;
  92. }
  93.  
  94. private Actor buildTitle() {
  95. Label.LabelStyle titleStyle = new Label.LabelStyle();
  96. titleStyle.font = asset.get(Asset.Font.MENU);
  97.  
  98. Label title = new Label("Summery" + '\n' + "Days", titleStyle);
  99. title.setAlignment(Align.center);
  100. title.debug();
  101.  
  102. Table table = new Table();
  103. table.add(title);
  104.  
  105. return table;
  106. }
  107.  
  108. private void buildParallax() {
  109. Texture bgForest = asset.get(Asset.Image.BG_FOREST);
  110. Texture bgCloud = asset.get(Asset.Image.BG_CLOUD);
  111.  
  112. forestParallax = new Parallax(bgForest)
  113. .setWidth(width / 3f)
  114. .setHeight(height / 3f)
  115. .repeat(3)
  116. .setSpeed(5);
  117.  
  118. cloudParallax = new Parallax(bgCloud)
  119. .setWidth(width)
  120. .setHeight(height)
  121. .repeat(1)
  122. .setSpeed(15);
  123. }
  124.  
  125. private void buildMenuOption() {
  126. HorizontalGroup menuGui = new HorizontalGroup();
  127. menuGui.addActor(buildMenuButton());
  128. menuGui.addActor(buildTitle());
  129. menuGui.setFillParent(true);
  130. menuGui.center();
  131.  
  132. stage.addActor(menuGui);
  133. }
  134.  
  135. @Override
  136. public void resize(int width, int height) {
  137. stage.getViewport().update(width, height, true);
  138. }
  139.  
  140. @Override
  141. public void update(float delta) {
  142. if (mover <= 1) {
  143. mover += delta * 0.09f;
  144. pointLight.setPosition(mover, 1.1f);
  145. }
  146.  
  147. cloudParallax.update(delta);
  148. forestParallax.update(delta);
  149.  
  150. stage.act(delta);
  151. world.step(1f / 60f, 6, 2);
  152. }
  153.  
  154. @Override
  155. public void render(float delta) {
  156. super.render(delta);
  157.  
  158. /* batch.begin();
  159. cloudParallax.draw(batch);
  160. forestParallax.draw(batch);
  161. batch.end();*/
  162.  
  163. stage.draw();
  164. /// rayHandler.updateAndRender();
  165. }
  166.  
  167. @Override
  168. public void dispose() {
  169. super.dispose();
  170. rayHandler.dispose();
  171. stage.dispose();
  172. world.dispose();
  173. }
  174.  
  175. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement