v0.4.1: big changes to key functionality
This commit is contained in:
parent
eb4d13d97b
commit
eed06b618d
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
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 |
|
@ -34,6 +34,7 @@ public class Assets {
|
|||
public static final String CHROME = "chrome.png";
|
||||
public static final String ICONS = "icons.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 SHLD_BAR = "shield_bar.png";
|
||||
public static final String XP_BAR = "exp_bar.png";
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
package com.shatteredpixel.shatteredpixeldungeon.actors.hero;
|
||||
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Badges;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.KindOfWeapon;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.KindofMisc;
|
||||
|
@ -50,6 +49,9 @@ public class Belongings implements Iterable<Item> {
|
|||
public KindofMisc misc1 = 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 ) {
|
||||
this.owner = owner;
|
||||
|
||||
|
@ -65,6 +67,9 @@ public class Belongings implements Iterable<Item> {
|
|||
private static final String MISC1 = "misc1";
|
||||
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 ) {
|
||||
|
||||
backpack.storeInBundle( bundle );
|
||||
|
@ -73,13 +78,30 @@ public class Belongings implements Iterable<Item> {
|
|||
bundle.put( ARMOR, armor );
|
||||
bundle.put( MISC1, misc1);
|
||||
bundle.put( MISC2, misc2);
|
||||
|
||||
bundle.put( IRON_KEYS, ironKeys);
|
||||
bundle.put( SPECIAL_KEYS, specialKeys);
|
||||
}
|
||||
|
||||
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.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){
|
||||
//handles the case of an equipped wand from pre-0.3.0
|
||||
Wand item = (Wand) bundle.get(WEAPON);
|
||||
|
@ -123,29 +145,6 @@ public class Belongings implements Iterable<Item> {
|
|||
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() {
|
||||
for (Item item : this) {
|
||||
item.identify();
|
||||
|
|
|
@ -65,10 +65,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.DriedRose;
|
|||
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.EtherealChains;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.TalismanOfForesight;
|
||||
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.SkeletonKey;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfMight;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfStrength;
|
||||
|
@ -638,7 +635,8 @@ public class Hero extends Char {
|
|||
|
||||
if (item instanceof Dewdrop
|
||||
|| item instanceof TimekeepersHourglass.sandBag
|
||||
|| item instanceof DriedRose.Petal) {
|
||||
|| item instanceof DriedRose.Petal
|
||||
|| item instanceof Key) {
|
||||
//Do Nothing
|
||||
} else {
|
||||
|
||||
|
@ -683,17 +681,13 @@ public class Hero extends Char {
|
|||
Heap heap = Dungeon.level.heaps.get( dst );
|
||||
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
|
||||
&& belongings.specialKeys[Dungeon.depth] < 1) {
|
||||
|
||||
if (heap.type == Type.LOCKED_CHEST || heap.type == Type.CRYSTAL_CHEST) {
|
||||
|
||||
theKey = belongings.getKey( GoldenKey.class, Dungeon.depth );
|
||||
|
||||
if (theKey == null) {
|
||||
GLog.w( Messages.get(this, "locked_chest") );
|
||||
ready();
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
switch (heap.type) {
|
||||
|
@ -731,20 +725,22 @@ public class Hero extends Char {
|
|||
int doorCell = action.dst;
|
||||
if (Level.adjacent( pos, doorCell )) {
|
||||
|
||||
theKey = null;
|
||||
boolean hasKey = false;
|
||||
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 );
|
||||
sprite.operate( doorCell );
|
||||
|
@ -1383,27 +1379,27 @@ public class Hero extends Char {
|
|||
|
||||
if (curAction instanceof HeroAction.Unlock) {
|
||||
|
||||
if (theKey != null) {
|
||||
theKey.detach( belongings.backpack );
|
||||
theKey = null;
|
||||
}
|
||||
|
||||
int doorCell = ((HeroAction.Unlock)curAction).dst;
|
||||
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 );
|
||||
GameScene.updateMap( doorCell );
|
||||
|
||||
} 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 );
|
||||
if (heap.type == Type.SKELETON || heap.type == Type.REMAINS) {
|
||||
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 );
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
*/
|
||||
package com.shatteredpixel.shatteredpixeldungeon.items.keys;
|
||||
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
|
||||
|
||||
public class GoldenKey extends Key {
|
||||
|
@ -28,6 +30,12 @@ public class GoldenKey extends Key {
|
|||
image = ItemSpriteSheet.GOLDEN_KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doPickUp(Hero hero) {
|
||||
Dungeon.hero.belongings.specialKeys[Dungeon.depth]++;
|
||||
return super.doPickUp(hero);
|
||||
}
|
||||
|
||||
public GoldenKey() {
|
||||
this( 0 );
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
package com.shatteredpixel.shatteredpixeldungeon.items.keys;
|
||||
|
||||
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;
|
||||
|
||||
public class IronKey extends Key {
|
||||
|
@ -32,6 +32,12 @@ public class IronKey extends Key {
|
|||
image = ItemSpriteSheet.IRON_KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doPickUp(Hero hero) {
|
||||
Dungeon.hero.belongings.ironKeys[Dungeon.depth]++;
|
||||
return super.doPickUp(hero);
|
||||
}
|
||||
|
||||
public IronKey() {
|
||||
this( 0 );
|
||||
}
|
||||
|
@ -41,20 +47,4 @@ public class IronKey extends Key {
|
|||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,10 +20,13 @@
|
|||
*/
|
||||
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.watabou.noosa.audio.Sample;
|
||||
import com.watabou.utils.Bundle;
|
||||
|
||||
public class Key extends Item {
|
||||
public abstract class Key extends Item {
|
||||
|
||||
public static final float TIME_TO_UNLOCK = 1f;
|
||||
|
||||
|
@ -39,6 +42,14 @@ public class Key extends Item {
|
|||
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";
|
||||
|
||||
@Override
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
*/
|
||||
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.sprites.ItemSpriteSheet;
|
||||
|
||||
|
@ -39,6 +41,12 @@ public class SkeletonKey extends Key {
|
|||
this.depth = depth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doPickUp(Hero hero) {
|
||||
Dungeon.hero.belongings.specialKeys[Dungeon.depth]++;
|
||||
return super.doPickUp(hero);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSimilar( Item item ) {
|
||||
return false;
|
||||
|
|
|
@ -22,15 +22,14 @@ package com.shatteredpixel.shatteredpixeldungeon.ui;
|
|||
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Assets;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
|
||||
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.PixelScene;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndGame;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndHero;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndJournal;
|
||||
import com.watabou.input.Touchscreen.Touch;
|
||||
import com.watabou.noosa.BitmapText;
|
||||
import com.watabou.noosa.Camera;
|
||||
|
@ -63,18 +62,18 @@ public class StatusPane extends Component {
|
|||
|
||||
private BitmapText level;
|
||||
private BitmapText depth;
|
||||
private BitmapText keys;
|
||||
|
||||
private DangerIndicator danger;
|
||||
private BuffIndicator buffs;
|
||||
private Compass compass;
|
||||
|
||||
private JournalButton btnJournal;
|
||||
private MenuButton btnMenu;
|
||||
|
||||
@Override
|
||||
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( new TouchArea( 0, 1, 31, 31 ) {
|
||||
|
@ -85,9 +84,12 @@ public class StatusPane extends Component {
|
|||
Camera.main.focusOn( sprite );
|
||||
}
|
||||
GameScene.show( new WndHero() );
|
||||
};
|
||||
}
|
||||
} );
|
||||
|
||||
btnJournal = new JournalButton();
|
||||
add( btnJournal );
|
||||
|
||||
btnMenu = new MenuButton();
|
||||
add( btnMenu );
|
||||
|
||||
|
@ -129,11 +131,6 @@ public class StatusPane extends Component {
|
|||
depth.measure();
|
||||
add( depth );
|
||||
|
||||
Dungeon.hero.belongings.countIronKeys();
|
||||
keys = new BitmapText( PixelScene.pixelFont);
|
||||
keys.hardlight( 0xCACFC2 );
|
||||
add( keys );
|
||||
|
||||
danger = new DangerIndicator();
|
||||
add( danger );
|
||||
|
||||
|
@ -161,15 +158,15 @@ public class StatusPane extends Component {
|
|||
|
||||
bossHP.setPos( 6 + (width - bossHP.width())/2, 20);
|
||||
|
||||
depth.x = width - 24 - depth.width() - 18;
|
||||
depth.y = 6;
|
||||
|
||||
keys.y = 6;
|
||||
depth.x = width - 35.5f - depth.width() / 2f;
|
||||
depth.y = 8f - depth.baseLine() / 2f;
|
||||
|
||||
danger.setPos( width - danger.width(), 20 );
|
||||
|
||||
buffs.setPos( 31, 9 );
|
||||
|
||||
btnJournal.setPos( width - 42, 1 );
|
||||
|
||||
btnMenu.setPos( width - btnMenu.width(), 1 );
|
||||
}
|
||||
|
||||
|
@ -215,14 +212,6 @@ public class StatusPane extends Component {
|
|||
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();
|
||||
if (tier != lastTier) {
|
||||
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 Image image;
|
||||
|
@ -245,7 +308,7 @@ public class StatusPane extends Component {
|
|||
protected void createChildren() {
|
||||
super.createChildren();
|
||||
|
||||
image = new Image( Assets.STATUS, 114, 3, 12, 11 );
|
||||
image = new Image( Assets.MENU, 17, 2, 12, 11 );
|
||||
add( image );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user