v0.8.0: fixed save/load issues with pitfall traps and added vfx to them

This commit is contained in:
Evan Debenham 2020-01-03 20:38:49 -05:00
parent e7540fc8c3
commit 70c45d3709
4 changed files with 123 additions and 3 deletions

View File

@ -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 );

View File

@ -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 <http://www.gnu.org/licenses/>
*/
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;
}
}

View File

@ -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

View File

@ -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;
@ -227,6 +228,9 @@ public class GameScene extends PixelScene {
levelVisuals = Dungeon.level.addVisuals();
add(levelVisuals);
floorEmitters = new Group();
add(floorEmitters);
heaps = new Group();
add( heaps );
@ -815,6 +819,16 @@ public class GameScene extends PixelScene {
}
}
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;
}