diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/effects/Enchanting.java b/src/com/shatteredpixel/shatteredpixeldungeon/effects/Enchanting.java
new file mode 100644
index 000000000..795125d28
--- /dev/null
+++ b/src/com/shatteredpixel/shatteredpixeldungeon/effects/Enchanting.java
@@ -0,0 +1,110 @@
+/*
+ * Pixel Dungeon
+ * Copyright (C) 2012-2015 Oleg Dolya
+ *
+ * Shattered Pixel Dungeon
+ * Copyright (C) 2014-2015 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;
+
+import com.watabou.noosa.Game;
+import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
+import com.shatteredpixel.shatteredpixeldungeon.items.Item;
+import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
+
+public class Enchanting extends ItemSprite {
+ private static final int SIZE = 16;
+
+ private enum Phase {
+ FADE_IN, STATIC, FADE_OUT
+ }
+
+ private static final float FADE_IN_TIME = 0.2f;
+ private static final float STATIC_TIME = 1.0f;
+ private static final float FADE_OUT_TIME = 0.4f;
+
+ private static final float ALPHA = 0.6f;
+
+ private int color;
+
+ private Char target;
+
+ private Phase phase;
+ private float duration;
+ private float passed;
+
+ public Enchanting( Item item ) {
+ super( item.image(), null );
+ originToCenter();
+
+ color = item.glowing().color;
+
+ phase = Phase.FADE_IN;
+ duration = FADE_IN_TIME;
+ passed = 0;
+ }
+
+ @Override
+ public void update() {
+ super.update();
+
+ x = target.sprite.center().x - SIZE / 2;
+ y = target.sprite.y - SIZE;
+
+ switch (phase) {
+ case FADE_IN:
+ alpha( passed / duration * ALPHA );
+ scale.set( passed / duration );
+ break;
+ case STATIC:
+ tint( color, passed / duration * 0.8f );
+ break;
+ case FADE_OUT:
+ alpha( (1 - passed / duration) * ALPHA );
+ scale.set( 1 + passed / duration );
+ break;
+ }
+
+ if ((passed += Game.elapsed) > duration) {
+ switch (phase) {
+ case FADE_IN:
+ phase = Phase.STATIC;
+ duration = STATIC_TIME;
+ break;
+ case STATIC:
+ phase = Phase.FADE_OUT;
+ duration = FADE_OUT_TIME;
+ break;
+ case FADE_OUT:
+ kill();
+ break;
+ }
+
+ passed = 0;
+ }
+ }
+
+ public static void show( Char ch, Item item ) {
+
+ if (!ch.sprite.visible) {
+ return;
+ }
+
+ Enchanting sprite = new Enchanting( item );
+ sprite.target = ch;
+ ch.sprite.parent.add( sprite );
+ }
+}
\ No newline at end of file
diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/effects/Flare.java b/src/com/shatteredpixel/shatteredpixeldungeon/effects/Flare.java
index fec565a51..db5bea234 100644
--- a/src/com/shatteredpixel/shatteredpixeldungeon/effects/Flare.java
+++ b/src/com/shatteredpixel/shatteredpixeldungeon/effects/Flare.java
@@ -29,13 +29,14 @@ import javax.microedition.khronos.opengles.GL10;
import android.annotation.SuppressLint;
import android.opengl.GLES20;
-import android.util.FloatMath;
import com.watabou.gltextures.Gradient;
import com.watabou.gltextures.SmartTexture;
import com.watabou.noosa.Game;
+import com.watabou.noosa.Group;
import com.watabou.noosa.NoosaScript;
import com.watabou.noosa.Visual;
+import com.watabou.utils.PointF;
public class Flare extends Visual {
@@ -120,7 +121,16 @@ public class Flare extends Visual {
return this;
}
-
+
+ public Flare show( Group parent, PointF pos, float duration ) {
+ point( pos );
+ parent.add( this );
+
+ lifespan = this.duration = duration;
+
+ return this;
+ }
+
@Override
public void update() {
super.update();
diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/effects/MagicMissile.java b/src/com/shatteredpixel/shatteredpixeldungeon/effects/MagicMissile.java
index 6919b37c7..6ba41c8fa 100644
--- a/src/com/shatteredpixel/shatteredpixeldungeon/effects/MagicMissile.java
+++ b/src/com/shatteredpixel/shatteredpixeldungeon/effects/MagicMissile.java
@@ -48,6 +48,10 @@ public class MagicMissile extends Emitter {
private float time;
public void reset( int from, int to, Callback callback ) {
+ reset( from, to, SPEED, callback );
+ }
+
+ public void reset( int from, int to, float velocity, Callback callback ) {
this.callback = callback;
revive();
@@ -61,10 +65,10 @@ public class MagicMissile extends Emitter {
height = 0;
PointF d = PointF.diff( pt, pf );
- PointF speed = new PointF( d ).normalize().scale( SPEED );
+ PointF speed = new PointF( d ).normalize().scale( velocity );
sx = speed.x;
sy = speed.y;
- time = d.length() / SPEED;
+ time = d.length() / velocity;
}
public void size( float size ) {
@@ -137,7 +141,7 @@ public class MagicMissile extends Emitter {
public static void force( Group group, int from, int to, Callback callback ) {
MagicMissile missile = ((MagicMissile)group.recycle( MagicMissile.class ));
missile.reset( from, to, callback );
- missile.size( 4 );
+ missile.size( 0 );
missile.pour( ForceParticle.FACTORY, 0.01f );
}
@@ -330,42 +334,29 @@ public class MagicMissile extends Emitter {
acc.set( (emitter.x - x) * 10, (emitter.y - y) * 10 );
}
}
-
- public static class ForceParticle extends PixelParticle {
-
+
+ public static class ForceParticle extends PixelParticle.Shrinking {
+
public static final Emitter.Factory FACTORY = new Factory() {
@Override
public void emit( Emitter emitter, int index, float x, float y ) {
- ((ForceParticle)emitter.recycle( ForceParticle.class )).reset( x, y );
+ ((ForceParticle)emitter.recycle( ForceParticle.class )).reset( index, x, y );
}
};
-
- public ForceParticle() {
- super();
-
- lifespan = 0.6f;
- size( 4 );
+ public void reset( int index, float x, float y ) {
+ super.reset( x, y, 0xFFFFFF, 8, 0.5f );
+
+ speed.polar( PointF.PI2 / 8 * index, 12 );
+ this.x -= speed.x * lifespan;
+ this.y -= speed.y * lifespan;
}
-
- public void reset( float x, float y ) {
- revive();
-
- this.x = x;
- this.y = y;
-
- left = lifespan;
-
- acc.set( 0 );
- speed.set( Random.Float( -40, +40 ), Random.Float( -40, +40 ) );
- }
-
+
@Override
public void update() {
super.update();
-
- am = (left / lifespan) / 2;
- acc.set( -speed.x * 10, -speed.y * 10 );
+
+ am = (1 - left / lifespan) / 2;
}
}
diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/effects/Swap.java b/src/com/shatteredpixel/shatteredpixeldungeon/effects/Swap.java
new file mode 100644
index 000000000..5e526866d
--- /dev/null
+++ b/src/com/shatteredpixel/shatteredpixeldungeon/effects/Swap.java
@@ -0,0 +1,140 @@
+/*
+ * Pixel Dungeon
+ * Copyright (C) 2012-2015 Oleg Dolya
+ *
+ * Shattered Pixel Dungeon
+ * Copyright (C) 2014-2015 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;
+
+import com.watabou.noosa.Game;
+import com.watabou.noosa.Visual;
+import com.watabou.noosa.audio.Sample;
+import com.shatteredpixel.shatteredpixeldungeon.Assets;
+import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
+import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
+import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
+import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
+import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
+import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
+import com.watabou.utils.PointF;
+
+public class Swap extends Actor {
+
+ private Char ch1;
+ private Char ch2;
+
+ private Effect eff1;
+ private Effect eff2;
+
+ private float delay;
+
+ public Swap( Char ch1, Char ch2 ) {
+
+ this.ch1 = ch1;
+ this.ch2 = ch2;
+
+ delay = Level.distance( ch1.pos, ch2.pos ) * 0.1f;
+
+ eff1 = new Effect( ch1.sprite, ch1.pos, ch2.pos );
+ eff2 = new Effect( ch2.sprite, ch2.pos, ch1.pos );
+ Sample.INSTANCE.play( Assets.SND_TELEPORT );
+ }
+
+ @Override
+ protected boolean act() {
+ return false;
+ }
+
+ private void finish( Effect eff ) {
+ if (eff == eff1) {
+ eff1 = null;
+ }
+ if (eff == eff2) {
+ eff2 = null;
+ }
+
+ if (eff1 == null && eff2 == null) {
+ Actor.remove( this );
+ next();
+
+ int pos = ch1.pos;
+ ch1.pos = ch2.pos;
+ ch2.pos = pos;
+
+ if (!ch1.flying) {
+ if (ch1 instanceof Mob) {
+ Dungeon.level.mobPress( (Mob)ch1 );
+ } else {
+ Dungeon.level.press( ch1.pos, ch1 );
+ }
+ }
+ if (!ch2.flying) {
+ if (ch2 instanceof Mob) {
+ Dungeon.level.mobPress( (Mob)ch2 );
+ } else {
+ Dungeon.level.press( ch2.pos, ch2 );
+ }
+ }
+
+ if (ch1 == Dungeon.hero || ch2 == Dungeon.hero) {
+ Dungeon.observe();
+ }
+ }
+ }
+
+ private class Effect extends Visual {
+
+ private CharSprite sprite;
+ private PointF end;
+ private float passed;
+
+ public Effect( CharSprite sprite, int from, int to ) {
+ super( 0, 0, 0, 0 );
+
+ this.sprite = sprite;
+
+ point( sprite.worldToCamera( from ) );
+ end = sprite.worldToCamera( to );
+
+ speed.set( 2 * (end.x - x) / delay, 2 * (end.y - y) / delay );
+ acc.set( -speed.x / delay, -speed.y / delay );
+
+ passed = 0;
+
+ sprite.parent.add( this );
+ }
+
+ @Override
+ public void update() {
+ super.update();
+
+ if ((passed += Game.elapsed) < delay) {
+ sprite.x = x;
+ sprite.y = y;
+
+ } else {
+
+ sprite.point( end );
+
+ killAndErase();
+ finish( this );
+
+ }
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/effects/particles/SacrificialParticle.java b/src/com/shatteredpixel/shatteredpixeldungeon/effects/particles/SacrificialParticle.java
new file mode 100644
index 000000000..c693e2884
--- /dev/null
+++ b/src/com/shatteredpixel/shatteredpixeldungeon/effects/particles/SacrificialParticle.java
@@ -0,0 +1,67 @@
+/*
+ * Pixel Dungeon
+ * Copyright (C) 2012-2015 Oleg Dolya
+ *
+ * Shattered Pixel Dungeon
+ * Copyright (C) 2014-2015 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.noosa.particles.Emitter.Factory;
+
+public class SacrificialParticle extends PixelParticle.Shrinking {
+
+ public static final Emitter.Factory FACTORY = new Factory() {
+ @Override
+ public void emit( Emitter emitter, int index, float x, float y ) {
+ ((SacrificialParticle)emitter.recycle( SacrificialParticle.class )).reset( x, y );
+ }
+ @Override
+ public boolean lightMode() {
+ return true;
+ };
+ };
+
+ public SacrificialParticle() {
+ super();
+
+ color( 0x4488EE );
+ lifespan = 0.6f;
+
+ acc.set( 0, -100 );
+ }
+
+ public void reset( float x, float y ) {
+ revive();
+
+ this.x = x;
+ this.y = y - 4;
+
+ left = lifespan;
+
+ size = 4;
+ speed.set( 0 );
+ }
+
+ @Override
+ public void update() {
+ super.update();
+ float p = left / lifespan;
+ am = p > 0.75f ? (1 - p) * 4 : 1;
+ }
+}
\ No newline at end of file