I am running into an issue with keyboard inputs.
Example; In the SelectPlayer state it does not give you the option to press enter. If enter is not pressed then the game proceeds as intended to the IntroMissionBriefing state and load firstScene, but if enter is pressed during the SelectPlayer state then it will proceed to IntroMissionBriefing and load secondScene completely skipping firstScene altogether.
I have also ran into this issue with a state further in the game but it is around 1000 lines of code and didn’t want this post to be too big (this issue is localized within a single state so I am unsure if the issue is identical or not, let me know if you want me to post the code for this issue as well).
I have posted all the code I thought would be relevant to finding the cause. The way I have the game coded right now is the only way I knew how to get this to work, but obviously it doesn’t. Please critique my code, only way I can learn
P.S. if you guys/gals would like me to post a video of what is happening to actually get a visual please let me know.
Main Game Class
package game;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;
public class Game extends StateBasedGame{
public static final String gameName = "SSC Fizzle";
public static final int menu = 0;
public static final int selectPlayer = 1;
public static final int missionBriefing = 2;
public static final int selectCrew = 3;
public static final int launchSite = 4;
public Game(String gameName){
super(gameName);
this.addState(new Menu(menu));
this.addState(new IntroLaunchSite(launchSite));
this.addState(new SelectPlayer(selectPlayer));
this.addState(new IntroMissionBriefing(missionBriefing));
this.addState(new SelectCrew(selectCrew));
}
public void initStatesList(GameContainer gc) throws SlickException{
this.getState(menu).init(gc, this);
this.getState(launchSite).init(gc, this);
this.getState(selectPlayer).init(gc, this);
this.getState(missionBriefing).init(gc, this);
this.getState(selectCrew).init(gc, this);
this.enterState(menu);
}
public static void main(String[] args) {
AppGameContainer appgc;
try{
appgc = new AppGameContainer(new Game(gameName));
appgc.setDisplayMode(1280, 720, false);
appgc.start();
}catch(SlickException e){
e.printStackTrace();
}
}
}
SelectPlayer
package game;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;
public class SelectPlayer extends BasicGameState{
private boolean firstScene = true;
private boolean quit = false;
private boolean oneDescription = false;
private boolean twoDescription = false;
private boolean threeDescription = false;
Image backdropOne;
Image backdropTwo;
Image blurBackground;
Image escBackdrop;
public SelectPlayer(int state){
}
public void init(GameContainer gc, StateBasedGame sbg) throws SlickException{
backdropOne = new Image("res/BackdropOne.png");
backdropTwo = new Image("res/BackdropTwo.png");
blurBackground = new Image("res/IntroBlurOne.png");
escBackdrop = new Image("res/EscMenu.png");
}
public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException{
g.drawImage(blurBackground, 0, 0);
if(firstScene == true){
//Player One - Military Commander
g.drawImage(backdropOne, 210, 110);
g.drawImage(Player.playerOne().picture, 223, 120);
g.drawString(Player.playerOne().name, 390, 125);
g.drawString(Player.playerOne().position, 390, 150);
g.drawString(Player.playerOne().traitOne, 390, 175);
g.drawString(Player.playerOne().traitTwo, 390, 200);
g.drawString(Player.playerOne().traitThree, 390, 225);
g.drawString("Background (Q)", 390, 250);
//Player Two - Scientist
g.drawImage(backdropOne, 210, 300);
g.drawImage(Player.playerTwo().picture, 223, 310);
g.drawString(Player.playerTwo().name, 390, 315);
g.drawString(Player.playerTwo().position, 390, 340);
g.drawString(Player.playerTwo().traitOne, 390, 365);
g.drawString(Player.playerTwo().traitTwo, 390, 390);
g.drawString(Player.playerTwo().traitThree, 390, 415);
g.drawString("Background (W)", 390, 440);
//Player Three - Pilot
g.drawImage(backdropOne, 210, 490);
g.drawImage(Player.playerThree().picture, 223, 500);
g.drawString(Player.playerThree().name, 390, 505);
g.drawString(Player.playerThree().position, 390, 530);
g.drawString(Player.playerThree().traitOne, 390, 555);
g.drawString(Player.playerThree().traitTwo, 390, 580);
g.drawString(Player.playerThree().traitThree, 390, 605);
g.drawString("Background (E)", 390, 630);
if(firstScene == false){
g.clear();
}
}
//Description One render
if(oneDescription == true){
g.drawImage(backdropTwo, 670, 160);
g.drawString(Player.playerOne().history, 680, 180);
g.drawString("Backspace to Return", 780, 520);
if(oneDescription == false){
g.clear();
}
}
//Description Two render
if(twoDescription == true){
g.drawImage(backdropTwo, 670, 160);
g.drawString(Player.playerTwo().history, 680, 180);
g.drawString("Backspace to Return", 780, 520);
if(twoDescription == false){
g.clear();
}
}
//Description Three render
if(threeDescription == true){
g.drawImage(backdropTwo, 670, 160);
g.drawString(Player.playerThree().history, 680, 180);
g.drawString("Backspace to Return", 780, 540);
if(threeDescription == false){
g.clear();
}
}
//Quit Menu render
if(quit == true){
g.drawImage(escBackdrop, 0, 0);
if(quit == false){
g.clear();
}
}
}
public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException{
Input userInput = gc.getInput();
//Choose Player One
if(userInput.isKeyPressed(Input.KEY_1)){
Player.player = Player.playerOne();
sbg.enterState(2);
}
//Choose Player Two
if(userInput.isKeyPressed(Input.KEY_2)){
Player.player = Player.playerTwo();
sbg.enterState(2);
}
//Choose Player Three
if(userInput.isKeyPressed(Input.KEY_3)){
Player.player = Player.playerThree();
sbg.enterState(2);
}
//Quit Menu
if(userInput.isKeyPressed(Input.KEY_ESCAPE)){
quit = true;
}
if(quit == true){
if(userInput.isKeyPressed(Input.KEY_R)){
quit = false;
}
if(userInput.isKeyPressed(Input.KEY_Q)){
System.exit(0);
}
}
//Description One update
if(userInput.isKeyPressed(Input.KEY_Q)){
twoDescription = false;
threeDescription = false;
oneDescription = true;
}
if(oneDescription == true){
if(userInput.isKeyPressed(Input.KEY_BACK)){
oneDescription = false;
}
}
//Description Two update
if(userInput.isKeyPressed(Input.KEY_W)){
oneDescription = false;
threeDescription = false;
twoDescription = true;
}
if(twoDescription == true){
if(userInput.isKeyPressed(Input.KEY_BACK)){
twoDescription = false;
}
}
//Description Three update
if(userInput.isKeyPressed(Input.KEY_E)){
oneDescription = false;
twoDescription = false;
threeDescription = true;
}
if(threeDescription == true){
if(userInput.isKeyPressed(Input.KEY_BACK)){
threeDescription = false;
}
}
}
public int getID(){
return 1;
}
}
IntroMissionBriefing
package game;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;
public class IntroMissionBriefing extends BasicGameState{
private boolean firstScene = true;
private boolean secondScene = false;
private boolean thirdScene = false;
private boolean quit = false;
Image blurBackground;
Image escBackdrop;
public IntroMissionBriefing(int state){
}
public void init(GameContainer gc, StateBasedGame sbg) throws SlickException{
blurBackground = new Image("res/IntroBlurOne.png");
escBackdrop = new Image("res/EscMenu.png");
}
public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException{
g.drawImage(blurBackground, 0, 0);
//First Scene of the Mission Briefing render
if(firstScene == true){
g.drawString("Explain the mission, going to space to spy on\n"
+ "the **** party. The year is 1933, Sectrete Space Command\n"
+ "Send the SSC Fizzel into space to spy on the Germans\n"
+ "be very detailed to setup the game", 500, 200);
g.drawString("press enter", 500, 300);
if(firstScene == false){
g.clear();
}
}
//Second Scene of the Mission Briefing render
if(secondScene == true){
g.drawString("More detail for mission briefing if needed", 500, 200);
g.drawString("press enter", 500, 300);
if(secondScene == false){
g.clear();
}
}
//Third Scene of the Mission Briefing render
if(thirdScene == true){
g.drawString("additional space if needed for Mission Briefing", 500, 200);
g.drawString("press enter", 500, 300);
if(thirdScene == false){
g.clear();
}
}
//Quit Menu render
if(quit == true){
g.drawImage(escBackdrop, 0, 0);
if(quit == false){
g.clear();
}
}
}
public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException{
Input userInput = gc.getInput();
//Quit Menu update
if(userInput.isKeyPressed(Input.KEY_ESCAPE)){
quit = true;
}
if(quit == true){
if(userInput.isKeyPressed(Input.KEY_R)){
quit = false;
}
if(userInput.isKeyPressed(Input.KEY_M)){
sbg.enterState(0);
}
if(userInput.isKeyPressed(Input.KEY_Q)){
System.exit(0);
}
}
//First Scene update
if(firstScene == true && userInput.isKeyPressed(Input.KEY_ENTER)){
firstScene = false;
secondScene = true;
thirdScene = false;
}
//Second Scene update
if(secondScene == true && userInput.isKeyPressed(Input.KEY_ENTER)){
firstScene = false;
secondScene = false;
thirdScene = true;
}
//Third Scene update
if(userInput.isKeyPressed(Input.KEY_ENTER)){
sbg.enterState(3);
}
}
public int getID(){
return 2;
}
}