From 2ec6e414d322430a72a85c56cf754507288f9778 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Tue, 27 Dec 2016 18:55:29 -0500 Subject: [PATCH] v0.5.0: added wall assist for tapping --- .../scenes/CellSelector.java | 3 +- .../tiles/DungeonTilemap.java | 40 ++++++++++++++----- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/CellSelector.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/CellSelector.java index b8059dba5..c08fc0bf0 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/CellSelector.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/CellSelector.java @@ -54,7 +54,8 @@ public class CellSelector extends TouchArea { select( ((DungeonTilemap)target).screenToTile( (int)touch.current.x, - (int)touch.current.y ) ); + (int)touch.current.y, + true ) ); } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/tiles/DungeonTilemap.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/tiles/DungeonTilemap.java index dfcff0dfd..411542f1f 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/tiles/DungeonTilemap.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/tiles/DungeonTilemap.java @@ -72,17 +72,37 @@ public abstract class DungeonTilemap extends Tilemap { protected abstract int getTileVisual(int pos, int tile, boolean flat); - public int screenToTile(int x, int y ) { - Point p = camera().screenToCamera( x, y ). + public int screenToTile(int x, int y ){ + return screenToTile(x, y, false); + } + + //wall assist is used to make raised perspective tapping a bit easier. + // If the pressed tile is a wall tile, the tap can be 'bumped' down into a none-wall tile. + // currently this happens if the bottom 1/4 of the wall tile is pressed. + public int screenToTile(int x, int y, boolean wallAssist ) { + PointF p = camera().screenToCamera( x, y ). offset( this.point().negate() ). - invScale( SIZE ). - floor(); - return p.x >= 0 - && p.x < Dungeon.level.width() - && p.y >= 0 - && p.y < Dungeon.level.height() ? - p.x + p.y * Dungeon.level.width() - : -1; + invScale( SIZE ); + if (p.x < 0 || p.x >= Dungeon.level.width() + || p.y < 0 + || p.y >= Dungeon.level.height()) + return -1; + + int cell = (int)p.x + (int)p.y * Dungeon.level.width(); + + if (wallAssist + && map != null + && DungeonTileSheet.wallStitcheable.contains(map[cell])){ + + if (cell + mapWidth < size + && p.y % 1 >= 0.75f + && !DungeonTileSheet.wallStitcheable.contains(map[cell + mapWidth])){ + cell += mapWidth; + } + + } + + return cell; } @Override