v0.4.1: big changes to key functionality

This commit is contained in:
Evan Debenham 2016-07-03 17:39:36 -04:00
parent eb4d13d97b
commit eed06b618d
11 changed files with 175 additions and 99 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

BIN
assets/menu_button.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 330 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 941 B

View File

@ -34,6 +34,7 @@ public class Assets {
public static final String CHROME = "chrome.png"; public static final String CHROME = "chrome.png";
public static final String ICONS = "icons.png"; public static final String ICONS = "icons.png";
public static final String STATUS = "status_pane.png"; public static final String STATUS = "status_pane.png";
public static final String MENU = "menu_button.png";
public static final String HP_BAR = "hp_bar.png"; public static final String HP_BAR = "hp_bar.png";
public static final String SHLD_BAR = "shield_bar.png"; public static final String SHLD_BAR = "shield_bar.png";
public static final String XP_BAR = "exp_bar.png"; public static final String XP_BAR = "exp_bar.png";

View File

@ -21,7 +21,6 @@
package com.shatteredpixel.shatteredpixeldungeon.actors.hero; package com.shatteredpixel.shatteredpixeldungeon.actors.hero;
import com.shatteredpixel.shatteredpixeldungeon.Badges; import com.shatteredpixel.shatteredpixeldungeon.Badges;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.KindOfWeapon; import com.shatteredpixel.shatteredpixeldungeon.items.KindOfWeapon;
import com.shatteredpixel.shatteredpixeldungeon.items.KindofMisc; import com.shatteredpixel.shatteredpixeldungeon.items.KindofMisc;
@ -49,6 +48,9 @@ public class Belongings implements Iterable<Item> {
public Armor armor = null; public Armor armor = null;
public KindofMisc misc1 = null; public KindofMisc misc1 = null;
public KindofMisc misc2 = null; public KindofMisc misc2 = null;
public int[] ironKeys = new int[26];
public int[] specialKeys = new int[26]; //golden or boss keys
public Belongings( Hero owner ) { public Belongings( Hero owner ) {
this.owner = owner; this.owner = owner;
@ -63,7 +65,10 @@ public class Belongings implements Iterable<Item> {
private static final String WEAPON = "weapon"; private static final String WEAPON = "weapon";
private static final String ARMOR = "armor"; private static final String ARMOR = "armor";
private static final String MISC1 = "misc1"; private static final String MISC1 = "misc1";
private static final String MISC2 = "misc2"; private static final String MISC2 = "misc2";
private static final String IRON_KEYS = "ironKeys";
private static final String SPECIAL_KEYS = "specialKeys";
public void storeInBundle( Bundle bundle ) { public void storeInBundle( Bundle bundle ) {
@ -73,13 +78,30 @@ public class Belongings implements Iterable<Item> {
bundle.put( ARMOR, armor ); bundle.put( ARMOR, armor );
bundle.put( MISC1, misc1); bundle.put( MISC1, misc1);
bundle.put( MISC2, misc2); bundle.put( MISC2, misc2);
bundle.put( IRON_KEYS, ironKeys);
bundle.put( SPECIAL_KEYS, specialKeys);
} }
public void restoreFromBundle( Bundle bundle ) { public void restoreFromBundle( Bundle bundle ) {
if (bundle.contains(IRON_KEYS)) ironKeys = bundle.getIntArray( IRON_KEYS );
if (bundle.contains(SPECIAL_KEYS)) specialKeys = bundle.getIntArray( SPECIAL_KEYS );
backpack.clear(); backpack.clear();
backpack.restoreFromBundle( bundle ); backpack.restoreFromBundle( bundle );
//removing keys, from pre-0.4.1 saves
for (Item item : backpack.items.toArray(new Item[0])){
if (item instanceof Key){
item.detachAll(backpack);
if (item instanceof IronKey)
ironKeys[((Key) item).depth] += item.quantity();
else
specialKeys[((Key) item).depth] += item.quantity();
}
}
if (bundle.get( WEAPON ) instanceof Wand){ if (bundle.get( WEAPON ) instanceof Wand){
//handles the case of an equipped wand from pre-0.3.0 //handles the case of an equipped wand from pre-0.3.0
Wand item = (Wand) bundle.get(WEAPON); Wand item = (Wand) bundle.get(WEAPON);
@ -123,29 +145,6 @@ public class Belongings implements Iterable<Item> {
return null; return null;
} }
@SuppressWarnings("unchecked")
public <T extends Key> T getKey( Class<T> kind, int depth ) {
for (Item item : backpack) {
if (item.getClass() == kind && ((Key)item).depth == depth) {
return (T)item;
}
}
return null;
}
public void countIronKeys() {
IronKey.curDepthQuantity = 0;
for (Item item : backpack) {
if (item instanceof IronKey && ((IronKey)item).depth == Dungeon.depth) {
IronKey.curDepthQuantity += item.quantity();
}
}
}
public void identify() { public void identify() {
for (Item item : this) { for (Item item : this) {
item.identify(); item.identify();

View File

@ -65,10 +65,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.DriedRose;
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.EtherealChains; import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.EtherealChains;
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.TalismanOfForesight; import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.TalismanOfForesight;
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.TimekeepersHourglass; import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.TimekeepersHourglass;
import com.shatteredpixel.shatteredpixeldungeon.items.keys.GoldenKey;
import com.shatteredpixel.shatteredpixeldungeon.items.keys.IronKey;
import com.shatteredpixel.shatteredpixeldungeon.items.keys.Key; import com.shatteredpixel.shatteredpixeldungeon.items.keys.Key;
import com.shatteredpixel.shatteredpixeldungeon.items.keys.SkeletonKey;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion; import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfMight; import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfMight;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfStrength; import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfStrength;
@ -638,7 +635,8 @@ public class Hero extends Char {
if (item instanceof Dewdrop if (item instanceof Dewdrop
|| item instanceof TimekeepersHourglass.sandBag || item instanceof TimekeepersHourglass.sandBag
|| item instanceof DriedRose.Petal) { || item instanceof DriedRose.Petal
|| item instanceof Key) {
//Do Nothing //Do Nothing
} else { } else {
@ -682,18 +680,14 @@ public class Hero extends Char {
Heap heap = Dungeon.level.heaps.get( dst ); Heap heap = Dungeon.level.heaps.get( dst );
if (heap != null && (heap.type != Type.HEAP && heap.type != Type.FOR_SALE)) { if (heap != null && (heap.type != Type.HEAP && heap.type != Type.FOR_SALE)) {
theKey = null;
if (heap.type == Type.LOCKED_CHEST || heap.type == Type.CRYSTAL_CHEST) { if (heap.type == Type.LOCKED_CHEST || heap.type == Type.CRYSTAL_CHEST
&& belongings.specialKeys[Dungeon.depth] < 1) {
theKey = belongings.getKey( GoldenKey.class, Dungeon.depth );
if (theKey == null) {
GLog.w( Messages.get(this, "locked_chest") ); GLog.w( Messages.get(this, "locked_chest") );
ready(); ready();
return false; return false;
}
} }
switch (heap.type) { switch (heap.type) {
@ -731,20 +725,22 @@ public class Hero extends Char {
int doorCell = action.dst; int doorCell = action.dst;
if (Level.adjacent( pos, doorCell )) { if (Level.adjacent( pos, doorCell )) {
theKey = null; boolean hasKey = false;
int door = Dungeon.level.map[doorCell]; int door = Dungeon.level.map[doorCell];
if (door == Terrain.LOCKED_DOOR) { if (door == Terrain.LOCKED_DOOR
&& belongings.ironKeys[Dungeon.depth] > 0) {
theKey = belongings.getKey( IronKey.class, Dungeon.depth ); hasKey = true;
} else if (door == Terrain.LOCKED_EXIT) { } else if (door == Terrain.LOCKED_EXIT
&& belongings.specialKeys[Dungeon.depth] > 0) {
theKey = belongings.getKey( SkeletonKey.class, Dungeon.depth );
hasKey = true;
} }
if (theKey != null) { if (hasKey) {
spend( Key.TIME_TO_UNLOCK ); spend( Key.TIME_TO_UNLOCK );
sprite.operate( doorCell ); sprite.operate( doorCell );
@ -1382,28 +1378,28 @@ public class Hero extends Char {
public void onOperateComplete() { public void onOperateComplete() {
if (curAction instanceof HeroAction.Unlock) { if (curAction instanceof HeroAction.Unlock) {
if (theKey != null) {
theKey.detach( belongings.backpack );
theKey = null;
}
int doorCell = ((HeroAction.Unlock)curAction).dst; int doorCell = ((HeroAction.Unlock)curAction).dst;
int door = Dungeon.level.map[doorCell]; int door = Dungeon.level.map[doorCell];
if (door == Terrain.LOCKED_DOOR){
belongings.ironKeys[Dungeon.depth]--;
Level.set( doorCell, Terrain.DOOR );
} else {
belongings.specialKeys[Dungeon.depth]--;
Level.set( doorCell, Terrain.UNLOCKED_EXIT );
}
Level.set( doorCell, door == Terrain.LOCKED_DOOR ? Terrain.DOOR : Terrain.UNLOCKED_EXIT ); Level.set( doorCell, door == Terrain.LOCKED_DOOR ? Terrain.DOOR : Terrain.UNLOCKED_EXIT );
GameScene.updateMap( doorCell ); GameScene.updateMap( doorCell );
} else if (curAction instanceof HeroAction.OpenChest) { } else if (curAction instanceof HeroAction.OpenChest) {
if (theKey != null) {
theKey.detach( belongings.backpack );
theKey = null;
}
Heap heap = Dungeon.level.heaps.get( ((HeroAction.OpenChest)curAction).dst ); Heap heap = Dungeon.level.heaps.get( ((HeroAction.OpenChest)curAction).dst );
if (heap.type == Type.SKELETON || heap.type == Type.REMAINS) { if (heap.type == Type.SKELETON || heap.type == Type.REMAINS) {
Sample.INSTANCE.play( Assets.SND_BONES ); Sample.INSTANCE.play( Assets.SND_BONES );
} else if (heap.type == Type.LOCKED_CHEST || heap.type == Type.CRYSTAL_CHEST){
belongings.specialKeys[Dungeon.depth]--;
} }
heap.open( this ); heap.open( this );
} }

View File

@ -20,6 +20,8 @@
*/ */
package com.shatteredpixel.shatteredpixeldungeon.items.keys; package com.shatteredpixel.shatteredpixeldungeon.items.keys;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
public class GoldenKey extends Key { public class GoldenKey extends Key {
@ -27,7 +29,13 @@ public class GoldenKey extends Key {
{ {
image = ItemSpriteSheet.GOLDEN_KEY; image = ItemSpriteSheet.GOLDEN_KEY;
} }
@Override
public boolean doPickUp(Hero hero) {
Dungeon.hero.belongings.specialKeys[Dungeon.depth]++;
return super.doPickUp(hero);
}
public GoldenKey() { public GoldenKey() {
this( 0 ); this( 0 );
} }

View File

@ -21,7 +21,7 @@
package com.shatteredpixel.shatteredpixeldungeon.items.keys; package com.shatteredpixel.shatteredpixeldungeon.items.keys;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
public class IronKey extends Key { public class IronKey extends Key {
@ -31,7 +31,13 @@ public class IronKey extends Key {
{ {
image = ItemSpriteSheet.IRON_KEY; image = ItemSpriteSheet.IRON_KEY;
} }
@Override
public boolean doPickUp(Hero hero) {
Dungeon.hero.belongings.ironKeys[Dungeon.depth]++;
return super.doPickUp(hero);
}
public IronKey() { public IronKey() {
this( 0 ); this( 0 );
} }
@ -40,21 +46,5 @@ public class IronKey extends Key {
super(); super();
this.depth = depth; this.depth = depth;
} }
@Override
public boolean collect( Bag bag ) {
boolean result = super.collect( bag );
if (result && depth == Dungeon.depth && Dungeon.hero != null) {
Dungeon.hero.belongings.countIronKeys();
}
return result;
}
@Override
public void onDetach( ) {
if (depth == Dungeon.depth) {
Dungeon.hero.belongings.countIronKeys();
}
}
} }

View File

@ -20,10 +20,13 @@
*/ */
package com.shatteredpixel.shatteredpixeldungeon.items.keys; package com.shatteredpixel.shatteredpixeldungeon.items.keys;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Bundle; import com.watabou.utils.Bundle;
public class Key extends Item { public abstract class Key extends Item {
public static final float TIME_TO_UNLOCK = 1f; public static final float TIME_TO_UNLOCK = 1f;
@ -38,7 +41,15 @@ public class Key extends Item {
public boolean isSimilar( Item item ) { public boolean isSimilar( Item item ) {
return item.getClass() == getClass() && ((Key)item).depth == depth; return item.getClass() == getClass() && ((Key)item).depth == depth;
} }
@Override
public boolean doPickUp(Hero hero) {
//TODO add a pickup animation to the journal
Sample.INSTANCE.play( Assets.SND_ITEM );
hero.spendAndNext( TIME_TO_PICK_UP );
return true;
}
private static final String DEPTH = "depth"; private static final String DEPTH = "depth";
@Override @Override

View File

@ -20,6 +20,8 @@
*/ */
package com.shatteredpixel.shatteredpixeldungeon.items.keys; package com.shatteredpixel.shatteredpixeldungeon.items.keys;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
@ -38,6 +40,12 @@ public class SkeletonKey extends Key {
super(); super();
this.depth = depth; this.depth = depth;
} }
@Override
public boolean doPickUp(Hero hero) {
Dungeon.hero.belongings.specialKeys[Dungeon.depth]++;
return super.doPickUp(hero);
}
@Override @Override
public boolean isSimilar( Item item ) { public boolean isSimilar( Item item ) {

View File

@ -22,15 +22,14 @@ package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
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.keys.IronKey;
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;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndGame; import com.shatteredpixel.shatteredpixeldungeon.windows.WndGame;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndHero; import com.shatteredpixel.shatteredpixeldungeon.windows.WndHero;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndJournal;
import com.watabou.input.Touchscreen.Touch; import com.watabou.input.Touchscreen.Touch;
import com.watabou.noosa.BitmapText; import com.watabou.noosa.BitmapText;
import com.watabou.noosa.Camera; import com.watabou.noosa.Camera;
@ -63,18 +62,18 @@ public class StatusPane extends Component {
private BitmapText level; private BitmapText level;
private BitmapText depth; private BitmapText depth;
private BitmapText keys;
private DangerIndicator danger; private DangerIndicator danger;
private BuffIndicator buffs; private BuffIndicator buffs;
private Compass compass; private Compass compass;
private JournalButton btnJournal;
private MenuButton btnMenu; private MenuButton btnMenu;
@Override @Override
protected void createChildren() { protected void createChildren() {
bg = new NinePatch( Assets.STATUS, 80, 0, 30 + 18, 0 ); bg = new NinePatch( Assets.STATUS, 85, 0, 45, 0 );
add( bg ); add( bg );
add( new TouchArea( 0, 1, 31, 31 ) { add( new TouchArea( 0, 1, 31, 31 ) {
@ -85,9 +84,12 @@ public class StatusPane extends Component {
Camera.main.focusOn( sprite ); Camera.main.focusOn( sprite );
} }
GameScene.show( new WndHero() ); GameScene.show( new WndHero() );
}; }
} ); } );
btnJournal = new JournalButton();
add( btnJournal );
btnMenu = new MenuButton(); btnMenu = new MenuButton();
add( btnMenu ); add( btnMenu );
@ -129,11 +131,6 @@ public class StatusPane extends Component {
depth.measure(); depth.measure();
add( depth ); add( depth );
Dungeon.hero.belongings.countIronKeys();
keys = new BitmapText( PixelScene.pixelFont);
keys.hardlight( 0xCACFC2 );
add( keys );
danger = new DangerIndicator(); danger = new DangerIndicator();
add( danger ); add( danger );
@ -161,15 +158,15 @@ public class StatusPane extends Component {
bossHP.setPos( 6 + (width - bossHP.width())/2, 20); bossHP.setPos( 6 + (width - bossHP.width())/2, 20);
depth.x = width - 24 - depth.width() - 18; depth.x = width - 35.5f - depth.width() / 2f;
depth.y = 6; depth.y = 8f - depth.baseLine() / 2f;
keys.y = 6;
danger.setPos( width - danger.width(), 20 ); danger.setPos( width - danger.width(), 20 );
buffs.setPos( 31, 9 ); buffs.setPos( 31, 9 );
btnJournal.setPos( width - 42, 1 );
btnMenu.setPos( width - btnMenu.width(), 1 ); btnMenu.setPos( width - btnMenu.width(), 1 );
} }
@ -215,14 +212,6 @@ public class StatusPane extends Component {
PixelScene.align(level); PixelScene.align(level);
} }
int k = IronKey.curDepthQuantity;
if (k != lastKeys) {
lastKeys = k;
keys.text( Integer.toString( lastKeys ) );
keys.measure();
keys.x = width - 8 - keys.width() - 18;
}
int tier = Dungeon.hero.tier(); int tier = Dungeon.hero.tier();
if (tier != lastTier) { if (tier != lastTier) {
lastTier = tier; lastTier = tier;
@ -230,6 +219,80 @@ public class StatusPane extends Component {
} }
} }
private static class JournalButton extends Button {
private Image bg;
private Image icon;
public JournalButton() {
super();
width = bg.width + 13; //includes the depth display to the left
height = bg.height + 4;
}
@Override
protected void createChildren() {
super.createChildren();
bg = new Image( Assets.MENU, 2, 2, 13, 11 );
add( bg );
icon = new Image( Assets.MENU, 32, 1, 10, 6);
add( icon );
}
@Override
protected void layout() {
super.layout();
bg.x = x + 13;
bg.y = y + 2;
icon.x = bg.x + 2;
icon.y = bg.y + 3;
}
@Override
public void update() {
super.update();
for (int i = 1; i <= Dungeon.depth; i++){
if (Dungeon.hero.belongings.ironKeys[i] > 0){
if (i == Dungeon.depth){
icon.resetColor();
} else {
icon.brightness(0);
icon.alpha(0.67f);
}
return;
}
}
icon.brightness(0);
icon.alpha(0.33f);
}
@Override
protected void onTouchDown() {
bg.brightness( 1.5f );
Sample.INSTANCE.play( Assets.SND_CLICK );
}
@Override
protected void onTouchUp() {
bg.resetColor();
}
@Override
protected void onClick() {
GameScene.show( new WndJournal() );
}
}
private static class MenuButton extends Button { private static class MenuButton extends Button {
private Image image; private Image image;
@ -245,7 +308,7 @@ public class StatusPane extends Component {
protected void createChildren() { protected void createChildren() {
super.createChildren(); super.createChildren();
image = new Image( Assets.STATUS, 114, 3, 12, 11 ); image = new Image( Assets.MENU, 17, 2, 12, 11 );
add( image ); add( image );
} }