v0.4.1: added a visual effect for adding items to the journal

This commit is contained in:
Evan Debenham 2016-07-20 01:19:18 -04:00 committed by Evan Debenham
parent c0eecb1338
commit 80a4ef2b9b
4 changed files with 41 additions and 14 deletions

View File

@ -23,6 +23,7 @@ package com.shatteredpixel.shatteredpixeldungeon.items.keys;
import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Bundle; import com.watabou.utils.Bundle;
@ -44,7 +45,7 @@ public abstract class Key extends Item {
@Override @Override
public boolean doPickUp(Hero hero) { public boolean doPickUp(Hero hero) {
//TODO add a pickup animation to the journal GameScene.pickUpJournal(this);
Sample.INSTANCE.play( Assets.SND_ITEM ); Sample.INSTANCE.play( Assets.SND_ITEM );
hero.spendAndNext( TIME_TO_PICK_UP ); hero.spendAndNext( TIME_TO_PICK_UP );
return true; return true;

View File

@ -109,6 +109,8 @@ public class GameScene extends PixelScene {
private DungeonTilemap tiles; private DungeonTilemap tiles;
private FogOfWar fog; private FogOfWar fog;
private HeroSprite hero; private HeroSprite hero;
private StatusPane pane;
private GameLog log; private GameLog log;
@ -248,11 +250,11 @@ public class GameScene extends PixelScene {
add( new HealthIndicator() ); add( new HealthIndicator() );
add( cellSelector = new CellSelector( tiles ) ); add( cellSelector = new CellSelector( tiles ) );
StatusPane sb = new StatusPane(); pane = new StatusPane();
sb.camera = uiCamera; pane.camera = uiCamera;
sb.setSize( uiCamera.width, 0 ); pane.setSize( uiCamera.width, 0 );
add( sb ); add( pane );
toolbar = new Toolbar(); toolbar = new Toolbar();
toolbar.camera = uiCamera; toolbar.camera = uiCamera;
@ -284,7 +286,7 @@ public class GameScene extends PixelScene {
busy = new BusyIndicator(); busy = new BusyIndicator();
busy.camera = uiCamera; busy.camera = uiCamera;
busy.x = 1; busy.x = 1;
busy.y = sb.bottom() + 1; busy.y = pane.bottom() + 1;
add( busy ); add( busy );
switch (InterlevelScene.mode) { switch (InterlevelScene.mode) {
@ -656,6 +658,10 @@ public class GameScene extends PixelScene {
scene.toolbar.pickup( item ); scene.toolbar.pickup( item );
} }
public static void pickUpJournal( Item item ) {
scene.pane.pickup( item );
}
public static void resetMap() { public static void resetMap() {
if (scene != null) { if (scene != null) {
scene.tiles.map(Dungeon.level.map, Level.WIDTH ); scene.tiles.map(Dungeon.level.map, Level.WIDTH );

View File

@ -24,6 +24,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck; import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.BloodParticle; import com.shatteredpixel.shatteredpixeldungeon.effects.particles.BloodParticle;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite; import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite;
@ -69,6 +70,8 @@ public class StatusPane extends Component {
private JournalButton btnJournal; private JournalButton btnJournal;
private MenuButton btnMenu; private MenuButton btnMenu;
private Toolbar.PickedUpItem pickedUp;
@Override @Override
protected void createChildren() { protected void createChildren() {
@ -135,6 +138,8 @@ public class StatusPane extends Component {
buffs = new BuffIndicator( Dungeon.hero ); buffs = new BuffIndicator( Dungeon.hero );
add( buffs ); add( buffs );
add( pickedUp = new Toolbar.PickedUpItem());
} }
@Override @Override
@ -218,6 +223,13 @@ public class StatusPane extends Component {
} }
} }
public void pickup( Item item ) {
pickedUp.reset( item,
btnJournal.icon.x + btnJournal.icon.width()/2f,
btnJournal.icon.y + btnJournal.icon.height()/2f,
true );
}
private static class JournalButton extends Button { private static class JournalButton extends Button {
private Image bg; private Image bg;

View File

@ -267,7 +267,8 @@ public class Toolbar extends Component {
public void pickup( Item item ) { public void pickup( Item item ) {
pickedUp.reset( item, pickedUp.reset( item,
btnInventory.centerX(), btnInventory.centerX(),
btnInventory.centerY() ); btnInventory.centerY(),
false );
} }
private static CellSelector.Listener informer = new CellSelector.Listener() { private static CellSelector.Listener informer = new CellSelector.Listener() {
@ -376,7 +377,7 @@ public class Toolbar extends Component {
} }
} }
private static class PickedUpItem extends ItemSprite { public static class PickedUpItem extends ItemSprite {
private static final float DISTANCE = DungeonTilemap.SIZE; private static final float DISTANCE = DungeonTilemap.SIZE;
private static final float DURATION = 0.2f; private static final float DURATION = 0.2f;
@ -384,6 +385,8 @@ public class Toolbar extends Component {
private float dstX; private float dstX;
private float dstY; private float dstY;
private float left; private float left;
private boolean rising = false;
public PickedUpItem() { public PickedUpItem() {
super(); super();
@ -395,19 +398,22 @@ public class Toolbar extends Component {
false; false;
} }
public void reset( Item item, float dstX, float dstY ) { public void reset( Item item, float dstX, float dstY, boolean rising ) {
view( item ); view( item );
active = active =
visible = visible =
true; true;
this.rising = rising;
this.dstX = dstX - ItemSprite.SIZE / 2; this.dstX = dstX - ItemSprite.SIZE / 2;
this.dstY = dstY - ItemSprite.SIZE / 2; this.dstY = dstY - ItemSprite.SIZE / 2;
left = DURATION; left = DURATION;
x = this.dstX - DISTANCE; x = this.dstX - DISTANCE;
y = this.dstY - DISTANCE; if (rising) y = this.dstY + DISTANCE;
else y = this.dstY - DISTANCE;
alpha( 1 ); alpha( 1 );
} }
@ -426,8 +432,10 @@ public class Toolbar extends Component {
float p = left / DURATION; float p = left / DURATION;
scale.set( (float)Math.sqrt( p ) ); scale.set( (float)Math.sqrt( p ) );
float offset = DISTANCE * p; float offset = DISTANCE * p;
x = dstX - offset;
y = dstY - offset; x = dstX - offset;
if (rising) y = dstY + offset;
else y = dstY - offset;
} }
} }
} }