/** * Update this state. * * @param container The gamecontainer that contains this state * @param sbg the state based game that uses this state * @param delta the time in ms since the last frame * @throws SlickException if something goes wrong */ public void update(GameContainer container, StateBasedGame sbg, int delta) throws SlickException { if (RND.getInstance().getOpacity() < 1.0f && !mainGame.getShouldSwitchState()) { RND.getInstance() .setOpacity( RND.getInstance().getOpacity() + ((float) delta) / mainGame.getOpacityFadeTimer()); } input = container.getInput(); nameField.update(input); ipField.update(input); elements.update(input); if ((input.isMousePressed(Input.MOUSE_LEFT_BUTTON) || input.isKeyDown(Input.KEY_ENTER)) && !mainGame.getShouldSwitchState()) { processButtons(input); } SoundPlayer.getInstance().playEffects(); exit(container, sbg, delta); }
/** Attempt to join a game. */ private void attemptJoin() { mainGame.killMultiplayer(); mainGame.setLanMultiplayer(true); processPlayerClient(); mainGame.resetLifeCount(); mainGame.resetLevelCount(); mainGame.setScore(0); Client client = new Client(ipField.getText(), MainGame.getMultiplayerPort(), mainGame, gameState); mainGame.spawnClient(client); mainGame.setIsClient(true); mainGame.setIsHost(false); Logger.getInstance().log("Client started", Logger.PriorityLevels.VERYHIGH, "multiplayer"); }
/** Prepare players for the client's viewpoint. */ private void processPlayerClient() { mainGame.getPlayerList().getPlayers().get(1).setPlayerName(nameField.getText()); mainGame.getPlayerList().getPlayers().get(1).setControlsForPlayer1(); mainGame.getPlayerList().getPlayers().get(0).setControlsDisabled(); }