/** * Game loop render */ public void render() { Color.white.bind(); texture.bind(); // or GL11.glBind(texture.getTextureID()); GL11.glBegin(GL11.GL_QUADS); GL11.glTexCoord2f(0,0); GL11.glVertex2f(100,100); GL11.glTexCoord2f(1,0); GL11.glVertex2f(100+texture.getTextureWidth(),100); GL11.glTexCoord2f(1,1); GL11.glVertex2f(100+texture.getTextureWidth(),100+texture.getTextureHeight()); GL11.glTexCoord2f(0,1); GL11.glVertex2f(100,100+texture.getTextureHeight()); GL11.glEnd(); font.drawString(150, 300, "HELLO LWJGL WORLD", Color.yellow); }
/** * @see org.newdawn.slick.state.transition.Transition#preRender(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics) */ public void preRender(StateBasedGame game, GameContainer container, Graphics g) throws SlickException { prev.render(container, game, g); MaskUtil.defineMask(); for (int i=0;i<blobs.size();i++) { ((Blob) blobs.get(i)).render(g); } MaskUtil.finishDefineMask(); MaskUtil.drawOnMask(); if (background != null) { Color c = g.getColor(); g.setColor(background); g.fillRect(0,0,container.getWidth(),container.getHeight()); g.setColor(c); } }
/** * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */ public void init(GameContainer container) throws SlickException { this.container = container; SpriteSheet sheet = new SpriteSheet("testdata/homeranim.png", 36, 65); animation = new Animation(); for (int i=0;i<8;i++) { animation.addFrame(sheet.getSprite(i,0), 150); } limited = new Animation(); for (int i=0;i<8;i++) { limited.addFrame(sheet.getSprite(i,0), 150); } limited.stopAt(7); manual = new Animation(false); for (int i=0;i<8;i++) { manual.addFrame(sheet.getSprite(i,0), 150); } pingPong = new Animation(sheet, 0,0,7,0,true,150,true); pingPong.setPingPong(true); container.getGraphics().setBackground(new Color(0.4f,0.6f,0.6f)); }
@Override public void fire(Player player, Pair<Float> position, float theta, long cTime) { Color color = getProjectile().getColor(); float velocity = getProjectile().getVelocity(); float width = getProjectile().getWidth(); float height = getProjectile().getHeight(); long lifespan = getProjectile().getLifespan(); Particle particle = new Particle(color, position, velocity, theta, 0.0f, new Pair<Float>(width, height), lifespan, cTime); Turret turret = new Turret(particle); projectiles.add(turret); ammoInClip--; lastFired = cTime; fireSound.play(); }
public final void drawInUse(int DrawX, int DrawY, int DrawX2, int DrawY2, int SrcX, int SrcY, int SrcX2, int SrcY2) { if (CurrentTexture > 0) { if (slickGame.g != null) { if (Blending == false) { slickResources.images[CurrentTexture].drawEmbedded(DrawX, DrawY, DrawX2, DrawY2, SrcX, SrcY, SrcX2, SrcY2, Color.white); } else { slickResources.images[CurrentTexture].drawEmbedded(DrawX, DrawY, DrawX2, DrawY2, SrcX, SrcY, SrcX2, SrcY2, slickGame.g.getColor()); } } } }
/** * Draw Pause button * @param gc GameContainer * @param g Graphics * @throws SlickException */ public static void showPauseButton(GameContainer gc, Graphics g) throws SlickException { pauseButton.draw(pauseButtonPosX, pauseButtonPosY, pauseButtonWidth, pauseButtonHeight); if (Controller.mouseInArea(pauseButtonPosX, pauseButtonPosY, pauseButtonPosX + pauseButtonHeight, pauseButtonPosY + pauseButtonHeight)) { pauseButton.draw(pauseButtonPosX, pauseButtonPosY, pauseButtonWidth, pauseButtonHeight, new Color(0, 0, 0, 50)); if (Mouse.getEventButtonState() && Mouse.getEventButton() == 0) { gc.setPaused(!gc.isPaused()); try { TimeUnit.MILLISECONDS.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } } }
/** * Loads a single glyph to the backing texture, if it fits. * * @param glyph The glyph to be rendered * @param width The expected width of the glyph * @param height The expected height of the glyph * @throws SlickException if the glyph could not be rendered. */ private void renderGlyph(Glyph glyph, int width, int height) throws SlickException { // Draw the glyph to the scratch image using Java2D. scratchGraphics.setComposite(AlphaComposite.Clear); scratchGraphics.fillRect(0, 0, MAX_GLYPH_SIZE, MAX_GLYPH_SIZE); scratchGraphics.setComposite(AlphaComposite.SrcOver); scratchGraphics.setColor(java.awt.Color.white); for (Iterator iter = unicodeFont.getEffects().iterator(); iter.hasNext();) ((Effect)iter.next()).draw(scratchImage, scratchGraphics, unicodeFont, glyph); glyph.setShape(null); // The shape will never be needed again. WritableRaster raster = scratchImage.getRaster(); int[] row = new int[width]; for (int y = 0; y < height; y++) { raster.getDataElements(0, y, width, 1, row); scratchIntBuffer.put(row); } GL.glTexSubImage2D(SGL.GL_TEXTURE_2D, 0, pageX, pageY, width, height, SGL.GL_BGRA, SGL.GL_UNSIGNED_BYTE, scratchByteBuffer); scratchIntBuffer.clear(); glyph.setImage(pageImage.getSubImage(pageX, pageY, width, height)); }
/** * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics) */ public void render(GameContainer container, Graphics g) { g.rotate(400, 300, ang); g.fill(rect, gradient); g.fill(round, gradient); g.fill(poly, gradient2); g.fill(center, gradient4); g.setAntiAlias(true); g.setLineWidth(10); g.draw(round2, gradient2); g.setLineWidth(2); g.draw(poly, gradient); g.setAntiAlias(false); g.fill(center, gradient4); g.setAntiAlias(true); g.setColor(Color.black); g.draw(center); g.setAntiAlias(false); }
@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); } }
/** * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics) */ public void render(GameContainer container, Graphics g) { g.setColor(Color.white); g.drawString("The OGG loop is now streaming from the file, woot.",100,60); g.drawString("Press space for sound effect (OGG)",100,100); g.drawString("Press P to pause/resume music (XM)",100,130); g.drawString("Press E to pause/resume engine sound (WAV)",100,190); g.drawString("Press enter for charlie (WAV)",100,160); g.drawString("Press C to change music",100,210); g.drawString("Press B to burp (AIF)",100,240); g.drawString("Press + or - to change global volume of music", 100, 270); g.drawString("Press Y or X to change individual volume of music", 100, 300); g.drawString("Press N or M to change global volume of sound fx", 100, 330); g.setColor(Color.blue); g.drawString("Global Sound Volume Level: " + container.getSoundVolume(), 150, 390); g.drawString("Global Music Volume Level: " + container.getMusicVolume(), 150, 420); g.drawString("Current Music Volume Level: " + music.getVolume(), 150, 450); }
/** * @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics) */ public void render(GameContainer container, Graphics g) throws SlickException { g.setAntiAlias(antialias); g.setLineWidth(50); g.setColor(Color.red); g.draw(path); // g.setColor(Color.red); // TextureImpl.bindNone(); // g.setLineWidth(width); // g.setAntiAlias(true); // for (int i=0;i<10;i++) { // g.translate(35,35); // g.draw(polygon); // } // g.translate(-350,-350); // // g.setColor(Color.white); // g.setLineWidth(1); // g.setAntiAlias(false); // g.draw(polygon); }
/** * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics) */ public void render(GameContainer container, Graphics g) { g.drawString("left shift down: "+lshift, 100, 240); g.drawString("right shift down: "+rshift, 100, 260); g.drawString("space down: "+space, 100, 280); g.setColor(Color.white); g.drawString(message, 10, 50); g.drawString(""+container.getInput().getMouseY(), 10, 400); g.drawString("Use the primary gamepad to control the blob, and hit a gamepad button to change the color", 10, 90); for (int i=0;i<lines.size();i++) { Line line = (Line) lines.get(i); line.draw(g); } g.setColor(cols[index]); g.fillOval((int) x, (int) y, 50, 50); g.setColor(Color.yellow); g.fillRect(50,200+ypos,40,40); }
/** * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics) */ public void render(GameContainer container, Graphics g) { g.setColor(Color.green); for(int i=0;i<shapes.size();i++) { g.fill((Shape)shapes.get(i)); } g.fill(randomShape); g.setColor(Color.black); g.setAntiAlias(true); g.draw(randomShape); g.setAntiAlias(false); g.setColor(Color.white); g.drawString("keys", 10, 300); g.drawString("wasd - move rectangle", 10, 315); g.drawString("WASD - resize rectangle", 10, 330); g.drawString("tgfh - move rounded rectangle", 10, 345); g.drawString("TGFH - resize rounded rectangle", 10, 360); g.drawString("ry - resize corner radius on rounded rectangle", 10, 375); g.drawString("ikjl - move ellipse", 10, 390); g.drawString("IKJL - resize ellipse", 10, 405); g.drawString("Arrows - move circle", 10, 420); g.drawString("Page Up/Page Down - resize circle", 10, 435); g.drawString("numpad 8546 - move polygon", 10, 450); }
/** * @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics) */ public void render(GameContainer container, Graphics g) throws SlickException { g.setColor(Color.gray); drawMarker(g, p1); drawMarker(g, p2); g.setColor(Color.red); drawMarker(g, c1); drawMarker(g, c2); g.setColor(Color.black); g.draw(curve); g.fill(curve); g.draw(poly); g.fill(poly); }
/** * Get the intepolated colour at the given location on the gradient * * @param p The point of the gradient (0 >= n >= 1) * @return The interpolated colour at the given location */ public Color getColorAt(float p) { if (p <= 0) { return ((Step) steps.get(0)).col; } if (p > 1) { return ((Step) steps.get(steps.size()-1)).col; } for (int i=1;i<steps.size();i++) { Step prev = ((Step) steps.get(i-1)); Step current = ((Step) steps.get(i)); if (p <= current.location) { float dis = current.location - prev.location; p -= prev.location; float v = p / dis; Color c = new Color(1,1,1,1); c.a = (prev.col.a * (1 - v)) + (current.col.a * (v)); c.r = (prev.col.r * (1 - v)) + (current.col.r * (v)); c.g = (prev.col.g * (1 - v)) + (current.col.g * (v)); c.b = (prev.col.b * (1 - v)) + (current.col.b * (v)); return c; } } // shouldn't ever happen return Color.black; }
/** * Update the state of the emitter based on colours in the editor */ private void updateColors() { if (blockUpdates) { return; } emitter.colors.clear(); for (int i=0;i<grad.getControlPointCount();i++) { float pos = grad.getPointPos(i); java.awt.Color col = grad.getColor(i); Color slick = new Color(col.getRed() / 255.0f, col.getGreen() / 255.0f, col.getBlue() / 255.0f, 1.0f); emitter.addColorPoint(pos, slick); } }
/** * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics) */ public void render(GameContainer container, Graphics g) { g.setColor(Color.white); g.drawString("The OGG loop is now streaming from the file, woot.",100,60); g.drawString("Press space for sound effect (OGG)",100,100); g.drawString("Press P to pause/resume music (XM)",100,130); g.drawString("Press E to pause/resume engine sound (WAV)",100,190); g.drawString("Press enter for charlie (WAV)",100,160); g.drawString("Press C to change music",100,210); g.drawString("Press B to burp (AIF)",100,240); g.drawString("Press + or - to change volume of music", 100, 270); g.setColor(Color.blue); g.drawString("Music Volume Level: " + volume / 10.0f, 150, 300); }
/** * @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics) */ public void render(GameContainer container, Graphics g) throws SlickException { g.setColor(Color.white); g.texture(poly, image); ShapeRenderer.texture(poly, image, texPaint); }
/** * @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int) */ public void update(GameContainer container, int delta) { int mx = container.getInput().getMouseX(); int my = container.getInput().getMouseY(); if ((mx >= 100) && (my >= 100) && (mx < 200) && (my < 200)) { read[4] = image.getColor(mx-100,my-100); } else { read[4] = Color.black; } read[5] = g.getPixel(mx, my); }
/** * Show play button * @param gc GameContainer * @param g Graphics */ public static void showPlayButton(GameContainer gc, Graphics g) { if (gc.isPaused()) { g.setColor(new Color(1, 1, 1, 100)); g.fillRect(0, 0, PZGUI.getWidth(), PZGUI.getHeight()); gamePausedText.render((PZGUI.getWidth()/2 - 170) * PZGUI.getResolutionRateWidth(), 300 * PZGUI.getResolutionRateHeight(), "Game is Paused!"); playButton.draw(pauseButtonPosX, pauseButtonPosY, pauseButtonWidth, pauseButtonHeight); } }
public void render(GameContainer container, Graphics g) throws SlickException { g.setColor(Color.white); g.drawString("Endianness is " + endian, 10, 100); g.drawString("Image below should be red", 10, 200); g.drawImage(fromRed, 10, 220); g.drawString("Image below should be blue", 410, 200); g.drawImage(fromBlue, 410, 220); }
static Icon getColorIcon (java.awt.Color color) { BufferedImage image = new BufferedImage(32, 16, BufferedImage.TYPE_INT_RGB); java.awt.Graphics g = image.getGraphics(); g.setColor(color); g.fillRect(1, 1, 30, 14); g.setColor(java.awt.Color.black); g.drawRect(0, 0, 31, 15); return new ImageIcon(image); }
/** * @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics) */ public void render(GameContainer container, Graphics g) throws SlickException { g.setColor(new Color(0.4f,0.6f,0.8f)); g.fillRect(0,0, 1024,568); g.setColor(Color.white); g.drawRect(5,5, 1024-10,568-10); g.setColor(Color.white); g.drawString(container.getInput().getMouseX()+","+container.getInput().getMouseY(), 10, 400); g.setColor(Color.red); g.fillOval(container.getInput().getMouseX()-10,container.getInput().getMouseY()-10,20,20); }
/** * @see org.newdawn.slick.Game#render(GameContainer, Graphics) */ public void render(GameContainer container, Graphics g) throws SlickException { g.setColor(Color.green); g.draw(a); g.setColor(Color.red); g.draw(b); g.setColor(Color.blue); g.draw(c); g.setColor(Color.white); g.draw(morph); }
/** * @see org.newdawn.slick.state.transition.Transition#postRender(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics) */ public void postRender(StateBasedGame game, GameContainer container, Graphics g) { Color old = g.getColor(); g.setColor(color); g.fillRect(0, 0, container.getWidth()*2, container.getHeight()*2); g.setColor(old); }
/** * Generate the image used for texturing the gradient across shapes */ public void genImage() { if (image == null) { ImageBuffer buffer = new ImageBuffer(128,16); for (int i=0;i<128;i++) { Color col = getColorAt(i / 128.0f); for (int j=0;j<16;j++) { buffer.setRGBA(i, j, col.getRedByte(), col.getGreenByte(), col.getBlueByte(), col.getAlphaByte()); } } image = buffer.getImage(); } }
@SuppressWarnings("serial") @Override public void init(GameContainer gc, StateBasedGame game) throws SlickException { assets = AssetManager.getManager(); expToLevelTooltip = new TooltipText(TrainState.FONT_NORMAL, "Exp To Next Level:", "Your progress towards leveling up and gaining a skill point.", Color.white, new Pair<Float>(30.0f, 120.0f)); healthUpTooltip = new TooltipText(TrainState.FONT_NORMAL, "Max Health:", "Each point in this increases your health by 20.", Color.white, new Pair<Float>(30.0f, 210.0f)); speedUpTooltip = new TooltipText(TrainState.FONT_NORMAL, "Speed:", "Each point in this increases your movement speed by 10%.", Color.white, new Pair<Float>(30.0f, 300.0f)); damageUpTooltip = new TooltipText(TrainState.FONT_NORMAL, "Damage:", "Each point in this increases damage done by 10%.", Color.white, new Pair<Float>(30.0f, 390.0f)); skillButtons = new ArrayList<SkillButton>() {{ add(new SkillButton("healthUp", true, new Pair<Float>(400.0f, 240.0f))); add(new SkillButton("healthUp", false, new Pair<Float>(340.0f, 240.0f))); add(new SkillButton("speedUp", true, new Pair<Float>(400.0f, 330.0f))); add(new SkillButton("speedUp", false, new Pair<Float>(340.0f, 330.0f))); add(new SkillButton("damageUp", true, new Pair<Float>(400.0f, 420.0f))); add(new SkillButton("damageUp", false, new Pair<Float>(340.0f, 420.0f))); }}; exit = false; }
/** * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, * org.newdawn.slick.Graphics) */ public void render(GameContainer container, Graphics g) { g.setFont(font); if (visible) { for (int i = 0; i < lines.size(); i++) { font.drawString(10, 50 + (i * 20), (String) lines.get(i), i > 10 ? Color.red : Color.green); } } }
/** * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */ public void init(GameContainer container) throws SlickException { this.container = container; geomColor = Color.magenta; overlayColor = Color.white; magImage = new Image(21, 21); }
/** * @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics) */ public void render(GameContainer container, Graphics g) throws SlickException { g.clearAlphaMap(); g.setDrawMode(Graphics.MODE_NORMAL); g.setColor(Color.white); g.fillOval(100,100,150,150); textureMap.draw(10,50); g.copyArea(copy, 100,100); g.setColor(Color.red); g.fillRect(300,100,200,200); copy.draw(350,150); }
/** * @see org.newdawn.slick.state.BasicGameState#render(org.newdawn.slick.GameContainer, org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.Graphics) */ public void render(GameContainer container, StateBasedGame game, Graphics g) { g.setFont(font); g.setColor(Color.green); g.drawString("This is State 2", 200, 50); g.rotate(400,300,ang); g.drawImage(image,400-(image.getWidth()/2),300-(image.getHeight()/2)); }