v0.8.0: fixes/tweaks:

- damage numbers now appear where a sprite is arriving if it is moving
- blob emitters can now have a defined bound within a cell
- tweaked hero level exit/entrance behaviour
- refactored game actions that are defined in GameAction.java
This commit is contained in:
Evan Debenham 2020-01-14 16:04:51 -05:00
parent df26e32949
commit 08a719ffe2
12 changed files with 58 additions and 54 deletions

View File

@ -52,9 +52,7 @@ public class GameAction {
} }
public static final GameAction NONE = new GameAction( "none" ); public static final GameAction NONE = new GameAction( "none" );
public static final GameAction BACK = new GameAction( "back" ); public static final GameAction BACK = new GameAction( "back" );
public static final GameAction MENU = new GameAction( "menu" );
public static ArrayList<GameAction> allActions(){ public static ArrayList<GameAction> allActions(){
return new ArrayList<>(ALL_ACTIONS); return new ArrayList<>(ALL_ACTIONS);

View File

@ -32,14 +32,6 @@ public class KeyBindings {
private static LinkedHashMap<Integer, GameAction> bindings = new LinkedHashMap<>(); private static LinkedHashMap<Integer, GameAction> bindings = new LinkedHashMap<>();
public static void addKeyBinding(int keyCode, GameAction action){
bindings.put(keyCode, action);
}
public static void clearKeyBindings(){
bindings.clear();
}
public static LinkedHashMap<Integer, GameAction> getAllBindings(){ public static LinkedHashMap<Integer, GameAction> getAllBindings(){
return new LinkedHashMap<>(bindings); return new LinkedHashMap<>(bindings);
} }
@ -48,20 +40,32 @@ public class KeyBindings {
bindings = new LinkedHashMap<>(newBindings); bindings = new LinkedHashMap<>(newBindings);
} }
//these are special keybinding that are not user-configurable
private static LinkedHashMap<Integer, GameAction> hardBindings = new LinkedHashMap<>();
public static void addHardBinding(int keyCode, GameAction action){
hardBindings.put(keyCode, action);
}
public static boolean acceptUnbound = false; public static boolean acceptUnbound = false;
public static boolean isKeyBound(int keyCode){ public static boolean isKeyBound(int keyCode){
if (keyCode <= 0 || keyCode > 255){ if (keyCode <= 0 || keyCode > 255){
return false; return false;
} }
return acceptUnbound || bindings.containsKey( keyCode ); return acceptUnbound || bindings.containsKey( keyCode ) || hardBindings.containsKey( keyCode );
} }
public static GameAction getActionForKey(KeyEvent event){ public static GameAction getActionForKey(KeyEvent event){
return bindings.get( event.code ); if (bindings.containsKey( event.code )){
return bindings.get( event.code );
} else if (hardBindings.containsKey( event.code )) {
return hardBindings.get( event.code );
}
return GameAction.NONE;
} }
public static ArrayList<Integer> getKeysForAction(GameAction action){ public static ArrayList<Integer> getBoundKeysForAction(GameAction action){
ArrayList<Integer> result = new ArrayList<>(); ArrayList<Integer> result = new ArrayList<>();
for( int i : bindings.keySet()){ for( int i : bindings.keySet()){
if (bindings.get(i) == action){ if (bindings.get(i) == action){
@ -76,6 +80,10 @@ public class KeyBindings {
return "None"; return "None";
} else if (keyCode == Input.Keys.PLUS){ } else if (keyCode == Input.Keys.PLUS){
return "+"; return "+";
} else if (keyCode == Input.Keys.BACKSPACE) {
return "Backspace";
} else if (keyCode == Input.Keys.FORWARD_DEL) {
return "Delete";
} else { } else {
return Input.Keys.toString(keyCode); return Input.Keys.toString(keyCode);
} }

View File

@ -37,10 +37,6 @@ public class Scene extends Group {
if (Game.instance != null && event.pressed) { if (Game.instance != null && event.pressed) {
if (KeyBindings.getActionForKey( event ) == GameAction.BACK){ if (KeyBindings.getActionForKey( event ) == GameAction.BACK){
onBackPressed(); onBackPressed();
} else if (KeyBindings.getActionForKey( event ) == GameAction.MENU){
onMenuPressed();
} }
} }
return false; return false;
@ -79,9 +75,5 @@ public class Scene extends Group {
protected void onBackPressed() { protected void onBackPressed() {
Game.instance.finish(); Game.instance.finish();
} }
protected void onMenuPressed() {
}
} }

View File

@ -66,8 +66,7 @@ public class Button extends Component {
KeyEvent.addKeyListener( keyListener = new Signal.Listener<KeyEvent>() { KeyEvent.addKeyListener( keyListener = new Signal.Listener<KeyEvent>() {
@Override @Override
public boolean onSignal ( KeyEvent event ) { public boolean onSignal ( KeyEvent event ) {
if ( active && !event.pressed if ( active && event.pressed && KeyBindings.getActionForKey( event ) == keyAction()){
&& KeyBindings.getActionForKey( event ) == keyAction()){
onClick(); onClick();
return true; return true;
} }

View File

@ -38,9 +38,7 @@ public class SPDAction extends GameAction {
//--New references to existing actions from GameAction //--New references to existing actions from GameAction
public static final GameAction NONE = GameAction.NONE; public static final GameAction NONE = GameAction.NONE;
public static final GameAction BACK = GameAction.BACK; public static final GameAction BACK = GameAction.BACK;
public static final GameAction MENU = GameAction.MENU;
//-- //--
public static final GameAction HERO_INFO = new SPDAction("hero_info"); public static final GameAction HERO_INFO = new SPDAction("hero_info");
@ -75,8 +73,8 @@ public class SPDAction extends GameAction {
private static final LinkedHashMap<Integer, GameAction> defaultBindings = new LinkedHashMap<>(); private static final LinkedHashMap<Integer, GameAction> defaultBindings = new LinkedHashMap<>();
static { static {
defaultBindings.put( Input.Keys.BACK, SPDAction.BACK ); defaultBindings.put( Input.Keys.ESCAPE, SPDAction.BACK );
defaultBindings.put( Input.Keys.MENU, SPDAction.MENU ); defaultBindings.put( Input.Keys.BACKSPACE, SPDAction.BACK );
defaultBindings.put( Input.Keys.H, SPDAction.HERO_INFO ); defaultBindings.put( Input.Keys.H, SPDAction.HERO_INFO );
defaultBindings.put( Input.Keys.J, SPDAction.JOURNAL ); defaultBindings.put( Input.Keys.J, SPDAction.JOURNAL );
@ -120,6 +118,12 @@ public class SPDAction extends GameAction {
return new LinkedHashMap<>(defaultBindings); return new LinkedHashMap<>(defaultBindings);
} }
//hard bindings for android devices
static {
KeyBindings.addHardBinding( Input.Keys.BACK, SPDAction.BACK );
KeyBindings.addHardBinding( Input.Keys.MENU, SPDAction.INVENTORY );
}
//we only save/loads keys which differ from the default configuration. //we only save/loads keys which differ from the default configuration.
private static final String BINDINGS_FILE = "keybinds.dat"; private static final String BINDINGS_FILE = "keybinds.dat";

View File

@ -846,8 +846,10 @@ public class Hero extends Char {
private boolean actDescend( HeroAction.Descend action ) { private boolean actDescend( HeroAction.Descend action ) {
int stairs = action.dst; int stairs = action.dst;
if (pos == stairs && (Dungeon.level.map[pos] == Terrain.EXIT
|| Dungeon.level.map[pos] == Terrain.UNLOCKED_EXIT)) { //there can be multiple exit tiles, so descend on any of them
//TODO this is slightly brittle, it assumes there are no disjointed sets of exit tiles
if ((Dungeon.level.map[pos] == Terrain.EXIT || Dungeon.level.map[pos] == Terrain.UNLOCKED_EXIT)) {
curAction = null; curAction = null;
@ -873,7 +875,10 @@ public class Hero extends Char {
private boolean actAscend( HeroAction.Ascend action ) { private boolean actAscend( HeroAction.Ascend action ) {
int stairs = action.dst; int stairs = action.dst;
if (pos == stairs && Dungeon.level.map[pos] == Terrain.ENTRANCE) {
//there can be multiple entrance tiles, so descend on any of them
//TODO this is slightly brittle, it assumes there are no disjointed sets of entrance tiles
if (Dungeon.level.map[pos] == Terrain.ENTRANCE) {
if (Dungeon.depth == 1) { if (Dungeon.depth == 1) {

View File

@ -26,6 +26,7 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob;
import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTilemap; import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTilemap;
import com.watabou.noosa.particles.Emitter; import com.watabou.noosa.particles.Emitter;
import com.watabou.utils.Random; import com.watabou.utils.Random;
import com.watabou.utils.RectF;
public class BlobEmitter extends Emitter { public class BlobEmitter extends Emitter {
@ -38,6 +39,8 @@ public class BlobEmitter extends Emitter {
this.blob = blob; this.blob = blob;
blob.use( this ); blob.use( this );
} }
public RectF bound = new RectF(0, 0, 1, 1);
@Override @Override
protected void emit( int index ) { protected void emit( int index ) {
@ -59,8 +62,8 @@ public class BlobEmitter extends Emitter {
if (cell < Dungeon.level.heroFOV.length if (cell < Dungeon.level.heroFOV.length
&& (Dungeon.level.heroFOV[cell] || blob.alwaysVisible) && (Dungeon.level.heroFOV[cell] || blob.alwaysVisible)
&& map[cell] > 0) { && map[cell] > 0) {
float x = (i + Random.Float()) * size; float x = (i + Random.Float(bound.left, bound.right)) * size;
float y = (j + Random.Float()) * size; float y = (j + Random.Float(bound.top, bound.bottom)) * size;
factory.emit(this, index, x, y); factory.emit(this, index, x, y);
} }
} }

View File

@ -650,13 +650,6 @@ public class GameScene extends PixelScene {
add( new WndGame() ); add( new WndGame() );
} }
} }
@Override
protected void onMenuPressed() {
if (Dungeon.hero.ready) {
selectItem( null, WndBag.Mode.ALL, null );
}
}
public void addCustomTile( CustomTilemap visual){ public void addCustomTile( CustomTilemap visual){
customTiles.add( visual.create() ); customTiles.add( visual.create() );

View File

@ -180,10 +180,12 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
if (args.length > 0) { if (args.length > 0) {
text = Messages.format( text, args ); text = Messages.format( text, args );
} }
float x = destinationCenter().x;
float y = destinationCenter().y - height()/2f;
if (ch != null) { if (ch != null) {
FloatingText.show( x + width() * 0.5f, y, ch.pos, text, color ); FloatingText.show( x, y, ch.pos, text, color );
} else { } else {
FloatingText.show( x + width() * 0.5f, y, text, color ); FloatingText.show( x, y, text, color );
} }
} }
} }

View File

@ -160,10 +160,6 @@ public class Window extends Group implements Signal.Listener<KeyEvent> {
if (event.pressed) { if (event.pressed) {
if (KeyBindings.getActionForKey( event ) == SPDAction.BACK){ if (KeyBindings.getActionForKey( event ) == SPDAction.BACK){
onBackPressed(); onBackPressed();
} else if (KeyBindings.getActionForKey( event ) == SPDAction.MENU){
onMenuPressed();
} }
} }
@ -175,7 +171,5 @@ public class Window extends Group implements Signal.Listener<KeyEvent> {
public void onBackPressed() { public void onBackPressed() {
hide(); hide();
} }
public void onMenuPressed() {
}
} }

View File

@ -23,6 +23,7 @@ package com.shatteredpixel.shatteredpixeldungeon.windows;
import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.SPDAction;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Belongings; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Belongings;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.items.EquipableItem; import com.shatteredpixel.shatteredpixeldungeon.items.EquipableItem;
@ -55,6 +56,8 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.ItemSlot;
import com.shatteredpixel.shatteredpixeldungeon.ui.QuickSlotButton; import com.shatteredpixel.shatteredpixeldungeon.ui.QuickSlotButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextBlock; import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextBlock;
import com.watabou.gltextures.TextureCache; import com.watabou.gltextures.TextureCache;
import com.watabou.input.KeyBindings;
import com.watabou.input.KeyEvent;
import com.watabou.noosa.BitmapText; import com.watabou.noosa.BitmapText;
import com.watabou.noosa.ColorBlock; import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.Game; import com.watabou.noosa.Game;
@ -244,11 +247,14 @@ public class WndBag extends WndTabbed {
count++; count++;
} }
@Override @Override
public void onMenuPressed() { public boolean onSignal(KeyEvent event) {
if (listener == null) { if (event.pressed && KeyBindings.getActionForKey( event ) == SPDAction.INVENTORY) {
hide(); hide();
return true;
} else {
return super.onSignal(event);
} }
} }

View File

@ -99,8 +99,8 @@ public class WndKeyBindings extends Window {
int y = 0; int y = 0;
for (GameAction action : GameAction.allActions()){ for (GameAction action : GameAction.allActions()){
//start at 3. No bindings for NONE, BACK, and MENU atm //start at 1. No bindings for NONE
if (action.code() < 3) continue; if (action.code() < 1) continue;
BindingItem item = new BindingItem(action); BindingItem item = new BindingItem(action);
item.setRect(0, y, WIDTH, BindingItem.HEIGHT); item.setRect(0, y, WIDTH, BindingItem.HEIGHT);
@ -192,7 +192,7 @@ public class WndKeyBindings extends Window {
actionName.setHightlighting(false); actionName.setHightlighting(false);
add(actionName); add(actionName);
ArrayList<Integer> keys = KeyBindings.getKeysForAction(action); ArrayList<Integer> keys = KeyBindings.getBoundKeysForAction(action);
origKey1 = key1 = keys.isEmpty() ? 0 : keys.remove(0); origKey1 = key1 = keys.isEmpty() ? 0 : keys.remove(0);
origKey2 = key2 = keys.isEmpty() ? 0 : keys.remove(0); origKey2 = key2 = keys.isEmpty() ? 0 : keys.remove(0);