@Override protected void renderImpl(Graphics graphicContext, Image frameBuffer) { super.renderImpl(graphicContext, frameBuffer); fbGraphics.clear(); fbGraphics.drawImage(frameBuffer, 0, 0); // Player-Glow Post Processing Effect Player player = this.getCurrentPlayer(); if (player != null && Constants.Debug.shadersActive) { // Get Player Position on Screen relative to LOWER left corner float px = player.getData()[Player.X] + player.getData()[Player.CENTER_X] + getData(X); float py = player.getData()[Player.Y] + player.getData()[Player.CENTER_Y] + getData(Y); Color playercol = StateColor.constIntoColor(player.getState().color); Color weaponcol = StateColor.constIntoColor(player.getState().weaponColor); float health = player.getState().health * params.spielerLeuchtstaerke / 10.0f; float ammo = player.getState().ammo * params.waffenLeuchtstaerke / 10.0f; int playerlook = 1; if (player.getState().shootDirection == PlayerActionState.RunLeft) playerlook = -1; // Horizontal Blur Shader.setActiveShader(blur1D); blur1D.initialize(JumpNRun.SCREENWIDTH, JumpNRun.SCREENHEIGHT); fbGraphics.drawImage(frameBuffer, 0, 0); fbGraphics.flush(); // Vertical Blur blur1D.setVertical(); fbGraphics.drawImage(frameBuffer, 0, 0); fbGraphics.flush(); // Draw Glow effects graphicContext.setColor(Color.white); if (params.additiveBlending == true) Shader.activateAdditiveBlending(); Shader.setActiveShader(glowshader); glowshader.setValue("range", params.waffenLeuchtWeite * 10); glowshader.setValue("target", px + 5 * playerlook, py + 40); glowshader.setValue("strength", ammo); glowshader.setValue("playercolor", weaponcol); glowshader.setValue("focus", playerlook * 10.0f / params.waffenLeuchtFocus); graphicContext.drawImage(frameBuffer, 0, 0); Shader.setActiveShader(glowshader2); glowshader2.setValue("range", params.spielerLeuchtWeite * 10); glowshader2.setValue("target", px, py); glowshader2.setValue("strength", health); glowshader2.setValue("playercolor", playercol); glowshader2.setValue("focus", 0); graphicContext.drawImage(frameBuffer, 0, 0); Shader.activateDefaultBlending(); Shader.setActiveShader(null); } }
@Override public void handleInput(Input input) { if (isActive()) { // Left / Right if (!input.isKeyDown(Input.KEY_A) && !input.isKeyDown(Input.KEY_D)) { getVel()[X] = 0.0f; } if (input.isKeyDown(Input.KEY_A)) { getVel()[X] = 600.0f; } if (input.isKeyDown(Input.KEY_D)) { getVel()[X] = -600.0f; } // Up / Down if (!input.isKeyDown(Input.KEY_W) && !input.isKeyDown(Input.KEY_S)) { getVel()[Y] = 0.0f; } if (input.isKeyDown(Input.KEY_W)) { getVel()[Y] = 600.0f; } if (input.isKeyDown(Input.KEY_S)) { getVel()[Y] = -600.0f; } // Zoom if (!input.isKeyDown(Input.KEY_R) && !input.isKeyDown(Input.KEY_F)) { getVel()[SCALE_X] = getVel()[SCALE_Y] = 0.0f; } if (input.isKeyDown(Input.KEY_R)) { getVel()[SCALE_X] = getVel()[SCALE_Y] = 1; } if (input.isKeyDown(Input.KEY_F)) { getVel()[SCALE_X] = getVel()[SCALE_Y] = -1; } // Rotation if (!input.isKeyDown(Input.KEY_Q) && !input.isKeyDown(Input.KEY_E)) { getVel()[ROTATION] = 0.0f; } if (input.isKeyDown(Input.KEY_Q)) { getVel()[ROTATION] = -15; } if (input.isKeyDown(Input.KEY_E)) { getVel()[ROTATION] = 15; } } super.handleInput(input); }
@Override public void update(int deltaInMillis) { super.update(deltaInMillis); // calculate physics if (isActive()) { focusOnPlayer(); checkLevelBordersScrolling(); parallaxScrollingBackground(); } }
@Override protected void postRender(Graphics graphicContext) { super.postRender(graphicContext); graphicContext.setColor(Constants.Debug.overlayColor); graphicContext.drawString( "NetworkID: " + NetworkComponent.getInstance().getNetworkId() + "\n" + factory.size() + " entities", 20, 50); Entity e = this; graphicContext.drawString( "Level\n" + "ID: " + e.getId() + "\n" + " X: " + e.getData()[X] + " Y: " + e.getData()[Y] + "\n" + "OX: " + e.getData()[CENTER_X] + " OY: " + e.getData()[CENTER_Y] + "\n" + "FX: " + "SX: " + e.getData()[SCALE_X] + " SY: " + e.getData()[SCALE_Y] + "\n" + "ROT: " + e.getData()[ROTATION], 20, 100); e = getCurrentPlayer(); if (e != null) { graphicContext.drawString( "Player\n" + "ID: " + e.getId() + "\n" + " X: " + e.getData()[X] + " Y: " + e.getData()[Y] + "\n" + "OX: " + e.getData()[CENTER_X] + " OY: " + e.getData()[CENTER_Y] + "SX: " + e.getData()[SCALE_X] + " SY: " + e.getData()[SCALE_Y] + "\n" + "ROT: " + e.getData()[ROTATION] + "\n" + "STATE: " + ((Player) e).currentState, 20, 250); } }