From e27cfc71b6c0510870985536b0a7713578b7f8c5 Mon Sep 17 00:00:00 2001 From: Jeasonfire Date: Mon, 18 May 2015 05:12:33 +0300 Subject: [PATCH] Added next-level button for emergency situations. --- .../gladiator/input/IRNextLevel.java | 38 +++++++++++++++++++ .../gladiator/input/InputHandler.java | 1 + .../gladiator/input/InputReceivers.java | 1 + .../gladiator/state/InGameState.java | 18 ++++++--- .../com/saltosion/gladiator/util/Name.java | 1 + 5 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 core/src/com/saltosion/gladiator/input/IRNextLevel.java diff --git a/core/src/com/saltosion/gladiator/input/IRNextLevel.java b/core/src/com/saltosion/gladiator/input/IRNextLevel.java new file mode 100644 index 0000000..a4f9091 --- /dev/null +++ b/core/src/com/saltosion/gladiator/input/IRNextLevel.java @@ -0,0 +1,38 @@ +/** + * GladiatorBrawler is a 2D swordfighting game. + * Copyright (C) 2015 Jeasonfire/Allexit + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.saltosion.gladiator.input; + +import com.saltosion.gladiator.GladiatorBrawler; +import com.saltosion.gladiator.state.InGameState; + +public class IRNextLevel implements InputReceiver { + + @Override + public boolean pressed() { + if (GladiatorBrawler.currentState instanceof InGameState) { + ((InGameState) GladiatorBrawler.currentState).nextLevel(); + } + return true; + } + + @Override + public boolean released() { + return false; + } + +} diff --git a/core/src/com/saltosion/gladiator/input/InputHandler.java b/core/src/com/saltosion/gladiator/input/InputHandler.java index 5c547da..007f3d3 100644 --- a/core/src/com/saltosion/gladiator/input/InputHandler.java +++ b/core/src/com/saltosion/gladiator/input/InputHandler.java @@ -49,6 +49,7 @@ public class InputHandler implements InputProcessor { addInput(Keys.DOWN, Name.SWING_DOWN, false); addInput(Keys.F2, Name.DEBUG, true); addInput(Keys.ESCAPE, Name.SKIP_INTRO, false); + addInput(Keys.F3, Name.NEXT_LEVEL, false); } private void addInput(int key, String action, boolean activated) { diff --git a/core/src/com/saltosion/gladiator/input/InputReceivers.java b/core/src/com/saltosion/gladiator/input/InputReceivers.java index bfa43cf..654721a 100644 --- a/core/src/com/saltosion/gladiator/input/InputReceivers.java +++ b/core/src/com/saltosion/gladiator/input/InputReceivers.java @@ -36,6 +36,7 @@ public class InputReceivers { inputreceivers.put(Name.SWING_DOWN, new IRSwing(Direction.DOWN)); inputreceivers.put(Name.DEBUG, new IRDebugToggle()); inputreceivers.put(Name.SKIP_INTRO, new IRSkipIntros()); + inputreceivers.put(Name.NEXT_LEVEL, new IRNextLevel()); } public static InputReceiver getReceiver(String key) { diff --git a/core/src/com/saltosion/gladiator/state/InGameState.java b/core/src/com/saltosion/gladiator/state/InGameState.java index 2dc4b7c..2af1357 100644 --- a/core/src/com/saltosion/gladiator/state/InGameState.java +++ b/core/src/com/saltosion/gladiator/state/InGameState.java @@ -81,6 +81,7 @@ public class InGameState extends BaseState { AppUtil.inputHandler.setInputEnabled(Name.SWING_LEFT, true); AppUtil.inputHandler.setInputEnabled(Name.SWING_RIGHT, true); AppUtil.inputHandler.setInputEnabled(Name.SWING_UP, true); + AppUtil.inputHandler.setInputEnabled(Name.NEXT_LEVEL, true); } @Override @@ -100,13 +101,8 @@ public class InGameState extends BaseState { if (level.levelCleared()) { timeSinceLevelWon += deltaTime; if (timeSinceLevelWon > levelWonDelay) { - currentLevel++; timeSinceLevelWon = 0; - if (currentLevel >= levels.length) { - setState(new WinState()); - } else { - changeLevel(levels[currentLevel]); - } + nextLevel(); } } @@ -118,6 +114,15 @@ public class InGameState extends BaseState { } } + public void nextLevel() { + currentLevel++; + if (currentLevel >= levels.length) { + setState(new WinState()); + } else { + changeLevel(levels[currentLevel]); + } + } + public void changeLevel(Level level) { AppUtil.engine.removeAllEntities(); this.level = level; @@ -136,6 +141,7 @@ public class InGameState extends BaseState { AppUtil.inputHandler.setInputEnabled(Name.SWING_LEFT, false); AppUtil.inputHandler.setInputEnabled(Name.SWING_RIGHT, false); AppUtil.inputHandler.setInputEnabled(Name.SWING_UP, false); + AppUtil.inputHandler.setInputEnabled(Name.NEXT_LEVEL, false); // Clear all entities that are left as they are no longer needed AppUtil.engine.removeAllEntities(); diff --git a/core/src/com/saltosion/gladiator/util/Name.java b/core/src/com/saltosion/gladiator/util/Name.java index f1fe422..4f21d8a 100644 --- a/core/src/com/saltosion/gladiator/util/Name.java +++ b/core/src/com/saltosion/gladiator/util/Name.java @@ -51,6 +51,7 @@ public class Name { public static final String SWING_UP = "SWING_UP"; public static final String SWING_DOWN = "SWING_DOWN"; public static final String SKIP_INTRO = "SKIP_INTRO"; + public static final String NEXT_LEVEL = "NEXT_LEVEL"; public static final String DEBUG = "DEBUG"; public static final String MUSIC_THEME = "MUSIC_THEME";