/** * Gets the Image used to draw the tile at the given x and y coordinates. * * @param x * The x coordinate of the tile whose image should be retrieved * @param y * The y coordinate of the tile whose image should be retrieved * @param layerIndex * The index of the layer on which the tile whose image should be * retrieve exists * @return The image used to draw the specified tile or null if there is no * image for the specified tile. */ public Image getTileImage(int x, int y, int layerIndex) { Layer layer = (Layer) layers.get(layerIndex); int tileSetIndex = layer.data[x][y][0]; if ((tileSetIndex >= 0) && (tileSetIndex < tileSets.size())) { TileSet tileSet = (TileSet) tileSets.get(tileSetIndex); int sheetX = tileSet.getTileX(layer.data[x][y][1]); int sheetY = tileSet.getTileY(layer.data[x][y][1]); return tileSet.tiles.getSprite(sheetX, sheetY); } return null; }
/** * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */ public void init(GameContainer container) throws SlickException { this.container = container; image1 = new Image("testdata/grass.png"); image2 = new Image("testdata/rocks.png"); fill = new GradientFill(-64,0,new Color(1,1,1,1f),64,0,new Color(0,0,0,0)); shape = new Rectangle(336,236,128,128); poly = new Polygon(); poly.addPoint(320,220); poly.addPoint(350,200); poly.addPoint(450,200); poly.addPoint(480,220); poly.addPoint(420,400); poly.addPoint(400,390); }
/** * Create an underlying graphics context for the given image * * @param image The image we want to render to * @return The graphics context created * @throws SlickException */ private static Graphics createGraphics(Image image) throws SlickException { init(); if (fbo) { try { return new FBOGraphics(image); } catch (Exception e) { fbo = false; Log.warn("FBO failed in use, falling back to PBuffer"); } } if (pbuffer) { if (pbufferRT) { return new PBufferGraphics(image); } else { return new PBufferUniqueGraphics(image); } } throw new SlickException("Failed to create offscreen buffer even though the card reports it's possible"); }
/** * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */ public void init(GameContainer container) throws SlickException { this.container = container; try { fire = ParticleIO.loadConfiguredSystem("testdata/system.xml"); } catch (IOException e) { throw new SlickException("Failed to load particle systems", e); } copy = new Image(400,300); String[] formats = ImageOut.getSupportedFormats(); message = "Formats supported: "; for (int i=0;i<formats.length;i++) { message += formats[i]; if (i < formats.length - 1) { message += ","; } } }
/** * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */ public void init(GameContainer container) throws SlickException { LoadingList.setDeferredLoading(true); new Sound("testdata/cbrown01.wav"); new Sound("testdata/engine.wav"); sound = new Sound("testdata/restart.ogg"); new Music("testdata/testloop.ogg"); music = new Music("testdata/SMB-X.XM"); new Image("testdata/cursor.png"); new Image("testdata/cursor.tga"); new Image("testdata/cursor.png"); new Image("testdata/cursor.png"); new Image("testdata/dungeontiles.gif"); new Image("testdata/logo.gif"); image = new Image("testdata/logo.tga"); new Image("testdata/logo.png"); new Image("testdata/rocket.png"); new Image("testdata/testpack.png"); font = new AngelCodeFont("testdata/demo.fnt", "testdata/demo_00.tga"); }
/** * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */ public void init(GameContainer container) throws SlickException { this.container = container; sheet = new PackedSpriteSheet("testdata/testpack.def", Image.FILTER_NEAREST); rocket = sheet.getSprite("rocket"); SpriteSheet anim = sheet.getSpriteSheet("runner"); runner = new Animation(); for (int y=0;y<2;y++) { for (int x=0;x<6;x++) { runner.addFrame(anim.getSprite(x,y), 50); } } }
/** * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics) */ public void render(GameContainer container, Graphics g) { image.draw(0,0); image.draw(500,0,200,100); scaleMe.draw(500,100,200,100); scaled.draw(400,500); Image flipped = scaled.getFlippedCopy(true, false); flipped.draw(520,500); Image flipped2 = flipped.getFlippedCopy(false, true); flipped2.draw(520,380); Image flipped3 = flipped2.getFlippedCopy(true, false); flipped3.draw(400,380); for (int i=0;i<3;i++) { subImage.draw(200+(i*30),300); } g.translate(500, 200); g.rotate(50, 50, rot); g.scale(0.3f,0.3f); image.draw(); g.resetTransform(); }
/** * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */ public void init(GameContainer container) throws SlickException { poly.addPoint(120, 120); poly.addPoint(420, 100); poly.addPoint(620, 420); poly.addPoint(300, 320); image = new Image("testdata/rocks.png"); texPaint = new TexCoordGenerator() { public Vector2f getCoordFor(float x, float y) { float tx = (texRect.getX() - x) / texRect.getWidth(); float ty = (texRect.getY() - y) / texRect.getHeight(); return new Vector2f(tx,ty); } }; }
/** * This method inizializes map, images, animations and sounds * @param container * @throws SlickException */ @Override public void init(GameContainer container) throws SlickException { ready = new Image("data/ready.jpg"); gameOver = new Image("data/gameover.png"); youWin = new Image("data/youwin.png"); mazeMap = new TiledMap("data/maze/Maze.tmx"); initMapProperty(); initAnimations(); begin = new Sound("data/pacmanSound/begin.wav"); begin.play(); eatFruit = new Sound("data/pacmanSound/eatFruit.wav"); pacmanGame.initMaze(mazeMap,this); }
/** * Set the image to use for this sprite sheet image to use for this tileset * * @param image * The image to use for this tileset */ public void setTileSetImage(Image image) { tiles = new SpriteSheet(image, tileWidth, tileHeight, tileSpacing, tileMargin); tilesAcross = tiles.getHorizontalCount(); tilesDown = tiles.getVerticalCount(); if (tilesAcross <= 0) { tilesAcross = 1; } if (tilesDown <= 0) { tilesDown = 1; } lastGID = (tilesAcross * tilesDown) + firstGID - 1; }
/** * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */ public void init(GameContainer container) throws SlickException { this.container = container; image = new Image("testdata/logo.tga", true); Image temp = new Image("testdata/palette_tool.png"); container.setMouseCursor(temp, 0, 0); container.setIcons(new String[] {"testdata/icon.tga"}); container.setTargetFrameRate(100); poly = new Polygon(); float len = 100; for (int x=0;x<360;x+=30) { if (len == 100) { len = 50; } else { len = 100; } poly.addPoint((float) FastTrig.cos(Math.toRadians(x)) * len, (float) FastTrig.sin(Math.toRadians(x)) * len); } }
/** * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */ public void init(GameContainer container) throws SlickException { poly.addPoint(100, 100); poly.addPoint(120, 100); poly.addPoint(120, 120); poly.addPoint(100, 120); image = new Image("testdata/rocks.png"); }
/** * @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); }
public void render(Graphics g) { Image img = AssetManager.getManager().getImage(image); if(img == null) { // Draw the text representing the button. UnicodeFont fnt = AssetManager.getManager().getFont(FONT_NAME); Color color = mouseOver() ? DEFAULT_HOVER : DEFAULT_TEXT; g.setColor(color); g.setFont(fnt); g.drawString(text, position.x, position.y); } else g.drawImage(img, position.x, position.y); }
/** * Create a new graphics context around a pbuffer * * @param image The image we're rendering to * @throws SlickException Indicates a failure to use pbuffers */ public PBufferGraphics(Image image) throws SlickException { super(image.getTexture().getTextureWidth(), image.getTexture().getTextureHeight()); this.image = image; Log.debug("Creating pbuffer(rtt) "+image.getWidth()+"x"+image.getHeight()); if ((Pbuffer.getCapabilities() & Pbuffer.PBUFFER_SUPPORTED) == 0) { throw new SlickException("Your OpenGL card does not support PBuffers and hence can't handle the dynamic images required for this application."); } if ((Pbuffer.getCapabilities() & Pbuffer.RENDER_TEXTURE_SUPPORTED) == 0) { throw new SlickException("Your OpenGL card does not support Render-To-Texture and hence can't handle the dynamic images required for this application."); } init(); }
/** * Get a graphics context for a particular image * * @param image The image for which to retrieve the graphics context * @return The graphics context * @throws SlickException Indicates it wasn't possible to create a graphics context * given available hardware. */ public static Graphics getGraphicsForImage(Image image) throws SlickException { Graphics g = (Graphics) graphics.get(image.getTexture()); if (g == null) { g = createGraphics(image); graphics.put(image.getTexture(), g); } return g; }
/** * Create a new graphics context around an FBO * * @param image The image we're rendering to * @throws SlickException Indicates a failure to use pbuffers */ public FBOGraphics(Image image) throws SlickException { super(image.getTexture().getTextureWidth(), image.getTexture().getTextureHeight()); this.image = image; Log.debug("Creating FBO "+image.getWidth()+"x"+image.getHeight()); boolean FBOEnabled = GLContext.getCapabilities().GL_EXT_framebuffer_object; if (!FBOEnabled) { throw new SlickException("Your OpenGL card does not support FBO and hence can't handle the dynamic images required for this application."); } init(); }
/** * Create a new particle system * * @param defaultSprite The sprite to render for each particle * @param maxParticles The number of particles available in the system */ public ParticleSystem(Image defaultSprite, int maxParticles) { this.maxParticlesPerEmitter= maxParticles; sprite = defaultSprite; dummy = createParticle(this); }
/** * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */ public void init(GameContainer container) throws SlickException { image = tga = new Image("testdata/logo.tga"); scaleMe = new Image("testdata/logo.tga", true, Image.FILTER_NEAREST); gif = new Image("testdata/logo.gif"); scaled = gif.getScaledCopy(120, 120); subImage = image.getSubImage(200,0,70,260); rot = 0; }
public boolean isTouching(double distance) { Image icon = getIcon(); if(icon != null) { float width = icon.getWidth(); float height = icon.getHeight(); return (distance <= ((width + height) / 2)); } else return false; }
/** * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */ public void init(GameContainer container) throws SlickException { this.container = container; try { fire = ParticleIO.loadConfiguredSystem("testdata/system.xml"); trail = ParticleIO.loadConfiguredSystem("testdata/smoketrail.xml"); } catch (IOException e) { throw new SlickException("Failed to load particle systems", e); } image = new Image("testdata/rocket.png"); spawnRocket(); }
@Override public void render(Graphics g, long cTime) { Image icon = getIcon(); if(isActive(cTime) && (icon != null)) { float x = position.x - (icon.getWidth() / 2); float y = position.y - (icon.getHeight() / 2); g.drawImage(icon, x, y); } }
/** * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics) */ public void render(GameContainer container, Graphics g) { g.drawRect(0,0,image.getWidth(),image.getHeight()); image.draw(0,0); image.draw(500,0,200,100); scaleMe.draw(500,100,200,100); scaled.draw(400,500); Image flipped = scaled.getFlippedCopy(true, false); flipped.draw(520,500); Image flipped2 = flipped.getFlippedCopy(false, true); flipped2.draw(520,380); Image flipped3 = flipped2.getFlippedCopy(true, false); flipped3.draw(400,380); for (int i=0;i<3;i++) { subImage.draw(200+(i*30),300); } g.translate(500, 200); g.rotate(50, 50, rot); g.scale(0.3f,0.3f); image.draw(); g.resetTransform(); rotImage.setRotation(rot); rotImage.draw(100, 200); }
/** * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */ public void init(GameContainer container) throws SlickException { // force a 256 pixel limit for testing original = image = new BigImage("testdata/bigimage.tga", Image.FILTER_NEAREST, 512); sub = image.getSubImage(210,210,200,130); scaledSub = sub.getScaledCopy(2); image = image.getScaledCopy(0.3f); imageX = image.getFlippedCopy(true, false); imageY = imageX.getFlippedCopy(true, true); bigSheet = new SpriteSheet(original, 16, 16); }
/** * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */ public void init(GameContainer container) throws SlickException { testImage = new Image("testdata/logo.png"); preloaded = new Image("testdata/logo.png"); testFont = new AngelCodeFont("testdata/hiero.fnt","testdata/hiero.png"); target = new Image(400,300); cut = new Image(100,100); gTarget = target.getGraphics(); offscreenPreload = preloaded.getGraphics(); offscreenPreload.drawString("Drawing over a loaded image", 5, 15); offscreenPreload.setLineWidth(5); offscreenPreload.setAntiAlias(true); offscreenPreload.setColor(Color.blue.brighter()); offscreenPreload.drawOval(200, 30, 50, 50); offscreenPreload.setColor(Color.white); offscreenPreload.drawRect(190,20,70,70); offscreenPreload.flush(); if (GraphicsFactory.usingFBO()) { using = "FBO (Frame Buffer Objects)"; } else if (GraphicsFactory.usingPBuffer()) { using = "Pbuffer (Pixel Buffers)"; } System.out.println(preloaded.getColor(50,50)); }
/** * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */ public void init(GameContainer container) throws SlickException { image = new Image("testdata/rocket.png"); back = new Image("testdata/sky.jpg"); font = new AngelCodeFont("testdata/hiero.fnt","testdata/hiero.png"); SpriteSheet sheet = new SpriteSheet("testdata/homeranim.png", 36, 65); homer = new Animation(sheet, 0,0,7,0,true,150,true); }
/** * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */ public void init(GameContainer container) throws SlickException { Image image = new Image("testdata/particle.tga", true); system = new ParticleSystem(image); system.addEmitter(new FireEmitter(400,300,45)); system.addEmitter(new FireEmitter(200,300,60)); system.addEmitter(new FireEmitter(600,300,30)); //system.setUsePoints(true); }
/** * Release any graphics context that is assocaited with the given image * * @param image The image to release * @throws SlickException Indicates a failure to release the context */ public static void releaseGraphicsForImage(Image image) throws SlickException { Graphics g = (Graphics) graphics.remove(image.getTexture()); if (g != null) { g.destroy(); } }
/** * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */ public void init(GameContainer container) throws SlickException { image = new Image("testdata/testcard.png"); read[0] = image.getColor(0, 0); read[1] = image.getColor(30, 40); read[2] = image.getColor(55, 70); read[3] = image.getColor(80, 90); }
/** * Create a new located image * * @param image The image to be drawn * @param x The x location at which the image should be drawn * @param y The y location at which the image should be drawn */ public LocatedImage(Image image, int x, int y) { this.image = image; this.x = x; this.y = y; this.width = image.getWidth(); this.height = image.getHeight(); }
/** * Render the current frame of the animation. * @param g The graphics context used for drawing. * @param position The position to render the animation at. * @param size The size to override the size of the image with. */ public void render(Graphics g, Pair<Float> position, Pair<Float> size) { Image image = getImage(); if(image != null) { float tlx = position.x - (size.x / 2); float tly = position.y - (size.y / 2); g.drawImage(image, tlx, tly, (tlx + size.x), (tly + size.y), srcPos.x, srcPos.y, (srcPos.x + srcSize.x), (srcPos.y + srcSize.y)); g.resetTransform(); } }
/** * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */ public void init(GameContainer container) throws SlickException { image = new Image("testdata/logo.png"); width = image.getWidth() / 3; height = image.getHeight() / 3; images = new Image[] { image.getSubImage(0, 0, width, height), image.getSubImage(width,0,width,height), image.getSubImage(width*2,0,width,height), image.getSubImage(0, height, width, height), image.getSubImage(width,height,width,height), image.getSubImage(width*2,height,width,height), image.getSubImage(0, height*2, width, height), image.getSubImage(width,height*2,width,height), image.getSubImage(width*2,height*2,width,height), }; images[0].setColor(Image.BOTTOM_RIGHT, 0,1,1,1); images[1].setColor(Image.BOTTOM_LEFT, 0,1,1,1); images[1].setColor(Image.BOTTOM_RIGHT, 0,1,1,1); images[2].setColor(Image.BOTTOM_LEFT, 0,1,1,1); images[3].setColor(Image.TOP_RIGHT, 0,1,1,1); images[3].setColor(Image.BOTTOM_RIGHT, 0,1,1,1); images[4].setColor(Image.TOP_RIGHT, 0,1,1,1); images[4].setColor(Image.TOP_LEFT, 0,1,1,1); images[4].setColor(Image.BOTTOM_LEFT, 0,1,1,1); images[4].setColor(Image.BOTTOM_RIGHT, 0,1,1,1); images[5].setColor(Image.TOP_LEFT, 0,1,1,1); images[5].setColor(Image.BOTTOM_LEFT, 0,1,1,1); images[6].setColor(Image.TOP_RIGHT, 0,1,1,1); images[7].setColor(Image.TOP_RIGHT, 0,1,1,1); images[7].setColor(Image.TOP_LEFT, 0,1,1,1); images[8].setColor(Image.TOP_LEFT, 0,1,1,1); }