v2.2.0: fixed combined direction key actions not always being adjacent
This commit is contained in:
@@ -72,6 +72,14 @@ public class Point {
|
||||
y += d.y;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isZero(){
|
||||
return x == 0 && y == 0;
|
||||
}
|
||||
|
||||
public float length() {
|
||||
return (float)Math.sqrt( x * x + y * y );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( Object obj ) {
|
||||
|
||||
@@ -116,7 +116,11 @@ public class PointF {
|
||||
public Point floor() {
|
||||
return new Point( (int)x, (int)y );
|
||||
}
|
||||
|
||||
|
||||
public boolean isZero(){
|
||||
return x == 0 && y == 0;
|
||||
}
|
||||
|
||||
public float length() {
|
||||
return (float)Math.sqrt( x * x + y * y );
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ import com.watabou.noosa.Camera;
|
||||
import com.watabou.noosa.Game;
|
||||
import com.watabou.noosa.ScrollArea;
|
||||
import com.watabou.utils.GameMath;
|
||||
import com.watabou.utils.Point;
|
||||
import com.watabou.utils.PointF;
|
||||
import com.watabou.utils.Signal;
|
||||
|
||||
@@ -325,7 +326,7 @@ public class CellSelector extends ScrollArea {
|
||||
heldDelay = initialDelay();
|
||||
}
|
||||
|
||||
} else if (directionFromAction(action) != 0) {
|
||||
} else if (!directionFromAction(action).isZero()) {
|
||||
|
||||
Dungeon.hero.resting = false;
|
||||
lastCellMoved = -1;
|
||||
@@ -396,10 +397,14 @@ public class CellSelector extends ScrollArea {
|
||||
return false;
|
||||
}
|
||||
|
||||
int cell = Dungeon.hero.pos;
|
||||
Point direction = new Point();
|
||||
for (GameAction action : actions) {
|
||||
cell += directionFromAction(action);
|
||||
direction.offset(directionFromAction(action));
|
||||
}
|
||||
int cell = Dungeon.hero.pos;
|
||||
//clamp to adjacent values (-1 to +1)
|
||||
cell += GameMath.gate(-1, direction.x, +1);
|
||||
cell += GameMath.gate(-1, direction.y, +1) * Dungeon.level.width();
|
||||
|
||||
if (cell != Dungeon.hero.pos && cell != lastCellMoved){
|
||||
lastCellMoved = cell;
|
||||
@@ -414,16 +419,16 @@ public class CellSelector extends ScrollArea {
|
||||
|
||||
}
|
||||
|
||||
private int directionFromAction(GameAction action){
|
||||
if (action == SPDAction.N) return -Dungeon.level.width();
|
||||
if (action == SPDAction.NE) return +1-Dungeon.level.width();
|
||||
if (action == SPDAction.E) return +1;
|
||||
if (action == SPDAction.SE) return +1+Dungeon.level.width();
|
||||
if (action == SPDAction.S) return +Dungeon.level.width();
|
||||
if (action == SPDAction.SW) return -1+Dungeon.level.width();
|
||||
if (action == SPDAction.W) return -1;
|
||||
if (action == SPDAction.NW) return -1-Dungeon.level.width();
|
||||
else return 0;
|
||||
private Point directionFromAction(GameAction action){
|
||||
if (action == SPDAction.N) return new Point( 0, -1);
|
||||
if (action == SPDAction.NE) return new Point(+1, -1);
|
||||
if (action == SPDAction.E) return new Point(+1, 0);
|
||||
if (action == SPDAction.SE) return new Point(+1, +1);
|
||||
if (action == SPDAction.S) return new Point( 0, +1);
|
||||
if (action == SPDAction.SW) return new Point(-1, +1);;
|
||||
if (action == SPDAction.W) return new Point(-1, 0);
|
||||
if (action == SPDAction.NW) return new Point(-1, -1);
|
||||
else return new Point();
|
||||
}
|
||||
|
||||
//~80% deadzone
|
||||
@@ -454,13 +459,13 @@ public class CellSelector extends ScrollArea {
|
||||
|
||||
public void processKeyHold() {
|
||||
//prioritize moving by controller stick over moving via keys
|
||||
if (directionFromAction(leftStickAction) != 0 && heldDelay < 0) {
|
||||
if (!directionFromAction(leftStickAction).isZero() && heldDelay < 0) {
|
||||
enabled = Dungeon.hero.ready = true;
|
||||
Dungeon.observe();
|
||||
if (moveFromActions(leftStickAction)) {
|
||||
Dungeon.hero.ready = false;
|
||||
}
|
||||
} else if (directionFromAction(heldAction1) + directionFromAction(heldAction2) != 0
|
||||
} else if (!(directionFromAction(heldAction1).offset(directionFromAction(heldAction2)).isZero())
|
||||
&& heldDelay <= 0){
|
||||
enabled = Dungeon.hero.ready = true;
|
||||
Dungeon.observe();
|
||||
|
||||
Reference in New Issue
Block a user