void openEffect() { FileDialog dialog = new FileDialog(editor, "Open Effect", FileDialog.LOAD); if (lastDir != null) dialog.setDirectory(lastDir); dialog.setVisible(true); final String file = dialog.getFile(); final String dir = dialog.getDirectory(); if (dir == null || file == null || file.trim().length() == 0) return; lastDir = dir; ParticleEffect effect = new ParticleEffect(); try { effect.loadEmitters(Gdx.files.absolute(new File(dir, file).getAbsolutePath())); editor.effect = effect; emitterTableModel.getDataVector().removeAllElements(); editor.particleData.clear(); } catch (Exception ex) { System.out.println("Error loading effect: " + new File(dir, file).getAbsolutePath()); ex.printStackTrace(); JOptionPane.showMessageDialog(editor, "Error opening effect."); return; } for (ParticleEmitter emitter : effect.getEmitters()) { emitter.setPosition( editor.worldCamera.viewportWidth / 2, editor.worldCamera.viewportHeight / 2); emitterTableModel.addRow(new Object[] {emitter.getName(), true}); } editIndex = 0; emitterTable.getSelectionModel().setSelectionInterval(editIndex, editIndex); editor.reloadRows(); }
@Override public void update(float delta) { if (!active) return; timer += delta; float a = timer / duration; if (a <= 1) { position.x = Interpolation.linear.apply(start.x, target.x, a); position.y = Interpolation.linear.apply(start.y, target.y, a) + ((1 + MathUtils.sinDeg(a * 180)) * 2); light.setDistance(1.5f + MathUtils.random(-.25f, .25f)); } else { effect.allowCompletion(); for (ParticleEmitter emitter : effect.getEmitters()) { emitter.setContinuous(false); } light.setDistance(light.getDistance() * 0.95f); } light.setPosition(position); effect.setPosition(position.x, position.y); effect.update(delta); if (effect.isComplete()) { Gdx.app.log("", "reset"); FlamingRock.pool.free(this); } }
/** * When player dies this should be called. Stops the players sound, resets position of the player * and creates an explosion particle effect. * * @param spawnPoint The Spawnpoint to which the player will be transfered to */ public void die(Vector2 spawnPoint) { crashed = true; explosion.setPosition(getPosition().x, getPosition().y); shootSound.stop(); exhaustSound.stop(); explosion.start(); explosionSound.play(); setPosition(spawnPoint.x, spawnPoint.y + 1); }
@Override public void tick(float delta) { super.tick(delta); body.applyForceToCenter(movement, true); if (gasPressed) { if (!exhaustSoundPlaying && !isCrashed()) { exhaustSound.play(); exhaustSoundPlaying = true; } accelerate(); } if (leftPressed) { body.applyAngularImpulse( isReversedSteering ? MathUtils.radDeg * -MAX_TURN_DEG : MathUtils.radDeg * MAX_TURN_DEG, true); } if (rightPressed) { body.applyAngularImpulse( isReversedSteering ? MathUtils.radDeg * MAX_TURN_DEG : MathUtils.radDeg * -MAX_TURN_DEG, true); } if (!gasPressed) { exhaustSound.stop(); exhaustSoundPlaying = false; } if (Gdx.app.getType() == ApplicationType.Android) { handleTouchPadInput(); touchPadStage.act(delta); } sprite.setPosition( getPosition().x - sprite.getWidth() / 2, getPosition().y - sprite.getHeight() / 2); sprite.setRotation(body.getAngle() * MathUtils.radiansToDegrees); // update exhaust exhaust.setPosition(getPosition().x, getPosition().y); exhaust.update(delta); explosion.update(delta); for (Bullet bullet : bullets) { bullet.tick(delta); } if (crashed) { timePassed += delta; ableToShoot = false; playExplosion(); } }
public void init(float x, float y, float tx, float ty) { position.set(x, y); start.set(position); target.set(tx, ty); effect.reset(); duration = target.dst(position) / 6; active = true; light.setActive(true); light.setPosition(x, y); for (ParticleEmitter emitter : effect.getEmitters()) { emitter.setContinuous(true); } }
@Override public void render(SpriteBatch batch) { // draw bullets for (Bullet bullet : bullets) { bullet.render(batch); } if (!crashed) { exhaust.draw(batch); sprite.draw(batch); } explosion.draw(batch); if (Gdx.app.getType() == ApplicationType.Android) { touchPadStage.draw(); } }
public ParticleEmitter newEmitter(String name, boolean select) { final ParticleEmitter emitter = new ParticleEmitter(); emitter.getDuration().setLow(1000); emitter.getEmission().setHigh(50); emitter.getLife().setHigh(500); emitter.getScale().setHigh(32, 32); emitter.getTint().setColors(new float[] {1, 0.12156863f, 0.047058824f}); emitter.getTransparency().setHigh(1); emitter.setFlip(false, true); emitter.setMaxParticleCount(25); emitter.setImagePath("particle.png"); addEmitter(name, select, emitter); return emitter; }
private void addEmitter(String name, boolean select, final ParticleEmitter emitter) { Array<ParticleEmitter> emitters = editor.effect.getEmitters(); if (emitters.size == 0) emitter.setPosition( editor.worldCamera.viewportWidth / 2, editor.worldCamera.viewportHeight / 2); else { ParticleEmitter p = emitters.get(0); emitter.setPosition(p.getX(), p.getY()); } emitters.add(emitter); emitterTableModel.addRow(new Object[] {name, true}); if (select) { editor.reloadRows(); int row = emitterTableModel.getRowCount() - 1; emitterTable.getSelectionModel().setSelectionInterval(row, row); } }
void saveEffect() { FileDialog dialog = new FileDialog(editor, "Save Effect", FileDialog.SAVE); if (lastDir != null) dialog.setDirectory(lastDir); dialog.setVisible(true); String file = dialog.getFile(); String dir = dialog.getDirectory(); if (dir == null || file == null || file.trim().length() == 0) return; lastDir = dir; int index = 0; for (ParticleEmitter emitter : editor.effect.getEmitters()) emitter.setName((String) emitterTableModel.getValueAt(index++, 0)); try { editor.effect.save(new File(dir, file)); } catch (Exception ex) { System.out.println("Error saving effect: " + new File(dir, file).getAbsolutePath()); ex.printStackTrace(); JOptionPane.showMessageDialog(editor, "Error saving effect."); } }
private void playExplosion() { if (timePassed < RESPAWN_TIME) { setMovement(0, 0); } else { explosion.allowCompletion(); crashed = false; timePassed = 0.0f; ableToShoot = true; } }
private void createGunSmoke(float angle) { ParticleEmitter emitter = EffectFactory.getInstance().addEffect(origin, EffectFactory.EFFECT_TYPE.GUNSMOKE); emitter.getAngle().setHigh(angle + -20, angle + 20); emitter.getAngle().setLow(angle + -20, angle + 20); emitter.getVelocity().setLow(1, 1); emitter.getVelocity().setHigh(1, 1); emitter.getScale().setHigh(emitter.getScale().getHighMin(), emitter.getScale().getHighMax()); emitter.getScale().setLow(emitter.getScale().getLowMin(), emitter.getScale().getLowMax()); }
private void handleTouchPadInput() { if (movementTouchPad.isTouched()) { body.applyAngularImpulse( MathUtils.radDeg * -MAX_TURN_DEG * (movementTouchPad.getKnobPercentX() + movementTouchPad.getKnobPercentY()), true); } if (gasTouchPad.isTouched()) { gasPressed = true; exhaust.start(); } if (!gasTouchPad.isTouched()) { gasPressed = false; movement.set(0, 0); exhaust.allowCompletion(); } }
private void loadImage(ParticleEmitter emitter) { final String imagePath = emitter.getImagePath(); String imageName = new File(imagePath.replace('\\', '/')).getName(); try { FileHandle file; if (imagePath.equals("particle.png")) file = Gdx.files.classpath(imagePath); else file = Gdx.files.absolute(imagePath); emitter.setSprite(new Sprite(new Texture(file))); } catch (GdxRuntimeException ex) { ex.printStackTrace(); EventQueue.invokeLater( new Runnable() { public void run() { JOptionPane.showMessageDialog( ParticleEditor.this, "Error loading image:\n" + imagePath); } }); emitter.setImagePath(null); } }
public ImageIcon getIcon(ParticleEmitter emitter) { ParticleData data = particleData.get(emitter); if (data == null) particleData.put(emitter, data = new ParticleData()); String imagePath = emitter.getImagePath(); if (data.icon == null && imagePath != null) { try { URL url; File file = new File(imagePath); if (file.exists()) url = file.toURI().toURL(); else { url = ParticleEditor.class.getResource(imagePath); if (url == null) return null; } data.icon = new ImageIcon(url); } catch (MalformedURLException ex) { ex.printStackTrace(); } } return data.icon; }
private void setExhaustRotation() { float angle = sprite.getRotation(); exhaust.getAngle().setLow(angle + 270); exhaust.getAngle().setHighMin(angle + 270 - 90); exhaust.getAngle().setHighMax(angle + 270 + 90); }
public void draw(ParticleEmitter emitter, TextureAtlas.AtlasRegion tex, boolean additive) { maybeChangeAdditive(additive); emitter.draw(myDrawer.getBatch(emitter.getSprite().getTexture(), tex)); }
public ParticleEmitter newExampleEmitter(String name, boolean select) { final ParticleEmitter emitter = new ParticleEmitter(); emitter.getDuration().setLow(3000); emitter.getEmission().setHigh(250); emitter.getLife().setHigh(500, 1000); emitter.getLife().setTimeline(new float[] {0, 0.66f, 1}); emitter.getLife().setScaling(new float[] {1, 1, 0.3f}); emitter.getScale().setHigh(32, 32); emitter.getRotation().setLow(1, 360); emitter.getRotation().setHigh(180, 180); emitter.getRotation().setTimeline(new float[] {0, 1}); emitter.getRotation().setScaling(new float[] {0, 1}); emitter.getRotation().setRelative(true); emitter.getAngle().setHigh(45, 135); emitter.getAngle().setLow(90); emitter.getAngle().setTimeline(new float[] {0, 0.5f, 1}); emitter.getAngle().setScaling(new float[] {1, 0, 0}); emitter.getAngle().setActive(true); emitter.getVelocity().setHigh(30, 300); emitter.getVelocity().setActive(true); emitter.getTint().setColors(new float[] {1, 0.12156863f, 0.047058824f}); emitter.getTransparency().setHigh(1, 1); emitter.getTransparency().setTimeline(new float[] {0, 0.2f, 0.8f, 1}); emitter.getTransparency().setScaling(new float[] {0, 1, 0.75f, 0}); emitter.setFlip(false, true); emitter.setMaxParticleCount(200); emitter.setImagePath("particle.png"); addEmitter(name, select, emitter); return emitter; }
public void setEnabled(ParticleEmitter emitter, boolean enabled) { ParticleData data = particleData.get(emitter); if (data == null) particleData.put(emitter, data = new ParticleData()); data.enabled = enabled; emitter.reset(); }
public void render() { int viewWidth = Gdx.graphics.getWidth(); int viewHeight = Gdx.graphics.getHeight(); float delta = Gdx.graphics.getDeltaTime(); Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); if ((pixelsPerMeter.getValue() != pixelsPerMeterPrev) || (zoomLevel.getValue() != zoomLevelPrev)) { if (pixelsPerMeter.getValue() <= 0) { pixelsPerMeter.setValue(1); } worldCamera.setToOrtho( false, viewWidth / pixelsPerMeter.getValue(), viewHeight / pixelsPerMeter.getValue()); worldCamera.zoom = zoomLevel.getValue(); worldCamera.update(); effect.setPosition(worldCamera.viewportWidth / 2, worldCamera.viewportHeight / 2); zoomLevelPrev = zoomLevel.getValue(); pixelsPerMeterPrev = pixelsPerMeter.getValue(); } spriteBatch.setProjectionMatrix(worldCamera.combined); spriteBatch.begin(); spriteBatch.enableBlending(); spriteBatch.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); if (bgImage != null) { bgImage.setPosition( viewWidth / 2 - bgImage.getWidth() / 2, viewHeight / 2 - bgImage.getHeight() / 2); bgImage.draw(spriteBatch); } activeCount = 0; boolean complete = true; for (ParticleEmitter emitter : effect.getEmitters()) { if (emitter.getSprite() == null && emitter.getImagePath() != null) loadImage(emitter); boolean enabled = isEnabled(emitter); if (enabled) { if (emitter.getSprite() != null) emitter.draw(spriteBatch, delta); activeCount += emitter.getActiveCount(); if (!emitter.isComplete()) complete = false; } } if (complete) effect.start(); maxActive = Math.max(maxActive, activeCount); maxActiveTimer += delta; if (maxActiveTimer > 3) { maxActiveTimer = 0; lastMaxActive = maxActive; maxActive = 0; } if (mouseDown) { // gl.drawLine(mouseX - 6, mouseY, mouseX + 5, mouseY); // gl.drawLine(mouseX, mouseY - 5, mouseX, mouseY + 6); } spriteBatch.setProjectionMatrix(textCamera.combined); font.draw(spriteBatch, "FPS: " + Gdx.graphics.getFramesPerSecond(), 5, 15); font.draw(spriteBatch, "Count: " + activeCount, 5, 35); font.draw(spriteBatch, "Max: " + lastMaxActive, 5, 55); font.draw(spriteBatch, (int) (getEmitter().getPercentComplete() * 100) + "%", 5, 75); spriteBatch.end(); // gl.drawLine((int)(viewWidth * getCurrentParticles().getPercentComplete()), viewHeight - 1, // viewWidth, viewHeight - // 1); }