diff --git a/core/assets/menu_background.png b/core/assets/menu_background.png new file mode 100644 index 0000000..51f8ca1 Binary files /dev/null and b/core/assets/menu_background.png differ diff --git a/core/assets/sprites/level.png b/core/assets/sprites/level.png index 292a03d..0373b5b 100644 Binary files a/core/assets/sprites/level.png and b/core/assets/sprites/level.png differ diff --git a/core/assets/sprites/level.xcf b/core/assets/sprites/level.xcf index 29de74a..d9869c9 100644 Binary files a/core/assets/sprites/level.xcf and b/core/assets/sprites/level.xcf differ diff --git a/core/src/com/me/pacman/Assets.java b/core/src/com/me/pacman/Assets.java index 1c21465..358a125 100644 --- a/core/src/com/me/pacman/Assets.java +++ b/core/src/com/me/pacman/Assets.java @@ -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); } diff --git a/core/src/com/me/pacman/PacDude.java b/core/src/com/me/pacman/PacDude.java index a3cac90..611e6e9 100644 --- a/core/src/com/me/pacman/PacDude.java +++ b/core/src/com/me/pacman/PacDude.java @@ -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 diff --git a/core/src/com/me/pacman/state/MenuState.java b/core/src/com/me/pacman/state/MenuState.java index 4888dd1..8a83450 100644 --- a/core/src/com/me/pacman/state/MenuState.java +++ b/core/src/com/me/pacman/state/MenuState.java @@ -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); + } + }