From 70c45d370904f22ead79cdd1fe59f7f40a3534a1 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Fri, 3 Jan 2020 20:38:49 -0500 Subject: [PATCH] v0.8.0: fixed save/load issues with pitfall traps and added vfx to them --- .../effects/CellEmitter.java | 10 +++ .../effects/particles/PitfallParticle.java | 63 +++++++++++++++++++ .../levels/traps/PitfallTrap.java | 35 ++++++++++- .../scenes/GameScene.java | 18 +++++- 4 files changed, 123 insertions(+), 3 deletions(-) create mode 100644 core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/particles/PitfallParticle.java diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/CellEmitter.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/CellEmitter.java index 333f162aa..c3d0e4b91 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/CellEmitter.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/CellEmitter.java @@ -28,6 +28,16 @@ import com.watabou.utils.PointF; public class CellEmitter { + public static Emitter floor( int cell ) { + + PointF p = DungeonTilemap.tileToWorld( cell ); + + Emitter emitter = GameScene.floorEmitter(); + emitter.pos( p.x, p.y, DungeonTilemap.SIZE, DungeonTilemap.SIZE ); + + return emitter; + } + public static Emitter get( int cell ) { PointF p = DungeonTilemap.tileToWorld( cell ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/particles/PitfallParticle.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/particles/PitfallParticle.java new file mode 100644 index 000000000..6a85aeaeb --- /dev/null +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/particles/PitfallParticle.java @@ -0,0 +1,63 @@ +/* + * Pixel Dungeon + * Copyright (C) 2012-2015 Oleg Dolya + * + * Shattered Pixel Dungeon + * Copyright (C) 2014-2020 Evan Debenham + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see + */ + +package com.shatteredpixel.shatteredpixeldungeon.effects.particles; + +import com.watabou.noosa.particles.Emitter; +import com.watabou.noosa.particles.PixelParticle; +import com.watabou.utils.Random; + +public class PitfallParticle extends PixelParticle.Shrinking { + + public static final Emitter.Factory FACTORY4 = new Emitter.Factory() { + @Override + public void emit( Emitter emitter, int index, float x, float y ) { + ((PitfallParticle)emitter.recycle( PitfallParticle.class )).reset( x, y, 4 ); + } + }; + + public static final Emitter.Factory FACTORY8 = new Emitter.Factory() { + @Override + public void emit( Emitter emitter, int index, float x, float y ) { + ((PitfallParticle)emitter.recycle( PitfallParticle.class )).reset( x, y, 8 ); + } + }; + + public PitfallParticle(){ + super(); + + color( 0x000000 ); + angle = Random.Float( -30, 30 ); + + } + + public void reset( float x, float y, int size ) { + revive(); + + this.x = x; + this.y = y; + + left = lifespan = 1f; + + this.size = size; + } + +} diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/PitfallTrap.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/PitfallTrap.java index b53c05a3c..942048c42 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/PitfallTrap.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/PitfallTrap.java @@ -27,12 +27,15 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.FlavourBuff; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob; +import com.shatteredpixel.shatteredpixeldungeon.effects.CellEmitter; +import com.shatteredpixel.shatteredpixeldungeon.effects.particles.PitfallParticle; import com.shatteredpixel.shatteredpixeldungeon.items.Heap; import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.levels.features.Chasm; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; +import com.watabou.utils.Bundle; import com.watabou.utils.PathFinder; public class PitfallTrap extends Trap { @@ -50,11 +53,16 @@ public class PitfallTrap extends Trap { return; } - //TODO visuals DelayedPit p = Buff.affect(Dungeon.hero, DelayedPit.class, 1); p.depth = Dungeon.depth; p.pos = pos; + for (int i : PathFinder.NEIGHBOURS9){ + if (!Dungeon.level.solid[pos+i] || Dungeon.level.passable[pos+i]){ + CellEmitter.floor(pos+i).burst(PitfallParticle.FACTORY4, 8); + } + } + if (pos == Dungeon.hero.pos){ GLog.n(Messages.get(this, "triggered_hero")); } else if (Dungeon.level.heroFOV[pos]){ @@ -72,8 +80,15 @@ public class PitfallTrap extends Trap { public boolean act() { if (depth == Dungeon.depth) { for (int i : PathFinder.NEIGHBOURS9) { + int cell = pos + i; + if (Dungeon.level.solid[pos+i] && !Dungeon.level.passable[pos+i]){ + continue; + } + + CellEmitter.floor(pos+i).burst(PitfallParticle.FACTORY8, 12); + Heap heap = Dungeon.level.heaps.get(cell); if (heap != null) { @@ -101,6 +116,24 @@ public class PitfallTrap extends Trap { detach(); return true; } + + private static final String POS = "pos"; + private static final String DEPTH = "depth"; + + @Override + public void storeInBundle(Bundle bundle) { + super.storeInBundle(bundle); + bundle.put(POS, pos); + bundle.put(DEPTH, depth); + } + + @Override + public void restoreFromBundle(Bundle bundle) { + super.restoreFromBundle(bundle); + pos = bundle.getInt(POS); + depth = bundle.getInt(DEPTH); + } + } //TODO these used to become chasms when disarmed, but the functionality was problematic diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java index 535fa2fd1..4f2e16140 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java @@ -147,6 +147,7 @@ public class GameScene extends PixelScene { private Group traps; private Group heaps; private Group mobs; + private Group floorEmitters; private Group emitters; private Group effects; private Group gases; @@ -226,14 +227,17 @@ public class GameScene extends PixelScene { levelVisuals = Dungeon.level.addVisuals(); add(levelVisuals); - + + floorEmitters = new Group(); + add(floorEmitters); + heaps = new Group(); add( heaps ); for ( Heap heap : Dungeon.level.heaps.valueList() ) { addHeapSprite( heap ); } - + emitters = new Group(); effects = new Group(); healthIndicators = new Group(); @@ -814,6 +818,16 @@ public class GameScene extends PixelScene { return null; } } + + public static Emitter floorEmitter() { + if (scene != null) { + Emitter emitter = (Emitter)scene.floorEmitters.recycle( Emitter.class ); + emitter.revive(); + return emitter; + } else { + return null; + } + } public static FloatingText status() { return scene != null ? (FloatingText)scene.statuses.recycle( FloatingText.class ) : null;