Level select menu
This commit is contained in:
parent
cfb59a3c4a
commit
4593a6c686
17 changed files with 346 additions and 24 deletions
|
@ -9,15 +9,6 @@ import com.badlogic.gdx.math.Vector3;
|
|||
*/
|
||||
public class CameraUtils {
|
||||
|
||||
public static void lockOnTarget(Camera cam, float tarX, float tarY)
|
||||
{
|
||||
Vector3 pos = cam.position;
|
||||
pos.x = tarX;
|
||||
pos.y = tarY;
|
||||
cam.position.set(pos);
|
||||
cam.update();
|
||||
}
|
||||
|
||||
public static void lerpToTarget(Camera cam, float tarX, float tarY)
|
||||
{
|
||||
Vector3 pos = cam.position;
|
||||
|
|
24
core/src/com/game/Misc/levelSelectClickListener.java
Normal file
24
core/src/com/game/Misc/levelSelectClickListener.java
Normal file
|
@ -0,0 +1,24 @@
|
|||
package com.game.misc;
|
||||
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
|
||||
import com.game.App;
|
||||
|
||||
/**
|
||||
* Created by Ash on 13/02/2016.
|
||||
*/
|
||||
public class levelSelectClickListener extends ClickListener {
|
||||
|
||||
private App app;
|
||||
private int levelNumber;
|
||||
|
||||
public levelSelectClickListener(App app, int levelNumber)
|
||||
{
|
||||
this.app = app;
|
||||
this.levelNumber = levelNumber;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clicked (com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) {
|
||||
app.sm.setPlayScreen(levelNumber);
|
||||
}
|
||||
}
|
|
@ -5,7 +5,9 @@ import com.badlogic.gdx.Input;
|
|||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
|
||||
import com.game.App;
|
||||
import com.game.managers.ScreenManager;
|
||||
|
||||
|
@ -14,22 +16,33 @@ import com.game.managers.ScreenManager;
|
|||
*/
|
||||
public class Leaderboard extends AbstractScreen {
|
||||
|
||||
private TextButton butBack;
|
||||
private Skin skin;
|
||||
|
||||
// Buttons
|
||||
private Vector2 buttonSize;
|
||||
private TextButton butBack;
|
||||
|
||||
|
||||
public Leaderboard(App app) {
|
||||
super(app);
|
||||
|
||||
skin = new Skin();
|
||||
buttonSize = new Vector2(50, 50);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
super.show();
|
||||
|
||||
skin.add("default-font", app.assets.get("badaboom45.ttf", BitmapFont.class));
|
||||
skin.load(Gdx.files.internal("spritesheets/uiskin.json"));
|
||||
|
||||
initButtons();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float dt) {
|
||||
|
||||
stage.act(dt);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -38,8 +51,9 @@ public class Leaderboard extends AbstractScreen {
|
|||
|
||||
app.sb.begin();
|
||||
app.sb.draw(app.assets.get("textures/leaderboardBackground.jpg", Texture.class), 0, 0);
|
||||
app.assets.get("badaboom25.ttf", BitmapFont.class).draw(app.sb,"Press M to go back to menu", 100, 100);
|
||||
app.sb.end();
|
||||
|
||||
stage.draw();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -51,4 +65,19 @@ public class Leaderboard extends AbstractScreen {
|
|||
public void dispose() {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
private void initButtons()
|
||||
{
|
||||
butBack = new TextButton("Back", skin, "default");
|
||||
butBack.setPosition(buttonSize.x, buttonSize.y / 2);
|
||||
butBack.setSize(buttonSize.x, buttonSize.y);
|
||||
butBack.addListener(new ClickListener() {
|
||||
@Override
|
||||
public void clicked (com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) {
|
||||
app.sm.setScreen(ScreenManager.Screen.MENU);
|
||||
}
|
||||
});
|
||||
|
||||
stage.addActor(butBack);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,105 @@
|
|||
package com.game.screens;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
|
||||
import com.game.App;
|
||||
import com.game.managers.ScreenManager;
|
||||
import com.game.misc.levelSelectClickListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by Ash on 11/02/2016.
|
||||
*/
|
||||
public class LevelSelect {
|
||||
public class LevelSelect extends AbstractScreen {
|
||||
|
||||
private Skin skin;
|
||||
|
||||
// Buttons
|
||||
private ArrayList<TextButton> butLevels = new ArrayList<TextButton>();
|
||||
private TextButton butEndless, butBack;
|
||||
private Vector2 buttonSize;
|
||||
|
||||
public LevelSelect(App app) {
|
||||
super(app);
|
||||
|
||||
skin = new Skin();
|
||||
buttonSize = new Vector2(50, 50);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show()
|
||||
{
|
||||
super.show();
|
||||
|
||||
skin.add("default-font", app.assets.get("badaboom60.ttf", BitmapFont.class));
|
||||
skin.load(Gdx.files.internal("spritesheets/uiskin.json"));
|
||||
|
||||
initButtons();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float dt) {
|
||||
stage.act(dt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(float dt) {
|
||||
super.render(dt);
|
||||
|
||||
app.sb.begin();
|
||||
app.sb.draw(app.assets.get("textures/levelSelectBackground.jpg", Texture.class), 0, 0);
|
||||
app.sb.end();
|
||||
|
||||
stage.draw();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleInput() {
|
||||
if(Gdx.input.isKeyJustPressed(Input.Keys.ESCAPE)) { app.sm.setScreen(ScreenManager.Screen.MENU); }
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose()
|
||||
{
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
private void initButtons()
|
||||
{
|
||||
butBack = new TextButton("Back", skin, "default");
|
||||
butBack.setPosition(buttonSize.x, buttonSize.y / 2);
|
||||
butBack.setSize(buttonSize.x, buttonSize.y);
|
||||
butBack.addListener(new ClickListener() {
|
||||
@Override
|
||||
public void clicked (com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) {
|
||||
app.sm.setScreen(ScreenManager.Screen.MENU);
|
||||
}
|
||||
});
|
||||
|
||||
int tempCounter = 1;
|
||||
for(int row = 0; row < 2; row++)
|
||||
{
|
||||
for(int col = 0; col < 5; col++)
|
||||
{
|
||||
TextButton butTemp = new TextButton(String.valueOf(tempCounter), skin, "default");
|
||||
butTemp.setPosition(500 + col * 60, 400 - row * 60);
|
||||
butTemp.setSize(buttonSize.x, buttonSize.y);
|
||||
butTemp.addListener(new levelSelectClickListener(app, tempCounter));
|
||||
|
||||
tempCounter++;
|
||||
|
||||
stage.addActor(butTemp);
|
||||
butLevels.add(butTemp);
|
||||
}
|
||||
}
|
||||
|
||||
stage.addActor(butBack);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,6 +99,7 @@ public class Loading extends AbstractScreen {
|
|||
app.assets.load("textures/badlogic.jpg", Texture.class);
|
||||
app.assets.load("textures/menuBackground.jpg", Texture.class);
|
||||
app.assets.load("textures/leaderboardBackground.jpg", Texture.class);
|
||||
app.assets.load("textures/levelSelectBackground.jpg", Texture.class);
|
||||
app.assets.load("textures/position0.png", Texture.class);
|
||||
app.assets.load("textures/position1.png", Texture.class);
|
||||
app.assets.load("textures/position2.png", Texture.class);
|
||||
|
|
|
@ -33,7 +33,7 @@ public class Menu extends AbstractScreen {
|
|||
super(app);
|
||||
skin = new Skin();
|
||||
|
||||
buttonSize = new Vector2(128, 40);
|
||||
buttonSize = new Vector2(50, 50);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -81,18 +81,17 @@ public class Menu extends AbstractScreen {
|
|||
private void initButtons()
|
||||
{
|
||||
butPlay = new TextButton("Play", skin, "default");
|
||||
butPlay.setPosition((stage.getWidth() / 2) - buttonSize.x / 2, buttonSize.y + 180);
|
||||
butPlay.setPosition((stage.getWidth() / 2) - buttonSize.x / 2, buttonSize.y + 160);
|
||||
butPlay.setSize(buttonSize.x, buttonSize.y);
|
||||
butPlay.addListener(new ClickListener() {
|
||||
@Override
|
||||
public void clicked (com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) {
|
||||
music.stop();
|
||||
app.sm.setPlayScreen(1);
|
||||
app.sm.setScreen(ScreenManager.Screen.LEVELSELECT);
|
||||
}
|
||||
});
|
||||
|
||||
butLeaderboard = new TextButton("Leaderboard", skin, "default");
|
||||
butLeaderboard.setPosition((stage.getWidth() / 2) - buttonSize.x / 2, buttonSize.y + 100);
|
||||
butLeaderboard.setPosition((stage.getWidth() / 2) - buttonSize.x / 2, buttonSize.y + 80);
|
||||
butLeaderboard.setSize(buttonSize.x, buttonSize.y);
|
||||
butLeaderboard.addListener(new ClickListener() {
|
||||
@Override
|
||||
|
@ -102,7 +101,7 @@ public class Menu extends AbstractScreen {
|
|||
});
|
||||
|
||||
butExit = new TextButton("Exit", skin, "default");
|
||||
butExit.setPosition((stage.getWidth() / 2) - buttonSize.x / 2, buttonSize.y + 20);
|
||||
butExit.setPosition((stage.getWidth() / 2) - buttonSize.x / 2, buttonSize.y);
|
||||
butExit.setSize(buttonSize.x, buttonSize.y);
|
||||
butExit.addListener(new ClickListener() {
|
||||
@Override
|
||||
|
@ -111,9 +110,9 @@ public class Menu extends AbstractScreen {
|
|||
}
|
||||
});
|
||||
|
||||
butPlay.addAction(sequence(alpha(0f), fadeIn(1f, Interpolation.pow2)));
|
||||
butLeaderboard.addAction(sequence(alpha(0f), fadeIn(1.5f, Interpolation.pow2)));
|
||||
butExit.addAction(sequence(alpha(0f), fadeIn(2f, Interpolation.pow2)));
|
||||
//butPlay.addAction(sequence(alpha(0f), fadeIn(1f, Interpolation.pow2)));
|
||||
//butLeaderboard.addAction(sequence(alpha(0f), fadeIn(1.5f, Interpolation.pow2)));
|
||||
//butExit.addAction(sequence(alpha(0f), fadeIn(2f, Interpolation.pow2)));
|
||||
|
||||
stage.addActor(butPlay);
|
||||
stage.addActor(butLeaderboard);
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.badlogic.gdx.Input;
|
|||
import com.badlogic.gdx.audio.Sound;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.maps.MapLayer;
|
||||
import com.badlogic.gdx.maps.MapProperties;
|
||||
|
@ -84,7 +85,7 @@ public class Play extends AbstractScreen {
|
|||
world.step(dt, 6, 2);
|
||||
|
||||
CameraUtils.lerpToTarget(cam, player.getPos().scl(PPM).x, 0);
|
||||
CameraUtils.lockOnTarget(b2dCam, player.getPos().x, player.getPos().y);
|
||||
CameraUtils.lerpToTarget(b2dCam, player.getPos().x, player.getPos().y);
|
||||
|
||||
Vector2 start = new Vector2(cam.viewportWidth / 2, cam.viewportHeight / 2);
|
||||
CameraUtils.setBoundary(cam, start, new Vector2(mapWidth * tileSize.x - start.x * 2, mapHeight * tileSize.y - start.y * 2));
|
||||
|
@ -101,7 +102,9 @@ public class Play extends AbstractScreen {
|
|||
if(!isDebug)
|
||||
{
|
||||
app.sb.begin();
|
||||
app.assets.get("badaboom25.ttf", BitmapFont.class).draw(app.sb,"Press M to go back to menu", 0, 0);
|
||||
app.sb.draw(app.assets.get("textures/position0.png", Texture.class), cam.position.x - cam.viewportWidth / 2, cam.position.y - cam.viewportHeight / 2);
|
||||
app.sb.draw(app.assets.get("textures/position1.png", Texture.class), cam.position.x - cam.viewportWidth / 2, cam.position.y - (cam.viewportHeight / 2) + 75);
|
||||
app.sb.draw(app.assets.get("textures/position2.png", Texture.class), cam.position.x - cam.viewportWidth / 2, cam.position.y - (cam.viewportHeight / 2) - 150);
|
||||
player.render(app.sb);
|
||||
app.sb.end();
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ public class ScreenManager {
|
|||
screens.put(Screen.LOADING, new Loading(app));
|
||||
screens.put(Screen.MENU, new Menu(app));
|
||||
screens.put(Screen.LEADERBOARD, new Leaderboard(app));
|
||||
screens.put(Screen.LEVELSELECT, new LevelSelect(app));
|
||||
}
|
||||
|
||||
public void setPlayScreen(int levelNumber)
|
||||
|
|
Reference in a new issue