public void update(GameContainer container, int delta) throws SlickException { if (!paused) { ypos += delta * 0.002 * systemMove; if (ypos > 300) { ypos = -300; } if (ypos < -300) { ypos = 300; } for (int i = 0; i < emitters.size(); i++) { ((ConfigurableEmitter) emitters.get(i)).replayCheck(); } for (int i = 0; i < delta; i++) { system.update(1); } } Display.sync(100); }
/** * Browse for a particle image and set the value into both the emitter and text field * on successful completion */ private void browseForImage() { if (emitter != null) { int resp = chooser.showOpenDialog(this); if (resp == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); String path = file.getParentFile().getAbsolutePath(); String name = file.getName(); ConfigurableEmitter.setRelativePath(path); emitter.setImageName(name); imageName.setText(name); } } }
/** * 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()); } }
@Override public void init(GameContainer container, StateBasedGame game) throws SlickException { try { this.barks = Utils.loadParticleSystem("data/particles/drawing.xml"); this.drawingEffectEmitter = (ConfigurableEmitter)this.barks.getEmitter(0); this.segment = Utils.loadParticleSystem("data/particles/segment.xml"); } catch (IOException e) { e.printStackTrace(); } this.hud.init(container, game); this.drawingPositions = new Vec2[MAX_DRAWING_LENGTH]; for (int i = 0; i < this.drawingPositions.length; i++) this.drawingPositions[i] = new Vec2(); this.drawings = new LinkedList<Body>(); }
/** * 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#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics) */ public void render(GameContainer container, Graphics g) { ((ConfigurableEmitter) trail.getEmitter(0)).setPosition(rx+14,ry+35); trail.render(); image.draw((int) rx,(int) ry); g.translate(400, 300); fire.render(); }
public void mousePressed(int button, int x, int y) { super.mousePressed(button, x, y); for (int i=0;i<fire.getEmitterCount();i++) { ((ConfigurableEmitter) fire.getEmitter(i)).setPosition(x - 400, y - 300, true); } }
/** * @see org.newdawn.slick.tools.peditor.ControlPanel#linkEmitterToFields(org.newdawn.slick.particles.ConfigurableEmitter) */ protected void linkEmitterToFields(ConfigurableEmitter emitter) { link(emitter.spawnInterval, "spawnInterval"); link(emitter.spawnCount, "spawnCount"); link(emitter.initialSize, "initialSize"); link(emitter.initialLife, "initialLife"); link(emitter.speed, "speed"); link(emitter.growthFactor, "growth"); }
/** * @see org.newdawn.slick.tools.peditor.ControlPanel#linkEmitterToFields(org.newdawn.slick.particles.ConfigurableEmitter) */ protected void linkEmitterToFields(ConfigurableEmitter emitter) { this.emitter = emitter; // register the new emitter editor.setLinkedEmitter(emitter); valueMap.clear(); linkToEmitter("Alpha", emitter.alpha); linkToEmitter("Size", emitter.size); linkToEmitter("Velocity", emitter.velocity); linkToEmitter("ScaleY", emitter.scaleY); editor.setFirstProperty(); }
/** * Add an emitter to the particle system held here * * @param emitter * The emitter to add */ public void addEmitter(ConfigurableEmitter emitter) { emitters.add(emitter); if (system == null) { waiting.add(emitter); } else { system.addEmitter(emitter); } }
/** * @see javax.swing.DefaultListCellRenderer#getListCellRendererComponent(javax.swing.JList, java.lang.Object, int, boolean, boolean) */ public Component getListCellRendererComponent(JList list, final Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); final JCheckBox box = new JCheckBox(label.getText()); box.setBackground(label.getBackground()); box.setSelected(((ConfigurableEmitter) value).isEnabled()); checks.put(value, box); return box; }
/** * @see org.newdawn.slick.tools.peditor.ControlPanel#linkEmitterToFields(org.newdawn.slick.particles.ConfigurableEmitter) */ protected void linkEmitterToFields(ConfigurableEmitter emitter) { name.setText(emitter.name); String value = emitter.getImageName(); if (value != null) { value = value.substring(value.lastIndexOf(File.separatorChar)+1); imageName.setText(value); } link(emitter.gravityFactor, "gravity"); link(emitter.windFactor, "wind"); }
/** * Set the currently selected and edited particle emitter * * @param emitter The emitter that should be selected or null for none */ public void setCurrentEmitter(ConfigurableEmitter emitter) { this.selected = emitter; if (emitter == null) { emissionControls.setEnabled(false); settingsPanel.setEnabled(false); positionControls.setEnabled(false); colorPanel.setEnabled(false); limitPanel.setEnabled(false); whiskasPanel.setEnabled(false); } else { emissionControls.setEnabled(true); settingsPanel.setEnabled(true); positionControls.setEnabled(true); colorPanel.setEnabled(true); limitPanel.setEnabled(true); whiskasPanel.setEnabled(true); emissionControls.setTarget(emitter); settingsPanel.setTarget(emitter); positionControls.setTarget(emitter); settingsPanel.setTarget(emitter); colorPanel.setTarget(emitter); limitPanel.setTarget(emitter); whiskasPanel.setTarget(emitter); } }
/** * Set the emitter that is being controlled * * @param emitter The emitter that is configured by this panel */ public void setLinkedEmitter(ConfigurableEmitter emitter) { // set the title Window w = SwingUtilities.windowForComponent(this); if (w instanceof Frame) ((Frame) w).setTitle("Whiskas Gradient Editor (" + emitter.name + ")"); // clear all values properties.removeAllItems(); values.clear(); panel.setInterpolator(null); enableControls(); }
/** * @see org.newdawn.slick.tools.peditor.ControlPanel#linkEmitterToFields(org.newdawn.slick.particles.ConfigurableEmitter) */ protected void linkEmitterToFields(ConfigurableEmitter emitter) { link(emitter.xOffset, "x"); link(emitter.yOffset, "y"); link(emitter.spread, "spread"); link(emitter.angularOffset, "angularOffset"); link(emitter.initialDistance, "initialDistance"); }