/** * @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 += ","; } } }
/** * Clone the selected emitter */ public void cloneEmitter() { if (selected == null) { return; } try { ByteArrayOutputStream bout = new ByteArrayOutputStream(); ParticleIO.saveEmitter(bout, selected); ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); ConfigurableEmitter emitter = ParticleIO.loadEmitter(bin); emitter.name = emitter.name + "_clone"; addEmitter(emitter); emitters.setSelected(emitter); } catch (IOException e) { Log.error(e); JOptionPane.showMessageDialog(this, e.getMessage()); } }
/** * Export an emitter XML file */ public void exportEmitter() { if (selected == null) { return; } chooser.setDialogTitle("Save"); int resp = chooser.showSaveDialog(this); if (resp == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); if (!file.getName().endsWith(".xml")) { file = new File(file.getAbsolutePath()+".xml"); } try { ParticleIO.saveEmitter(file, selected); } catch (IOException e) { Log.error(e); JOptionPane.showMessageDialog(this, e.getMessage()); } } }
/** * Save a complete particle system XML description */ public void saveSystem() { int resp = chooser.showSaveDialog(this); if (resp == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); if (!file.getName().endsWith(".xml")) { file = new File(file.getAbsolutePath()+".xml"); } try { ParticleIO.saveConfiguredSystem(file, game.getSystem()); } catch (IOException e) { Log.error(e); JOptionPane.showMessageDialog(this, e.getMessage()); } } }
/** * load ressources (the particle system) and create our duplicate emitters * and place them nicely on the screen * @param container The surrounding game container */ public void init(GameContainer container) throws SlickException { this.container = container; try { // load the particle system containing our explosion emitter explosionSystem = ParticleIO.loadConfiguredSystem("testdata/endlessexplosion.xml"); // get the emitter, it's the first (and only one) in this particle system explosionEmitter = (ConfigurableEmitter) explosionSystem.getEmitter(0); // set the original emitter in the middle of the screen at the top explosionEmitter.setPosition(400,100); // create 5 duplicate emitters for (int i = 0; i < 5; i++) { // a single duplicate of the first emitter is created here ConfigurableEmitter newOne = explosionEmitter.duplicate(); // we might get null as a result - protect against that if (newOne == null) throw new SlickException("Failed to duplicate explosionEmitter"); // give the new emitter a new unique name newOne.name = newOne.name + "_" + i; // place it somewhere on a row below the original emitter newOne.setPosition((i+1)* (800/6), 400); // and add it to the original particle system to get the new emitter updated and rendered explosionSystem.addEmitter(newOne); } } catch (IOException e) { throw new SlickException("Failed to load particle systems", e); } }
/** * @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(); }
public AnimSpace(){ try { smoke = ParticleIO.loadConfiguredSystem("resources/space.xml"); } catch (IOException e) { e.printStackTrace(); } v.x = Window.WIDTH -100; v.y = Window.HEIGHT/2; smoke.setPosition(v.x, v.y); }
/** * Import an emitter XML file */ public void importEmitter() { chooser.setDialogTitle("Open"); int resp = chooser.showOpenDialog(this); if (resp == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); File path = file.getParentFile(); try { final ConfigurableEmitter emitter = ParticleIO.loadEmitter(file); if (emitter.getImageName() != null) { File possible = new File(path, emitter.getImageName()); if (possible.exists()) { emitter.setImageName(possible.getAbsolutePath()); } else { chooser.setDialogTitle("Locate the image: "+emitter.getImageName()); resp = chooser.showOpenDialog(this); FileFilter filter = new FileFilter() { public boolean accept(File f) { if (f.isDirectory()) { return true; } return (f.getName().equals(emitter.getImageName())); } public String getDescription() { return emitter.getImageName(); } }; chooser.addChoosableFileFilter(filter); if (resp == JFileChooser.APPROVE_OPTION) { File image = chooser.getSelectedFile(); emitter.setImageName(image.getAbsolutePath()); path = image.getParentFile(); } chooser.resetChoosableFileFilters(); chooser.addChoosableFileFilter(xmlFileFilter); } } addEmitter(emitter); emitters.setSelected(emitter); } catch (IOException e) { Log.error(e); JOptionPane.showMessageDialog(this, e.getMessage()); } } }
/** * Load a complete particle system XML description */ public void loadSystem() { chooser.setDialogTitle("Open"); int resp = chooser.showOpenDialog(this); if (resp == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); File path = file.getParentFile(); try { ParticleSystem system = ParticleIO.loadConfiguredSystem(file); game.setSystem(system); emitters.clear(); for (int i=0;i<system.getEmitterCount();i++) { final ConfigurableEmitter emitter = (ConfigurableEmitter) system.getEmitter(i); if (emitter.getImageName() != null) { File possible = new File(path, emitter.getImageName()); if (possible.exists()) { emitter.setImageName(possible.getAbsolutePath()); } else { chooser.setDialogTitle("Locate the image: "+emitter.getImageName()); FileFilter filter = new FileFilter() { public boolean accept(File f) { if (f.isDirectory()) { return true; } return (f.getName().equals(emitter.getImageName())); } public String getDescription() { return emitter.getImageName(); } }; chooser.addChoosableFileFilter(filter); resp = chooser.showOpenDialog(this); if (resp == JFileChooser.APPROVE_OPTION) { File image = chooser.getSelectedFile(); emitter.setImageName(image.getAbsolutePath()); path = image.getParentFile(); } chooser.setDialogTitle("Open"); chooser.resetChoosableFileFilters(); chooser.addChoosableFileFilter(xmlFileFilter); } } emitters.add(emitter); } additive.setSelected(system.getBlendingMode() == ParticleSystem.BLEND_ADDITIVE); pointsEnabled.setSelected(system.usePoints()); emitters.setSelected(0); } catch (IOException e) { Log.error(e); JOptionPane.showMessageDialog(this, e.getMessage()); } } }
@Override public void init(GameContainer arg0, StateBasedGame arg1) throws SlickException { player = new Player(); buildings = new ArrayList<>(); goons = new ArrayList<>(); bullets = new ArrayList<>(); playerImage = new Image("res/player.png"); playerImage.setFilter(Image.FILTER_NEAREST); playerJump = new Image("res/playerjump.png"); playerJump.setFilter(Image.FILTER_NEAREST); cannonImage = new Image("res/cannon.png"); cannonImage.setFilter(Image.FILTER_LINEAR); cannonImage.setCenterOfRotation(Player.CANNON_CENTER_X, Player.CANNON_CENTER_Y); SpriteSheet playerSS = new SpriteSheet("res/player_run.png", 60, 75); playerRunRight = new Animation(playerSS, RUN_ANIMATION_SPEED); playerRunLeft = new Animation(); int ssw = playerSS.getHorizontalCount(), ssh = playerSS.getVerticalCount(); for (int y = 0; y < ssh; y++) { for (int x = 0; x < ssw; x++) { playerRunLeft.addFrame(playerSS.getSprite(x, y).getFlippedCopy(true, false), RUN_ANIMATION_SPEED); } } bulletAnim = new Animation(new SpriteSheet("res/bullet.png", 30, 30), BULLET_ANIMATION_SPEED); buildingTexture = new Image("res/building.png"); buildingLastRow = buildingTexture.getSubImage(0, buildingTexture.getHeight() - 1, buildingTexture.getWidth(), 1); buildingTexture.setFilter(Image.FILTER_NEAREST); buildingLastRow.setFilter(Image.FILTER_NEAREST); graffitiImages = new Image[NUM_GRAFFITI * 2]; for (int i = 0; i < NUM_GRAFFITI; i++) { graffitiImages[i] = new Image("res/graffiti" + i + ".png"); graffitiImages[i + NUM_GRAFFITI] = graffitiImages[i].getFlippedCopy(true, false); } graffiti = new ArrayList<>(); mainTheme = new Music("res/main.ogg"); try { partsys = ParticleIO.loadConfiguredSystem("res/particle.xml"); } catch (IOException e) { e.printStackTrace(); } fireExplosion = (ConfigurableEmitter)partsys.getEmitter(0); blueExplosion = (ConfigurableEmitter)partsys.getEmitter(1); fireExplosion.setEnabled(false); blueExplosion.setEnabled(false); fireCannon = new Sound("res/firecannon.ogg"); highExplosion = new Sound("res/highexplosion.ogg"); softExplosion = new Sound("res/softexplosion.ogg"); hurtSound = new Sound("res/hurt.ogg"); basicGoon = new Image("res/plasticbag.png"); strongGoon = new Image("res/trashbag.png"); flyingGoon = new Animation(new SpriteSheet("res/tshirt.png", 50, 50), 200); background = new Image("res/sunset.png"); background.setFilter(Image.FILTER_NEAREST); camx = 0; camy = 0; camvx = 0; }
/** * Carrega um sistema de part�culas. * @param path Caminho do arquivo XML do sistema de part�culas. * @return Sistema de part�culas carregado. * @throws IOException */ public static ParticleSystem loadParticleSystem(String path) throws IOException { ParticleSystem system = ParticleIO.loadConfiguredSystem(path); system.setDefaultImageName("data/particles/particle.tga"); return system; }