Functional menu
This commit is contained in:
parent
30962673d5
commit
bf0d5e041b
BIN
core/assets/menu_background.png
Normal file
BIN
core/assets/menu_background.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.5 KiB |
Binary file not shown.
Before Width: | Height: | Size: 9.9 KiB After Width: | Height: | Size: 1.7 KiB |
Binary file not shown.
@ -38,6 +38,7 @@ public class Assets {
|
||||
|
||||
public void loadAssets() {
|
||||
manager.load("level_background.png", Texture.class);
|
||||
manager.load("menu_background.png", Texture.class);
|
||||
manager.load("logo.png", Texture.class);
|
||||
|
||||
manager.load("sprites/level.png", Texture.class);
|
||||
@ -104,6 +105,10 @@ public class Assets {
|
||||
return manager.get("level_background.png", Texture.class);
|
||||
}
|
||||
|
||||
public Texture getMenuBackground() {
|
||||
return manager.get("menu_background.png", Texture.class);
|
||||
}
|
||||
|
||||
public Texture getLogo() {
|
||||
return manager.get("logo.png", Texture.class);
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||
import com.badlogic.gdx.utils.viewport.FitViewport;
|
||||
import com.badlogic.gdx.utils.viewport.Viewport;
|
||||
import com.me.pacman.state.MenuState;
|
||||
import com.me.pacman.state.PlayState;
|
||||
|
||||
public class PacDude extends Game {
|
||||
@ -39,7 +40,7 @@ public class PacDude extends Game {
|
||||
batch = new SpriteBatch();
|
||||
sr = new ShapeRenderer();
|
||||
|
||||
setScreen(new PlayState(this));
|
||||
setScreen(new MenuState(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,9 +1,12 @@
|
||||
package com.me.pacman.state;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input;
|
||||
import com.badlogic.gdx.InputAdapter;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.me.pacman.PacDude;
|
||||
import com.me.pacman.level.Level;
|
||||
|
||||
public class MenuState extends LevelState {
|
||||
|
||||
@ -11,30 +14,80 @@ public class MenuState extends LevelState {
|
||||
private Texture logo;
|
||||
private BitmapFont font;
|
||||
|
||||
|
||||
public static final int NEW_GAME = 0;
|
||||
public static final int HIGH_SCORES = 1;
|
||||
|
||||
private static final int MENU_PADDING = 24;
|
||||
private static final int MENU_X = 84;
|
||||
private static final int MENU_Y = 85;
|
||||
|
||||
private int selectedOption;
|
||||
private static final String[] options = {
|
||||
"New Game",
|
||||
"High Scores",
|
||||
};
|
||||
|
||||
|
||||
public MenuState(PacDude game) {
|
||||
super(game);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
levelBackground = game.assets.getLevelBackground();
|
||||
levelBackground = game.assets.getMenuBackground();
|
||||
logo = game.assets.getLogo();
|
||||
logo.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
|
||||
font = game.assets.getFont();
|
||||
|
||||
level = new Level(game,"level");
|
||||
Gdx.input.setInputProcessor(this.new Controller());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
game.batch.draw(levelBackground, 0, 16);
|
||||
level.render(0, 16);
|
||||
game.batch.draw(logo, 0, 124, 224, 120);
|
||||
game.batch.draw(logo, 0, 140, 224, 120);
|
||||
|
||||
for (int i = 0; i < options.length; i++) {
|
||||
font.setColor(i == selectedOption? Color.BLUE : Color.WHITE);
|
||||
|
||||
font.draw(game.batch, options[i], MENU_X, MENU_Y - (i * MENU_PADDING), 56, 1, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float dt) {
|
||||
public void update(float dt) {}
|
||||
|
||||
private final class Controller extends InputAdapter {
|
||||
|
||||
@Override
|
||||
public boolean keyDown(int keycode) {
|
||||
switch (keycode) {
|
||||
case Input.Keys.UP:
|
||||
selectedOption = selectedOption > 0 ? --selectedOption : options.length - 1;
|
||||
break;
|
||||
case Input.Keys.DOWN:
|
||||
selectedOption = selectedOption < options.length - 1 ? ++selectedOption : 0;
|
||||
break;
|
||||
case Input.Keys.ENTER:
|
||||
switch (selectedOption) {
|
||||
case NEW_GAME:
|
||||
game.setScreen(new PlayState(game));
|
||||
break;
|
||||
case HIGH_SCORES:
|
||||
// game.setScreen(new HighScores(game));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return super.keyDown(keycode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
Gdx.input.setInputProcessor(null);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user