You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.5 KiB
74 lines
1.5 KiB
10 years ago
|
package mightypork.rogue.world.gui.interaction;
|
||
10 years ago
|
|
||
|
|
||
|
import mightypork.gamecore.input.InputSystem;
|
||
|
import mightypork.gamecore.input.Keys;
|
||
10 years ago
|
import mightypork.gamecore.util.math.algo.Sides;
|
||
|
import mightypork.gamecore.util.math.algo.Step;
|
||
10 years ago
|
import mightypork.gamecore.util.math.constraints.vect.Vect;
|
||
10 years ago
|
import mightypork.rogue.world.PlayerControl;
|
||
10 years ago
|
import mightypork.rogue.world.gui.MapView;
|
||
10 years ago
|
|
||
|
|
||
10 years ago
|
public class MIPKeyboard implements MapInteractionPlugin {
|
||
10 years ago
|
|
||
10 years ago
|
private static final int[] keys = { Keys.LEFT, Keys.RIGHT, Keys.UP, Keys.DOWN };
|
||
|
private static final Step[] sides = { Sides.W, Sides.E, Sides.N, Sides.S };
|
||
|
|
||
|
|
||
10 years ago
|
@Override
|
||
10 years ago
|
public boolean onStepEnd(MapView view, PlayerControl player)
|
||
10 years ago
|
{
|
||
10 years ago
|
return walkByKey(player);
|
||
10 years ago
|
}
|
||
|
|
||
|
|
||
|
@Override
|
||
10 years ago
|
public boolean onClick(MapView view, PlayerControl player, Vect mouse, int button, boolean down)
|
||
10 years ago
|
{
|
||
10 years ago
|
return false;
|
||
10 years ago
|
}
|
||
|
|
||
|
|
||
|
@Override
|
||
10 years ago
|
public boolean onKey(MapView view, PlayerControl player, int key, boolean down)
|
||
10 years ago
|
{
|
||
10 years ago
|
if (down) return false; // not interested
|
||
10 years ago
|
|
||
|
for (int i = 0; i < 4; i++) {
|
||
|
if (key == keys[i]) {
|
||
|
return player.clickTile(sides[i]);
|
||
|
}
|
||
|
}
|
||
|
|
||
10 years ago
|
return false;
|
||
10 years ago
|
}
|
||
|
|
||
|
|
||
10 years ago
|
private boolean walkByKey(PlayerControl pc)
|
||
10 years ago
|
{
|
||
10 years ago
|
if (pc.getPlayerEntity().pos.isMoving()) return false;
|
||
10 years ago
|
|
||
|
for (int i = 0; i < 4; i++) {
|
||
|
if (InputSystem.isKeyDown(keys[i])) {
|
||
|
|
||
10 years ago
|
final Step side = sides[i];
|
||
10 years ago
|
if (pc.canGo(side)) {
|
||
|
pc.go(side);
|
||
10 years ago
|
return true;
|
||
|
} else {
|
||
10 years ago
|
return false;
|
||
10 years ago
|
}
|
||
|
}
|
||
10 years ago
|
}
|
||
10 years ago
|
return false;
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
|
||
|
@Override
|
||
|
public void update(MapView mapView, PlayerControl pc, double delta)
|
||
|
{
|
||
10 years ago
|
walkByKey(pc);
|
||
10 years ago
|
}
|
||
10 years ago
|
}
|