/** * Add message when returning from game. * * @param message Message to display */ public void addMessage(String message) { mainGame.resetLifeCount(); mainGame.resetLevelCount(); mainGame.setScore(0); this.message = message; elements.throwPopup(message); }
/** * Initialize this state. * * @param container the GameContainer that contains this state * @param arg1 the state based game that uses this state * @throws SlickException if something goes wrong */ public void init(GameContainer container, StateBasedGame arg1) throws SlickException { nameField = new Textfield(TEXT_FIELD_X, TEXT_FIELD_Y, "Player", container); ipField = new Textfield(TEXT_FIELD_X, TEXT_FIELD_Y_2, START_IP, container); popup = new Popup("", MainGame.getxRes(), MainGame.getyRes()); initElements(); separatorTop = new Separator(SEPARATOR_X, SEPARATOR_Y, true, separatorTopTitle, container.getWidth()); separatorHost = new Separator(SEPARATOR_X, SEPARATOR_Y_2, false, separatorHostTitle, container.getWidth()); separatorJoin = new Separator(SEPARATOR_X, SEPARATOR_Y_3, false, separatorJoinTitle, container.getWidth()); separatorMisc = new Separator(SEPARATOR_X, SEPARATOR_Y_4, false, separatorMiscTitle, container.getWidth()); }
/** * Render this state. * * @param container the Gamecontainer that contains this state * @param arg1 the state based game that uses this state * @param graphics the Graphics object used in this state * @throws SlickException if something goes wrong. */ public void render(GameContainer container, StateBasedGame arg1, Graphics graphics) throws SlickException { this.input = container.getInput(); RND.getInstance().drawBackground(graphics); drawText(graphics, container); separatorTop.drawColor(graphics, mainGame.getColor()); separatorHost.drawColor(graphics, mainGame.getColor()); separatorJoin.drawColor(graphics, mainGame.getColor()); separatorMisc.drawColor(graphics, mainGame.getColor()); mainGame.drawWaterMark(); RND.getInstance().drawLogo(graphics, LOGO_X, LOGO_Y); elements.render(graphics, input, mainGame.getColor()); RND.getInstance().drawForeGround(graphics); }
/** Attempt to host a game. */ private void attemptHost() { mainGame.killMultiplayer(); mainGame.setLanMultiplayer(true); processPlayerHost(); mainGame.resetLifeCount(); mainGame.resetLevelCount(); mainGame.setScore(0); mainGame.spawnHost(new Host(MainGame.getMultiplayerPort(), mainGame, gameState)); mainGame.setIsHost(true); mainGame.setIsClient(false); Logger.getInstance().log("Host started", Logger.PriorityLevels.VERYHIGH, "multiplayer"); }
/** 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"); }
/** * Exit function for state. Fades out and everything. * * @param container the GameContainer we are running in * @param sbg the gamestate cont. * @param delta the deltatime in ms */ public void exit(GameContainer container, StateBasedGame sbg, int delta) { if (mainGame.getShouldSwitchState()) { if (RND.getInstance().getOpacity() > 0.0f) { RND.getInstance() .setOpacity( RND.getInstance().getOpacity() - ((float) delta) / mainGame.getOpacityFadeTimer()); } else { Logger.getInstance() .log("Exiting MenuMultiplayerState", Logger.PriorityLevels.LOW, "States"); if (mainGame.getSwitchState() == -1) { container.exit(); } else { mainGame.switchColor(); sbg.enterState(mainGame.getSwitchState()); } } } }
/** * setup all variables when entering this state. * * @param container the Container this state is part of * @param arg1 The statebasedgame this state is part of * @throws SlickException sometimes. */ @Override public void enter(GameContainer container, StateBasedGame arg1) throws SlickException { Logger.getInstance().log("Entering MenuMultiplayerState", Logger.PriorityLevels.LOW, "States"); RND.getInstance().setOpacity(0.0f); elements.reset(); mainGame.stopSwitchState(); SoundPlayer.getInstance().setActiveList(MusicLists.MENU_LIST); }
public WinScreen(MainGame arg0, String background, String winner) { super(arg0, background, new ArrayList<Option>()); ArrayList<Option> options = new ArrayList<Option>(); options.add(new Label("Congrats on winning " + winner)); options.add(new Label("Press r to return to title")); this.setMyOptions(options); this.setNextState((GameState) arg0.getGame(0)); myHandler = new InputHandler(); myHandler.addKey(KeyEvent.VK_R, new QuitAction(arg0)); }
public Monster(MainGame game, Wave wave, int startHitPoints, float speed, int value, String textureFile, int columnCount, int spriteCount, int spriteHeight, int spriteWidth) { super(game, textureFile, new Vector2f(1f, 200f), columnCount, spriteCount, spriteWidth, spriteHeight, 1f); Vector2f startPoint = game.getGameplayScreen().getLevelSettings() .getStartPoint().cpy(); this.setGridPosition(new Vector2f(startPoint.x, MathUtils .nextInt(-1, 2) + startPoint.y)); this.Init(game, wave, value, startHitPoints, speed); }
/** * 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); }
public Monster(MainGame game, Wave wave, int startHitPoints, float speed, int value, String textureFile, int columnCount, int spriteCount, int spriteHeight, int spriteWidth, Vector2f gridPosition) { super(game, textureFile, new Vector2f(1f, 200f), columnCount, spriteCount, spriteWidth, spriteHeight, 1f); if (((gridPosition.x < 2) || (gridPosition.x > 0x10)) || ((gridPosition.y < 0) || (gridPosition.y > 0x12))) { throw new RuntimeException("gridPosition is out of bounds."); } if (game.getGameplayScreen().getDirs()[gridPosition.x()][gridPosition .y()] == null) { throw new RuntimeException("gridPosition is not valid."); } this.setGridPosition(gridPosition); this.Init(game, wave, value, startHitPoints, speed); }
private void Init(MainGame game, Wave wave, int value, int startHitPoints, float speed) { this.setStartHitPoints(startHitPoints); this.setHitPoints(startHitPoints); this.setSpeed(speed); this.setHealthBar(new ProgressBar(game, 20, true)); this.getHealthBar().setDrawOrder(1); this.getHealthBar().setDrawBorder(true); this.setPosition(Utils.ConvertToPositionCoordinates( this.getGridPosition()).add(10f, 10f)); this.destinationPosition = this.getPosition(); this.game = game; this.wave = wave; this.setValue(value); game.Components().add(this.getHealthBar()); game.Components().add(this); }
public BuyToGetFeaturesScreen(MainGame game, ScreenType prevScreen, Difficulty difficulty) { super("", game, prevScreen); this.game = game; super.setTransitionOnTime(0f); super.setTransitionOffTime(0f); super.setIsPopup(true); Vector2f vector = new Vector2f(60f, 50f); MenuEntry item = new MenuEntry(""); item.setuseButtonBackground(false); item.setPosition(new Vector2f(48f, 425f)); item.setnoButtonBackgroundSize(vector); MenuEntry entry2 = new MenuEntry(""); entry2.setuseButtonBackground(false); entry2.setPosition(new Vector2f(222f, 425f)); entry2.setnoButtonBackgroundSize(vector); item.Selected = new GameEvent() { @Override public void invoke(MenuEntry comp) { YesSelected(); } }; entry2.Selected = new GameEvent() { @Override public void invoke(MenuEntry comp) { NoSelected(); } }; super.getMenuEntries().add(item); super.getMenuEntries().add(entry2); this.difficulty = difficulty; this.buyToGetFeaturesSpriteWithText = new BuyToGetFeaturesSpriteWithText( game); this.buyToGetFeaturesSpriteWithText.setDrawOrder(100); game.Components().add(this.buyToGetFeaturesSpriteWithText); }
/** * Draw all the text in this state. * * @param graphics context to use * @param container appgamecontainer to use */ private void drawText(Graphics graphics, GameContainer container) { RND.getInstance() .text( graphics, TEXT_HELP_X, TEXT_HELP_Y_1, "# You can play a game together with another player, over LAN."); RND.getInstance() .text( graphics, TEXT_HELP_X, TEXT_HELP_Y_2, "# If you are the host, you will have to wait until another player joins you."); RND.getInstance() .text( graphics, TEXT_HELP_X, TEXT_HELP_Y_3, "# If you wish to join another player," + " please enter their IP-address below."); RND.getInstance().text(graphics, TEXT_HELP_X, TEXT_HELP_Y_4, "# Your player name:"); if (mainGame.isHost()) { try { RND.getInstance() .text( graphics, TEXT_HOST_X, TEXT_HOST_Y, "# Hosting game on IP: " + InetAddress.getLocalHost().getHostAddress()); } catch (UnknownHostException e) { e.printStackTrace(); } } RND.getInstance().text(graphics, TEXT_HELP_X, TEXT_JOIN_Y, "# Join this IP: "); RND.getInstance() .text( graphics, container.getWidth() / 2 - BOTTOM_TEXT_OFFSET_X, container.getHeight() - BOTTOM_TEXT_OFFSET_Y, "Waiting for user input..."); }
/** Process a click on the return button. */ private void processReturnButton() { mainGame.killMultiplayer(); mainGame.setSwitchState(mainGame.getMainState()); }
/** 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(); }
@Override public int getID() { return mainGame.getMultiplayerState(); }
@Override public void transitionState() { if (nextState != null) myEngine.nextGame = this.nextState; else myEngine.nextGame = this.lastState; finish(); }
@Override public void initResources() { this.lastState = myEngine.getCurrentState(); this.nextState = (GameState) myEngine.getGame(0); }