/** @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int) */ public void update(GameContainer container, int delta) throws SlickException { if ((targetHeight != container.getHeight()) || (targetWidth != container.getWidth())) { recalculateScale(); } held.update(container, delta); }
/** * Update and render the game * * @param delta The change in time since last update and render * @throws SlickException Indicates an internal fault to the game. */ protected void updateAndRender(int delta) throws SlickException { storedDelta += delta; input.poll(width, height); SoundStore.get().poll(delta); if (storedDelta >= minimumLogicInterval) { try { if (maximumLogicInterval != 0) { long cycles = storedDelta / maximumLogicInterval; for (int i = 0; i < cycles; i++) { game.update(this, (int) maximumLogicInterval); } game.update(this, (int) (delta % maximumLogicInterval)); } else { game.update(this, (int) storedDelta); } storedDelta = 0; } catch (Throwable e) { Log.error(e); throw new SlickException("Game.update() failure - check the game code."); } } GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); GL11.glLoadIdentity(); graphics.resetFont(); graphics.resetLineWidth(); graphics.setAntiAlias(false); try { game.render(this, graphics); } catch (Throwable e) { Log.error(e); throw new SlickException("Game.render() failure - check the game code."); } graphics.resetTransform(); if (showFPS) { defaultFont.drawString(10, 10, "FPS: " + recordedFPS); } if (targetFPS != -1) { Display.sync(targetFPS); } }
public void update() { super.update(); probState.update(true); if (Gdx.input.justTouched()) { field.update(Gdx.input.getX(), Gdx.input.getY()); field2.update(Gdx.input.getX(), Gdx.input.getY()); } if (field.update()) { field.animateTo(new Vector2(Gdx.graphics.getWidth() / 2, 2 * Gdx.graphics.getHeight() / 3)); field2.setVisible(true); } if (field2.update()) { System.out.println("okay"); Application.TRANSITION_SIGNAL = 83; } }
@Override public void simpleUpdate(float tpf) { if (loading) { if (loading_frames == 0) { if (game.isMultiplayer() && client.allConnected() == false) { return; } } if (loading_frames == 5) { if (game.isMultiplayer() && client.allLoaded() == false) { return; } } loading(loading_frames); loading_frames++; } else { loops = 0; while (System.currentTimeMillis() > next_game_tick && loops < MAX_FRAMESKIP && (game.isMultiplayer() == false || client.canContinue())) { if (game.isMultiplayer()) { client.update(); } Timer.update(GAME_TPF); game.update(GAME_TPF); next_game_tick += SKIP_TICKS; loops++; } camera.update(tpf); listener.setLocation(cam.getLocation()); listener.setRotation(cam.getRotation()); gui.update(tpf); // nur wegen Kamera auf Minimap } }
/** * Update and render the game * * @param delta The change in time since last update and render * @throws SlickException Indicates an internal fault to the game. */ protected void updateAndRender(int delta) throws SlickException { if (smoothDeltas) { if (getFPS() != 0) { delta = 1000 / getFPS(); } } input.poll(width, height); Music.poll(delta); if (!paused) { storedDelta += delta; if (storedDelta >= minimumLogicInterval) { try { if (maximumLogicInterval != 0) { long cycles = storedDelta / maximumLogicInterval; for (int i = 0; i < cycles; i++) { game.update(this, (int) maximumLogicInterval); } int remainder = (int) (storedDelta % maximumLogicInterval); if (remainder > minimumLogicInterval) { game.update(this, (int) (remainder % maximumLogicInterval)); storedDelta = 0; } else { storedDelta = remainder; } } else { game.update(this, (int) storedDelta); storedDelta = 0; } } catch (Throwable e) { // Log.error(e); throw new SlickException("Game.update() failure.", e); } } } else { game.update(this, 0); } if (hasFocus() || getAlwaysRender()) { if (clearEachFrame) { GL.glClear(SGL.GL_COLOR_BUFFER_BIT | SGL.GL_DEPTH_BUFFER_BIT); } GL.glLoadIdentity(); graphics.resetTransform(); graphics.resetFont(); graphics.resetLineWidth(); graphics.setAntiAlias(false); try { game.render(this, graphics); } catch (Throwable e) { // Log.error(e); throw new SlickException("Game.render() failure.", e); } graphics.resetTransform(); if (showFPS) { defaultFont.drawString(10, 10, "FPS: " + recordedFPS); } GL.flush(); } if (targetFPS != -1) { Display.sync(targetFPS); } }
public static void main(String[] args) throws IOException { String indexHTML = new String(Files.readAllBytes(Paths.get("index.html"))); String createHTML = new String(Files.readAllBytes(Paths.get("create.html"))); Spark.port(80); Spark.get( "/create-submit", (request, response) -> { Game newGame = new Game(request.queryParams("name"), Integer.valueOf(request.queryParams("size"))); games.put(newGame.hashCode(), newGame); // response.redirect("/game/" + newGame.hashCode()); response.redirect("/"); return "success"; }); Spark.get( "/create", (request, response) -> { return createHTML; }); Spark.get( "/game/:gameID/:player/:x/:y/:xOffset/:yOffset", (request, response) -> { Game game = games.get(Integer.parseInt(request.params(":gameID"))); game.update( Integer.parseInt(request.params(":x")), Integer.parseInt(request.params(":y")), request.params(":player"), Integer.parseInt(request.params(":xOffset")), Integer.parseInt(request.params(":yOffset"))); return game.draw(request.params(":player")); }); Spark.get( "/game/:gameID/:player/:x/:y", (request, response) -> { Game game = games.get(Integer.parseInt(request.params(":gameID"))); game.update( Integer.parseInt(request.params(":x")), Integer.parseInt(request.params(":y")), request.params(":player"), 1, 1); return game.draw(request.params(":player")); }); Spark.get( "/game/:gameID/:player", (request, response) -> { return games .get(Integer.parseInt(request.params(":gameID"))) .draw(request.params(":player")); }); Spark.get( "/game/:gameID", (request, response) -> { return ""; }); // default route, home page Spark.get( "/", (request, response) -> { StringBuilder gameList = new StringBuilder(); ArrayList<Game> gamesList = new ArrayList<>(games.values()); Collections.sort(gamesList); for (Game game : gamesList) { gameList.append( " " + game.getName() + "\t<a href=\"/game/" + game.hashCode() + "/green\">Green</a>\t<a href=\"/game/" + game.hashCode() + "/red\">Red</a>\n" + " </br>\n"); } return indexHTML.replace("<!--INSERT_GAME_LIST-->", gameList.toString()); }); }
private void update() { Input.update(); game.update(); glfwPollEvents(); }