/** * @see org.newdawn.slick.state.BasicGameState#keyReleased(int, char) */ public void keyReleased(int key, char c) { if (key == Input.KEY_2) { GameState target = game.getState(TestState2.ID); final long start = System.currentTimeMillis(); CrossStateTransition t = new CrossStateTransition(target) { public boolean isComplete() { return (System.currentTimeMillis() - start) > 2000; } public void init(GameState firstState, GameState secondState) { } }; game.enterState(TestState2.ID, t, new EmptyTransition()); } if (key == Input.KEY_3) { game.enterState(TestState3.ID, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); } }
/** * @see org.newdawn.slick.state.BasicGameState#keyReleased(int, char) */ public void keyReleased(int key, char c) { if (key == Input.KEY_DOWN) { selected++; if (selected >= options.length) { selected = 0; } } if (key == Input.KEY_UP) { selected--; if (selected < 0) { selected = options.length - 1; } } if (key == Input.KEY_1) { game.enterState(TestState1.ID, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); } if (key == Input.KEY_2) { game.enterState(TestState2.ID, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); } }
@Override public void update(GameContainer gc, StateBasedGame sbg, int i) throws SlickException { if (shouldToggleFullscreen) { shouldToggleFullscreen = false; boolean fs = !gc.isFullscreen(); AppGameContainer agc = (AppGameContainer)gc; agc.setDisplayMode(fs ? agc.getScreenWidth() : Application.DISPLAY_WIDTH, fs ? agc.getScreenHeight() : Application.DISPLAY_HEIGHT, fs); } if (gc.getInput().isKeyPressed(Input.KEY_ENTER)) { click.play(1.0f, CLICK_VOLUME); mainMenu.fade(1000, 0.0f, true); sbg.enterState(Application.GAME, new FadeOutTransition(Color.black, 1000), new EmptyTransition()); } if (gc.getInput().isKeyPressed(Input.KEY_C)) { sbg.enterState(Application.CREDITS); } }
@Override public void update(GameContainer gc, StateBasedGame game, int delta) throws SlickException { if(gameStart.inBounds(Globals.mouse.getPosition().x, Globals.mouse.getPosition().y)) { gameStart.mouseEnter(); if(Globals.mouse.isMouseDown()) { Globals.resetEntityNum(); Globals.resetInputs(); game.enterState(GameState.ID, new FadeOutTransition(), new FadeInTransition()); } } else gameStart.mouseExit(); if(credits.inBounds(Globals.mouse.getPosition().x, Globals.mouse.getPosition().y)) credits.mouseEnter(); else credits.mouseExit(); if(exit.inBounds(Globals.mouse.getPosition().x, Globals.mouse.getPosition().y)) { exit.mouseEnter(); if(Globals.mouse.isMouseDown()) gc.exit(); } else exit.mouseExit(); MusicPlayer.getInstance().update(); }
private void backToMainMenu(StateBasedGame sbg) { pressedEscape = false; caseMonsterAnimation = 2; pressedEnter = false; monsterPicking = true; songPicking = false; p1Picking = true; p2Picking = false; for (Music music : musicSongChoices) { if (music.playing()) { music.stop(); } } MainMenuState.resumeMusic(); sbg.enterState(BeatBitBeatMain.getMainMenu(), new FadeOutTransition(), new FadeInTransition()); }
@Override public void update(GameContainer gc, StateBasedGame sbg, int i) throws SlickException { Input input = gc.getInput(); xMouse = input.getMouseX(); yMouse = input.getMouseY(); if (coordHumanP1.getX() != 100){ coordHumanP1.setX(coordHumanP1.getX() - 15); coordHumanP2.setX(coordHumanP2.getX() + 15); } if (pressable){ if (enterPressed){ pressable = false; enterPressed = false; sbg.enterState(BeatBitBeatMain.getGameProper(), new FadeOutTransition(), new FadeInTransition()); } } // }
@Override public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException { String ip = "127.0.0.1"; boolean inp = false; Input input = container.getInput(); if(input.isKeyDown(Input.KEY_1)){ (new Server()).start(); inp = true; } else if(input.isKeyDown(Input.KEY_2)){ ip = JOptionPane.showInputDialog("Connect to server using ip."); inp = true; } if(inp){ this.game.enterState(Game.ID, new FadeOutTransition(org.newdawn.slick.Color.black), new FadeInTransition(org.newdawn.slick.Color.black)); new InitThread(ip, (Game) game.getState(Game.ID)).start(); } }
public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException { super.update(container, game, delta); if (mResource != null) { try { mResource.load(); } catch (IOException e) { throw new SlickException("Failed to load: " + mResource.getDescription(), e); } mResource = null; } mRemaining = LoadingList.get().getRemainingResources(); mTotal = LoadingList.get().getTotalResources(); if (LoadingList.get().getRemainingResources() > 0) { mResource = LoadingList.get().getNext(); } else { ((Music)DatasManager.getInstance().getFile("Music.menu")).loop(); game.enterState(1, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); } }
private void gameoverInput(GameContainer gc, StateBasedGame sbg, Input input) throws SlickException { if(input.isKeyPressed(Input.KEY_RIGHT)){ if(!selection){ selection = true; } }else if(input.isKeyPressed(Input.KEY_LEFT)){ if(selection){ selection = false; } }else if(input.isKeyPressed(Input.KEY_ENTER)){ if(selection){ status.get(0).setData(false); sbg.getState(Spacerun.MAINMENUSTATE).init(gc, sbg); sbg.enterState(Spacerun.MAINMENUSTATE, new FadeOutTransition(), new FadeInTransition()); }else{ sbg.getState(Spacerun.GAMESTATE).init(gc, sbg); sbg.enterState(Spacerun.GAMESTATE, new FadeOutTransition(), new FadeInTransition()); } } }
@Override public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException { Input input = gc.getInput(); if(input.isKeyPressed(Input.KEY_ESCAPE)){ sbg.getState(Spacerun.MAINMENUSTATE).init(gc, sbg); sbg.enterState(Spacerun.MAINMENUSTATE, new FadeOutTransition(), new FadeInTransition()); } if(input.isKeyPressed(Input.KEY_UP)){ menuSelection = true; }else if(input.isKeyPressed(Input.KEY_DOWN)){ menuSelection = false; }else if(input.isKeyPressed(Input.KEY_ENTER)){ if(menuSelection){ if((boolean)status.get(1).getData()){ status.get(1).setData(false); }else{ status.get(1).setData(true); } }else{ sbg.getState(Spacerun.MAINMENUSTATE).init(gc, sbg); sbg.enterState(Spacerun.MAINMENUSTATE, new FadeOutTransition(), new FadeInTransition()); } } }
@Override public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException{ Input input = gc.getInput(); if(input.isKeyPressed(Input.KEY_LEFT)){ selection = false; }else if(input.isKeyPressed(Input.KEY_RIGHT)){ selection = true; }else if(input.isKeyPressed(Input.KEY_ENTER)){ if(selection){ fHandler.deleteHighscore(); sbg.getState(Spacerun.HIGHSCORESTATE).init(gc, sbg); //we need to update the screen; the easiest way sbg.enterState(Spacerun.HIGHSCORESTATE, new FadeOutTransition(), new FadeInTransition()); }else{ sbg.getState(Spacerun.MAINMENUSTATE).init(gc, sbg); sbg.enterState(Spacerun.MAINMENUSTATE, new FadeOutTransition(), new FadeInTransition()); } } if(input.isKeyPressed(Input.KEY_ESCAPE)){ sbg.getState(Spacerun.MAINMENUSTATE).init(gc, sbg); sbg.enterState(Spacerun.MAINMENUSTATE, new FadeOutTransition(), new FadeInTransition()); } }
@Override public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException { if(!loadComplete) { if(makeFighter(fileName, currentFighter)) { if(loadingSecondCharacter) { loadComplete = true; System.out.println("LOAD COMPLETE"); } else { fileName = fighter2; loadingSecondCharacter = true; } } } if(loadComplete) { //if(flashyThingDone || skipButtonPressed) game.enterState(Manager.StateIndex.FIGHT.ordinal(), new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); } }
/** * @see org.newdawn.slick.state.BasicGameState#keyReleased(int, char) */ public void keyReleased(int key, char c) { if (key == Input.KEY_1) { game.enterState(TestState1.ID, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); } if (key == Input.KEY_3) { game.enterState(TestState3.ID, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); } }
private void proceedToGameProper(StateBasedGame sbg) { // stop playing preview of songs for (int i = 0; i < musicSongChoices.length; i++) { musicSongChoices[i].stop(); } GameProperState.setMonsterP1(monsterP1); GameProperState.setMonsterP2(monsterP2); // TODO low prio. 3..2..1.. Countdown at GameProperState before music starts sbg.enterState(BeatBitBeatMain.getVersusPreview(), new FadeOutTransition(), new FadeInTransition()); }
@Override public void update(GameContainer gameContainer, StateBasedGame stateBasedGame, int i) throws SlickException { if (pressedEscape) { pressedEscape = false; stateBasedGame.enterState(BeatBitBeatMain.getMainMenu(), new FadeOutTransition(), new FadeInTransition()); } }
@Override public void update(GameContainer gameContainer, StateBasedGame stateBasedGame, int i) throws SlickException { Input input = gameContainer.getInput(); xMouse = input.getMouseX(); yMouse = input.getMouseY(); if (pressedEsc) { pressedEsc = false; stateBasedGame.enterState(BeatBitBeatMain.getMainMenu(), new FadeOutTransition(), new FadeInTransition()); } }
public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException { this.delta = delta; // for printing. temporary Input input = gc.getInput(); xMouse = input.getMouseX(); yMouse = input.getMouseY(); // Enter selected state if (enterPressed) { enterPressed = false; try { if (yIndicator == coordsArrows[0].getY()) { // if indicator is pointing to Start btn indexOfSelectedState = BeatBitBeatMain.getCharacterSelection(); // get ID for state } else if (yIndicator == coordsArrows[1].getY()) { // if indicator is pointing to options btn indexOfSelectedState = BeatBitBeatMain.getOptions(); } else if (yIndicator == coordsArrows[2].getY()) { // if indicator is pointing to credits btn indexOfSelectedState = BeatBitBeatMain.getCredits(); } else if (yIndicator == coordsArrows[3].getY()) { // if indicator is pointing to exit btn System.exit(0); } } catch (ArrayIndexOutOfBoundsException e){ } // enter state indicated by indexOfSelectedState sbg.enterState(indexOfSelectedState, new FadeOutTransition(), new FadeInTransition()); } // end of if (enterPressed) }
@Override public void mouseClicked(int button, int x, int y, int clickCount) { if (startButton.contains(x, y) && !clicked) { clicked = true; SFX.playSound(G.SELECT_SOUND); game.enterState(Launcher.GAME_STATE, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); } if (exitButton.contains(x, y) && !clicked) { clicked = true; SFX.playSound(G.SELECT_SOUND); System.exit(0); } }
@Override public void keyPressed(int key, char c) { if (key == Input.KEY_ESCAPE) { if (!pressEscapeState) { pressEscapeState = true; } else { game.enterState(Launcher.MENU_STATE, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); } } else { pressEscapeState = false; } }
@Override public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException { time += delta; if(time > DELAY){ game.enterState(MainMenu.ID, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); } }
@Override protected void layout() { if (mLoaded) { lblStatus.setText(""); mLoginScene.getGame().enterState(2, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); mLoaded = false; } // login panel is centered adjustSize(); setPosition((getParent().getWidth() - getWidth()) / 2, (getParent().getHeight() - getHeight()) / 2); }
@Override public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException { // load three at a time. for (int i = 0; i < LoadingList.get().getRemainingResources(); ++i) { DeferredResource asset = LoadingList.get().getNext(); if (asset != null) { try { asset.load(); } catch (IOException e) { throw new SlickException("Issue asynchronously loading world resources: " + e.getMessage(), e); } } else { break; } if (i > 2) { break; } } if (LoadingList.get().getRemainingResources() == 0 && timeInSplash > MIN_FRAMES_IN_SPLASH) { // Tell next state to actually build the world now that the graphics are in place; remember, // certain calculations require the actual graphics, such as determining the number of hazards. worldIsReady(game); game.enterState( Game.ID, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); } ++timeInSplash; }
private void nameInput(GameContainer gc, StateBasedGame sbg, Input input) throws SlickException{ if(enteredName){ if(input.isKeyPressed(Input.KEY_RIGHT)){ if(!selection){ selection = true; } }else if(input.isKeyPressed(Input.KEY_LEFT)){ if(selection){ selection = false; } }else if(input.isKeyPressed(Input.KEY_ENTER)){ if(selection){ sbg.getState(Spacerun.MAINMENUSTATE).init(gc, sbg); sbg.enterState(Spacerun.MAINMENUSTATE, new FadeOutTransition(), new FadeInTransition()); }else{ sbg.getState(Spacerun.GAMESTATE).init(gc, sbg); sbg.enterState(Spacerun.GAMESTATE, new FadeOutTransition(), new FadeInTransition()); } } }else{ if(input.isKeyPressed(Input.KEY_ENTER)){ new FileHandler().writeHighscore(nameField.getText(), score); nameField.setFocus(false); nameField.setAcceptingInput(false); enteredName = true; } } }