Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ph.sparcsy.summerydays.screen;
- import com.badlogic.gdx.Gdx;
- import com.badlogic.gdx.graphics.Color;
- import com.badlogic.gdx.graphics.OrthographicCamera;
- import com.badlogic.gdx.graphics.Texture;
- import com.badlogic.gdx.math.Vector2;
- import com.badlogic.gdx.physics.box2d.World;
- import com.badlogic.gdx.scenes.scene2d.Actor;
- import com.badlogic.gdx.scenes.scene2d.Stage;
- import com.badlogic.gdx.scenes.scene2d.ui.Button;
- import com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup;
- import com.badlogic.gdx.scenes.scene2d.ui.Label;
- import com.badlogic.gdx.scenes.scene2d.ui.Skin;
- import com.badlogic.gdx.scenes.scene2d.ui.Table;
- import com.badlogic.gdx.utils.Align;
- import com.badlogic.gdx.utils.viewport.StretchViewport;
- import box2dLight.PointLight;
- import box2dLight.RayHandler;
- import ph.sparcsy.summerydays.SummeryDays;
- import ph.sparcsy.summerydays.asset.Asset;
- import ph.sparcsy.summerydays.enitity.Parallax;
- public class MenuScreen extends BaseScreen {
- private Parallax forestParallax;
- private Parallax cloudParallax;
- private float mover;
- private Stage stage;
- private World world;
- private RayHandler rayHandler;
- private PointLight pointLight;
- private Skin skin;
- MenuScreen(SummeryDays game) {
- super(game);
- }
- @Override
- public void show() {
- mover = -1f;
- skin = asset.get(Asset.Data.UISKIN);
- stage = new Stage(new StretchViewport(width, height, new OrthographicCamera(width, height)), batch);
- buildWorld();
- buildParallax();
- buildMenuOption();
- Gdx.input.setInputProcessor(stage);
- // Sound.play(asset, Asset.Sound.FANTASY_NIGHT, true);
- }
- private void buildWorld() {
- world = new World(new Vector2(0, 0), true);
- rayHandler = new RayHandler(world);
- rayHandler.setAmbientLight(Color.GOLDENROD);
- rayHandler.setAmbientLight(0.2f);
- pointLight = new PointLight(rayHandler, 200);
- pointLight.setColor(Color.ORANGE);
- pointLight.setDistance(4);
- }
- private Actor buildMenuButton() {
- float padY = height * 0.038f;
- float padX = width * 0.09f;
- Button btnExit = new Button(skin, "exit-style");
- btnExit.pad(padY, padX, padY, padX);
- Button btnPlay = new Button(skin, "play-style");
- btnPlay.pad(padY, padX, padY, padX);
- Button btnLoad = new Button(skin, "load-style");
- btnLoad.pad(padY, padX, padY, padX);
- Table menuOption = new Table();
- menuOption.add().padLeft(width * 0.3f).row();
- menuOption.add(btnPlay).padBottom(padY).left().row();
- menuOption.add(btnLoad).padBottom(padY).center().row();
- menuOption.add(btnExit).padBottom(padY).right().row();
- return menuOption;
- }
- private Actor buildTitle() {
- Label.LabelStyle titleStyle = new Label.LabelStyle();
- titleStyle.font = asset.get(Asset.Font.MENU);
- Label title = new Label("Summery" + '\n' + "Days", titleStyle);
- title.setAlignment(Align.center);
- title.debug();
- Table table = new Table();
- table.add(title);
- return table;
- }
- private void buildParallax() {
- Texture bgForest = asset.get(Asset.Image.BG_FOREST);
- Texture bgCloud = asset.get(Asset.Image.BG_CLOUD);
- forestParallax = new Parallax(bgForest)
- .setWidth(width / 3f)
- .setHeight(height / 3f)
- .repeat(3)
- .setSpeed(5);
- cloudParallax = new Parallax(bgCloud)
- .setWidth(width)
- .setHeight(height)
- .repeat(1)
- .setSpeed(15);
- }
- private void buildMenuOption() {
- HorizontalGroup menuGui = new HorizontalGroup();
- menuGui.addActor(buildMenuButton());
- menuGui.addActor(buildTitle());
- menuGui.setFillParent(true);
- menuGui.center();
- stage.addActor(menuGui);
- }
- @Override
- public void resize(int width, int height) {
- stage.getViewport().update(width, height, true);
- }
- @Override
- public void update(float delta) {
- if (mover <= 1) {
- mover += delta * 0.09f;
- pointLight.setPosition(mover, 1.1f);
- }
- cloudParallax.update(delta);
- forestParallax.update(delta);
- stage.act(delta);
- world.step(1f / 60f, 6, 2);
- }
- @Override
- public void render(float delta) {
- super.render(delta);
- /* batch.begin();
- cloudParallax.draw(batch);
- forestParallax.draw(batch);
- batch.end();*/
- stage.draw();
- /// rayHandler.updateAndRender();
- }
- @Override
- public void dispose() {
- super.dispose();
- rayHandler.dispose();
- stage.dispose();
- world.dispose();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement