From 539d2442a4203507601d6aea240bab0259508066 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Fri, 24 Apr 2015 02:29:07 -0400 Subject: [PATCH] v0.3.0: added a visual indicator when a mob is surprised. --- assets/effects.png | Bin 3037 -> 3080 bytes .../actors/mobs/Mob.java | 11 ++- .../effects/Effects.java | 4 + .../effects/Surprise.java | 71 ++++++++++++++++++ 4 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 src/com/shatteredpixel/shatteredpixeldungeon/effects/Surprise.java diff --git a/assets/effects.png b/assets/effects.png index 2e684a8e37b483a235bee34d568c26d9318ac216..8de92a775e1d2a9586d48feb09931f8a2e99b9a9 100644 GIT binary patch delta 413 zcmcaB-XSqTl7pFnfx%@-*RhR?9$b^Fxn%1l*ti9@#%Fv7ihBq6gt!7}etv!l35i38 zJPsfBJAORk^9SC~ABDbs;rjlSDO-K3CE@lw)Vvgm}8!vUigiN;sIO+WGR)9gd@IJ`E> zPP@;$U$E?S(ubKV4qj`zdw8S3t8;67RZp#%s&MAVdV}?67J62#x7>BkqUYq32X(7r zik@kB?XS0Tx1K)LNWV$x{?=<=mdj_%Gnjg4HRGIwTdhkOU75scn7dfEuiKzn(V?ob zVCBWa9jm)C2(1V5_VhJ98wXK@N!|4k=Hv6 zpWuxWOB@&*zc)O81cs5Ut#c7MVq=pW;4O$ezVj5nf4s^w02H^tHAw6yS?7`nz?T<1 z#pf0H{RiUYQ;Bt~zL_=+Y)XF+lIGqjjwi{SZ>kPwi&&AX`~&63o552Cq6i zq~bKNwqk7?O#w{V0nWAy0RnFXXg!CyLnswXfEFl##t3f&kYa45MV+7vS3+AyL=<3~ zEW(@#mm;fyMUDD6F8E~0DAxWM_!j7oEu)~Z^?OHuBX$j36YyBa?j}cT6EtAyN`MJ{ z_aTtEj_-CCxJ$5l9k<};-)_Uc?@Lz+0F?i2=qkZ546Sz!{O&e%w=XO{tLHnXR8{~0 N002ovPDHLkV1m%tnREaE diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java index 60d464676..e61711b20 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java @@ -29,6 +29,7 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Sleep; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Terror; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.HeroSubClass; +import com.shatteredpixel.shatteredpixeldungeon.effects.Surprise; import com.shatteredpixel.shatteredpixeldungeon.effects.Wound; import com.shatteredpixel.shatteredpixeldungeon.items.Generator; import com.shatteredpixel.shatteredpixeldungeon.items.Item; @@ -346,9 +347,13 @@ public abstract class Mob extends Char { @Override public int defenseProc( Char enemy, int damage ) { - if (!enemySeen && enemy == Dungeon.hero && ((Hero)enemy).subClass == HeroSubClass.ASSASSIN) { - damage *= 1.34f; - Wound.hit( this ); + if (!enemySeen && enemy == Dungeon.hero) { + if (((Hero)enemy).subClass == HeroSubClass.ASSASSIN) { + damage *= 1.34f; + Wound.hit(this); + } else { + Surprise.hit(this); + } } return damage; } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/effects/Effects.java b/src/com/shatteredpixel/shatteredpixeldungeon/effects/Effects.java index 9d949e910..10bbafdd4 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/effects/Effects.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/effects/Effects.java @@ -26,6 +26,7 @@ public class Effects { RIPPLE, LIGHTNING, WOUND, + EXCLAMATION, DEATH_RAY, LIGHT_RAY }; @@ -42,6 +43,9 @@ public class Effects { case WOUND: icon.frame(icon.texture.uvRect(16, 8, 32, 16)); break; + case EXCLAMATION: + icon.frame(icon.texture.uvRect(0, 16, 6, 25)); + break; case DEATH_RAY: icon.frame(icon.texture.uvRect(16, 16, 32, 24)); break; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/effects/Surprise.java b/src/com/shatteredpixel/shatteredpixeldungeon/effects/Surprise.java new file mode 100644 index 000000000..dc1753a01 --- /dev/null +++ b/src/com/shatteredpixel/shatteredpixeldungeon/effects/Surprise.java @@ -0,0 +1,71 @@ +package com.shatteredpixel.shatteredpixeldungeon.effects; + +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; +import com.shatteredpixel.shatteredpixeldungeon.DungeonTilemap; +import com.shatteredpixel.shatteredpixeldungeon.actors.Char; +import com.shatteredpixel.shatteredpixeldungeon.levels.Level; +import com.watabou.noosa.Game; +import com.watabou.noosa.Group; +import com.watabou.noosa.Image; + +/** + * Created by Evan on 20/04/2015. + */ +public class Surprise extends Image { + + private static final float TIME_TO_FADE = 0.8f; + + private float time; + + public Surprise() { + super(Effects.get(Effects.Type.EXCLAMATION)); + origin.set(width / 2, height / 2); + } + + public void reset(int p) { + revive(); + + x = (p % Level.WIDTH) * DungeonTilemap.SIZE + (DungeonTilemap.SIZE - width) / 2; + y = (p / Level.WIDTH) * DungeonTilemap.SIZE + (DungeonTilemap.SIZE - height) / 2; + + time = TIME_TO_FADE; + } + + @Override + public void update() { + super.update(); + + if ((time -= Game.elapsed) <= 0) { + kill(); + } else { + float p = time / TIME_TO_FADE; + alpha(p); + scale.y = 1 + p/2; + } + } + + public static void hit(Char ch) { + hit(ch, 0); + } + + public static void hit(Char ch, float angle) { + if (ch.sprite.parent != null) { + Surprise s = (Surprise) ch.sprite.parent.recycle(Surprise.class); + ch.sprite.parent.bringToFront(s); + s.reset(ch.pos); + s.angle = angle; + } + } + + public static void hit(int pos) { + hit(pos, 0); + } + + public static void hit(int pos, float angle) { + Group parent = Dungeon.hero.sprite.parent; + Wound w = (Wound) parent.recycle(Wound.class); + parent.bringToFront(w); + w.reset(pos); + w.angle = angle; + } +}