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 BACK = new GameAction( "back" );
public static final GameAction MENU = new GameAction( "menu" );
public static ArrayList<GameAction> allActions(){
return new ArrayList<>(ALL_ACTIONS);

View File

@ -32,14 +32,6 @@ public class KeyBindings {
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(){
return new LinkedHashMap<>(bindings);
}
@ -48,20 +40,32 @@ public class KeyBindings {
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 isKeyBound(int keyCode){
if (keyCode <= 0 || keyCode > 255){
return false;
}
return acceptUnbound || bindings.containsKey( keyCode );
return acceptUnbound || bindings.containsKey( keyCode ) || hardBindings.containsKey( keyCode );
}
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<>();
for( int i : bindings.keySet()){
if (bindings.get(i) == action){
@ -76,6 +80,10 @@ public class KeyBindings {
return "None";
} else if (keyCode == Input.Keys.PLUS){
return "+";
} else if (keyCode == Input.Keys.BACKSPACE) {
return "Backspace";
} else if (keyCode == Input.Keys.FORWARD_DEL) {
return "Delete";
} else {
return Input.Keys.toString(keyCode);
}

View File

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

View File

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

View File

@ -38,9 +38,7 @@ public class SPDAction extends GameAction {
//--New references to existing actions from GameAction
public static final GameAction NONE = GameAction.NONE;
public static final GameAction BACK = GameAction.BACK;
public static final GameAction MENU = GameAction.MENU;
//--
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<>();
static {
defaultBindings.put( Input.Keys.BACK, SPDAction.BACK );
defaultBindings.put( Input.Keys.MENU, SPDAction.MENU );
defaultBindings.put( Input.Keys.ESCAPE, SPDAction.BACK );
defaultBindings.put( Input.Keys.BACKSPACE, SPDAction.BACK );
defaultBindings.put( Input.Keys.H, SPDAction.HERO_INFO );
defaultBindings.put( Input.Keys.J, SPDAction.JOURNAL );
@ -120,6 +118,12 @@ public class SPDAction extends GameAction {
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.
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 ) {
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;
@ -873,7 +875,10 @@ public class Hero extends Char {
private boolean actAscend( HeroAction.Ascend action ) {
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) {

View File

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

View File

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

View File

@ -180,10 +180,12 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
if (args.length > 0) {
text = Messages.format( text, args );
}
float x = destinationCenter().x;
float y = destinationCenter().y - height()/2f;
if (ch != null) {
FloatingText.show( x + width() * 0.5f, y, ch.pos, text, color );
FloatingText.show( x, y, ch.pos, text, color );
} 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 (KeyBindings.getActionForKey( event ) == SPDAction.BACK){
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() {
hide();
}
public void onMenuPressed() {
}
}

View File

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

View File

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