/** * @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 { if (moveBackDone) { g.translate(xp1,yp1); g.scale(scale1, scale1); g.setClip((int) xp1,(int) yp1,(int) (scale1*container.getWidth()),(int) (scale1*container.getHeight())); prev.render(container, game, g); g.resetTransform(); g.clearClip(); } g.translate(xp2,yp2); g.scale(scale2, scale2); g.setClip((int) xp2,(int) yp2,(int) (scale2*container.getWidth()),(int) (scale2*container.getHeight())); }
/** * 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); }
/** * @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.Game#init(org.newdawn.slick.GameContainer) */ public void init(GameContainer container) throws SlickException { awtFont = new java.awt.Font("Verdana", Font.PLAIN, 16); font = new TrueTypeFont(awtFont, false); for (int j = 0; j < 2; j++) { int lineLen = 90; for (int i = 0; i < text.length(); i += lineLen) { if (i + lineLen > text.length()) { lineLen = text.length() - i; } lines.add(text.substring(i, i + lineLen)); } lines.add(""); } }
@Override public void update(GameContainer gc, StateBasedGame game, int delta) throws SlickException { if(gameStart.inBounds(Globals.mouse.getPosition().x, Globals.mouse.getPosition().y)) { gameStart.mouseEnter(); if(Globals.mouse.isMouseDown()) { Globals.resetEntityNum(); Globals.resetInputs(); game.enterState(GameState.ID, new FadeOutTransition(), new FadeInTransition()); } } else gameStart.mouseExit(); if(credits.inBounds(Globals.mouse.getPosition().x, Globals.mouse.getPosition().y)) credits.mouseEnter(); else credits.mouseExit(); if(exit.inBounds(Globals.mouse.getPosition().x, Globals.mouse.getPosition().y)) { exit.mouseEnter(); if(Globals.mouse.isMouseDown()) gc.exit(); } else exit.mouseExit(); MusicPlayer.getInstance().update(); }
/** * @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 a Slick image writer for the given format * * @param format The format of the image to write * @return The image write to use to produce these images * @throws SlickException */ public static ImageWriter getWriterForFormat(String format) throws SlickException { ImageWriter writer = (ImageWriter) writers.get(format); if (writer != null) { return writer; } writer = (ImageWriter) writers.get(format.toLowerCase()); if (writer != null) { return writer; } writer = (ImageWriter) writers.get(format.toUpperCase()); if (writer != null) { return writer; } throw new SlickException("No image writer available for: "+format); }
/** * change texture of ghost current frame * according with rotation of the ghost * @throws SlickException */ @Override public void rotate(int value) throws SlickException { switch(value) { case 0: this.getImage(0).setTexture(textureData[6]); this.getImage(1).setTexture(textureData[7]); break; case 90: this.getImage(0).setTexture(textureData[2]); this.getImage(1).setTexture(textureData[3]); break; case 180: this.getImage(0).setTexture(textureData[4]); this.getImage(1).setTexture(textureData[5]); break; case 270: this.getImage(0).setTexture(textureData[0]); this.getImage(1).setTexture(textureData[1]); break; } }
/** * 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(); } } } }
/** * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */ public void init(GameContainer container) throws SlickException { this.container = container; rect = new Rectangle(400,100,200,150); round = new RoundedRectangle(150,100,200,150,50); round2 = new RoundedRectangle(150,300,200,150,50); center = new Rectangle(350,250,100,100); poly = new Polygon(); poly.addPoint(400,350); poly.addPoint(550,320); poly.addPoint(600,380); poly.addPoint(620,450); poly.addPoint(500,450); gradient = new GradientFill(0,-75,Color.red,0,75,Color.yellow,true); gradient2 = new GradientFill(0,-75,Color.blue,0,75,Color.white,true); gradient4 = new GradientFill(-50,-40,Color.green,50,40,Color.cyan,true); }
/** * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */ public final void init(GameContainer container) throws SlickException { this.container = container; initStatesList(container); Iterator gameStates = states.values().iterator(); while (gameStates.hasNext()) { GameState state = (GameState) gameStates.next(); state.init(container, this); } if (currentState != null) { currentState.enter(container, this); } }
/** * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics) */ public void render(GameContainer container, Graphics g) throws SlickException { g.scale(2,2); g.fillRect(0, 0, 800, 600, back, 0, 0); g.resetTransform(); g.drawImage(image,100,100); image.draw(100,200,80,200); font.drawString(100,200,"Text Drawn before the callable"); SlickCallable callable = new SlickCallable() { protected void performGLOperations() throws SlickException { renderGL(); } }; callable.call(); homer.draw(450,250,80,200); font.drawString(150,300,"Text Drawn after the callable"); }
@SuppressWarnings("unchecked") public void addFont(String key, String file, int size, boolean bold, boolean italic, Effect [] effects) throws SlickException { try { AssetManager.ASSETS_TO_LOAD++; UnicodeFont uni = new UnicodeFont(file, size, bold, italic); uni.addAsciiGlyphs(); uni.addGlyphs(400, 600); uni.getEffects().add(new ColorEffect(Color.WHITE)); uni.getEffects().addAll(Arrays.asList(effects)); uni.loadGlyphs(); if((fonts != null) && (uni != null)) { fonts.put(key, uni); AssetManager.ASSETS_LOADED++; System.out.println(String.format("Font Loaded: %s", key)); } } catch(Exception ex) { ex.printStackTrace(); System.out.printf("ERROR: Font \"%s\" could not be loaded!\n", file); } }
/** * Initialise offscreen rendering by checking what buffers are supported * by the card * * @throws SlickException Indicates no buffers are supported */ private static void init() throws SlickException { init = true; if (fbo) { fbo = GLContext.getCapabilities().GL_EXT_framebuffer_object; } pbuffer = (Pbuffer.getCapabilities() & Pbuffer.PBUFFER_SUPPORTED) != 0; pbufferRT = (Pbuffer.getCapabilities() & Pbuffer.RENDER_TEXTURE_SUPPORTED) != 0; if (!fbo && !pbuffer && !pbufferRT) { throw new SlickException("Your OpenGL card does not support offscreen buffers and hence can't handle the dynamic images required for this application."); } Log.info("Offscreen Buffers FBO="+fbo+" PBUFFER="+pbuffer+" PBUFFERRT="+pbufferRT); }
/** * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */ public void init(GameContainer container) throws SlickException { sound = new Sound(ResourceLoader.getResource("testdata/restart.ogg")); charlie = new Sound(ResourceLoader.getResource("testdata/cbrown01.wav")); engine = new Sound(ResourceLoader.getResource("testdata/engine.wav")); //music = musica = new Music("testdata/SMB-X.XM"); music = musica = new Music(ResourceLoader.getResource("testdata/restart.ogg"), false); musicb = new Music(ResourceLoader.getResource("testdata/kirby.ogg"), false); burp = new Sound(ResourceLoader.getResource("testdata/burp.aif")); }
/** * Entry point to our test * * @param argv The arguments to pass into the test */ public static void main(String[] argv) { try { AppGameContainer container = new AppGameContainer(new ClipTest()); container.setDisplayMode(800,600,false); container.start(); } catch (SlickException e) { e.printStackTrace(); } }
/** * Entry point to the sound test * * @param argv The arguments provided to the test */ public static void main(String[] argv) { try { AppGameContainer container = new AppGameContainer(new SoundTest()); container.setDisplayMode(800,600,false); container.start(); } catch (SlickException e) { e.printStackTrace(); } }
/** * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */ public void init(GameContainer container) throws SlickException { map = new TiledMap("testdata/testmap.tmx","testdata"); // read some properties from map and layer mapName = map.getMapProperty("name", "Unknown map name"); monsterDifficulty = map.getLayerProperty(0, "monsters", "easy peasy"); nonExistingMapProperty = map.getMapProperty("zaphod", "Undefined map property"); nonExistingLayerProperty = map.getLayerProperty(1, "beeblebrox", "Undefined layer property"); // store the original tileid of layer 0 at 10, 10 originalTileID = map.getTileId(10, 10, 0); }
/** * Entry point to our simple test * * @param args The arguments supplied to the test * @throws SlickException Indicates a failure loading or processing resources * @throws IOException Indicates a failure loading the font */ public static void main(String[] args) throws SlickException, IOException { Input.disableControllers(); AppGameContainer container = new AppGameContainer(new UnicodeFontTest()); container.setDisplayMode(512, 600, false); container.setTargetFrameRate(20); container.start(); }
/** * Entry point to our test * * @param argv The arguments to pass into the test */ public static void main(String[] argv) { try { AppGameContainer container = new AppGameContainer(new InputProviderTest()); container.setDisplayMode(800,600,false); container.start(); } catch (SlickException e) { e.printStackTrace(); } }
/** * @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.state.transition.Transition#update(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, int) */ public void update(StateBasedGame game, GameContainer container, int delta) throws SlickException { for (int i=0;i<transitions.size();i++) { Transition t = (Transition) transitions.get(i); if (!t.isComplete()) { t.update(game, container, delta); } } }
/** * @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#update(org.newdawn.slick.GameContainer, int) */ public void update(GameContainer container, int delta) throws SlickException { if (container.getInput().isKeyDown(Input.KEY_Q)) { zoom += (delta * 0.01f); if (zoom > 10) { zoom = 10; } } if (container.getInput().isKeyDown(Input.KEY_A)) { zoom -= (delta * 0.01f); if (zoom < 0.1f) { zoom = 0.1f; } } if (container.getInput().isKeyDown(Input.KEY_RIGHT)) { x += (delta * 0.1f); } if (container.getInput().isKeyDown(Input.KEY_LEFT)) { x -= (delta * 0.1f); } if (container.getInput().isKeyDown(Input.KEY_DOWN)) { y += (delta * 0.1f); } if (container.getInput().isKeyDown(Input.KEY_UP)) { y -= (delta * 0.1f); } }
/** * Entry point to our test * * @param argv The arguments passed to the test */ public static void main(String[] argv) { try { AppGameContainer container = new AppGameContainer(new AntiAliasTest()); container.setDisplayMode(800,600,false); container.start(); } catch (SlickException e) { e.printStackTrace(); } }
/** * @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); }
/** * Entry point to our test * * @param argv The arguments passed into our test */ public static void main(String[] argv) { try { AppGameContainer container = new AppGameContainer(new InputTest()); container.setDisplayMode(800,600,false); container.start(); } catch (SlickException e) { e.printStackTrace(); } }
/** * Update data map etc */ public void update(GameContainer container, int delta) throws SlickException { if (container.getInput().isKeyPressed(Input.KEY_1)) { showLinks = !showLinks; } if (container.getInput().isKeyPressed(Input.KEY_2)) { showSpaces = !showSpaces; } }
/** * @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) throws SlickException { g.resetTransform(); if (!moveBackDone) { g.translate(xp1,yp1); g.scale(scale1, scale1); g.setClip((int) xp1,(int) yp1,(int) (scale1*container.getWidth()),(int) (scale1*container.getHeight())); prev.render(container, game, g); g.resetTransform(); g.clearClip(); } }
/** * @see BasicGame#init(GameContainer) */ public void init(GameContainer container) throws SlickException { a = new Rectangle(100,100,50,200); a = a.transform(Transform.createRotateTransform(0.1f,100,100)); b = new Rectangle(200,100,50,200); b = b.transform(Transform.createRotateTransform(-0.6f,100,100)); c = new Rectangle(300,100,50,200); c = c.transform(Transform.createRotateTransform(-0.2f,100,100)); morph = new MorphShape(a); morph.addShape(b); morph.addShape(c); container.setVSync(true); }
/** * @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); }
/** * Entry point to the sound test * * @param argv The arguments provided to the test */ public static void main(String[] argv) { try { AppGameContainer container = new AppGameContainer(new SoundURLTest()); container.setDisplayMode(800,600,false); container.start(); } catch (SlickException e) { e.printStackTrace(); } }
/** * Entry point to our test * * @param argv The arguments to pass into the test */ public static void main(String[] argv) { try { AppGameContainer container = new AppGameContainer(new GradientImageTest()); container.setDisplayMode(800,600,false); container.start(); } catch (SlickException e) { e.printStackTrace(); } }
/** * @see org.newdawn.slick.state.transition.Transition#update(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, int) */ public void update(StateBasedGame game, GameContainer container, int delta) throws SlickException { offset += delta * 1f; if (offset > container.getWidth() / 2) { finish = true; } }
/** * Entry point to our simple test * * @param argv The arguments passed in */ public static void main(String argv[]) { try { Renderer.setRenderer(Renderer.VERTEX_ARRAY_RENDERER); Renderer.setLineStripRenderer(Renderer.QUAD_BASED_LINE_STRIP_RENDERER); AppGameContainer container = new AppGameContainer(new InkscapeTest()); container.setDisplayMode(800,600,false); container.start(); } catch (SlickException e) { e.printStackTrace(); } }
/** * Entry point to our test * * @param argv The arguments to pass into the test */ public static void main(String[] argv) { try { AppGameContainer container = new AppGameContainer(new TransparentColorTest()); container.setDisplayMode(800,600,false); container.start(); } catch (SlickException e) { e.printStackTrace(); } }
/** * Entry point to our test * * @param argv * The arguments passed to the test */ public static void main(String[] argv) { try { AppGameContainer container = new AppGameContainer( new GeomUtilTileTest()); container.setDisplayMode(800, 600, false); container.start(); } catch (SlickException e) { e.printStackTrace(); } }
/** * Entry point to our test * * @param argv The arguments passed to the test */ public static void main(String[] argv) { try { Renderer.setLineStripRenderer(Renderer.QUAD_BASED_LINE_STRIP_RENDERER); Renderer.getLineStripRenderer().setLineCaps(true); AppGameContainer container = new AppGameContainer(new LineRenderTest()); container.setDisplayMode(800,600,false); container.start(); } catch (SlickException e) { e.printStackTrace(); } }
/** * Initialise resources and the map data * * @param container the container the game is running in */ public void init(GameContainer container) throws SlickException { container.setShowFPS(false); try { dataMap = new DataMap("testdata/map.dat"); } catch (IOException e) { throw new SlickException("Failed to load map data", e); } builder = new NavMeshBuilder(); navMesh = builder.build(dataMap); System.out.println("Navmesh shapes: "+navMesh.getSpaceCount()); }
/** * @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int) */ public final void update(GameContainer container, int delta) throws SlickException { preUpdateState(container, delta); if (leaveTransition != null) { leaveTransition.update(this, container, delta); if (leaveTransition.isComplete()) { currentState.leave(container, this); GameState prevState = currentState; currentState = nextState; nextState = null; leaveTransition = null; currentState.enter(container, this); if (enterTransition != null) { enterTransition.init(currentState, prevState); } } else { return; } } if (enterTransition != null) { enterTransition.update(this, container, delta); if (enterTransition.isComplete()) { enterTransition = null; } else { return; } } currentState.update(container, this, delta); postUpdateState(container, delta); }