fixed buggy controls
This commit is contained in:
@@ -49,7 +49,7 @@ public final class Res {
|
||||
private static void loadFonts()
|
||||
{
|
||||
fonts.loadFont("polygon_pixel", new DeferredFont("/res/font/PolygonPixel5x7Standard.ttf", Glyphs.basic, 16));
|
||||
fonts.loadFont("press_start", new DeferredFont("/res/font/PressStart2P.ttf", Glyphs.basic, 16));
|
||||
fonts.loadFont("press_start", new DeferredFont("/res/font/PressStart2P.ttf", Glyphs.latin, 16));
|
||||
|
||||
// aliases based on concrete usage
|
||||
fonts.addAlias("default", "polygon_pixel");
|
||||
|
||||
@@ -11,8 +11,10 @@ import mightypork.gamecore.gui.screens.Screen;
|
||||
import mightypork.gamecore.gui.screens.ScreenLayer;
|
||||
import mightypork.gamecore.util.math.color.pal.COMMODORE;
|
||||
import mightypork.gamecore.util.math.color.pal.PAL16;
|
||||
import mightypork.gamecore.util.math.color.pal.RGB;
|
||||
import mightypork.gamecore.util.math.constraints.num.Num;
|
||||
import mightypork.gamecore.util.math.constraints.rect.Rect;
|
||||
import mightypork.gamecore.util.math.constraints.vect.Vect;
|
||||
import mightypork.rogue.Res;
|
||||
|
||||
|
||||
@@ -40,7 +42,8 @@ class MenuLayer extends ScreenLayer {
|
||||
root.add(layout);
|
||||
|
||||
int r = 0;
|
||||
final TextPainter tp = new TextPainter(Res.getFont("main_menu_title"), AlignX.CENTER, COMMODORE.PURPLE, "Rogue!");
|
||||
final TextPainter tp = new TextPainter(Res.getFont("main_menu_title"), AlignX.CENTER, COMMODORE.PURPLE, "Rats");
|
||||
tp.setShadow(RGB.BLACK.withAlpha(0.6), Vect.make(tp.height().div(16)));
|
||||
layout.put(tp, r, 0, 3, 1);
|
||||
r += 5;
|
||||
|
||||
@@ -62,7 +65,7 @@ class MenuLayer extends ScreenLayer {
|
||||
|
||||
|
||||
// bouncy text button
|
||||
btn = new MenuButton("Bouncy Cubes Test", PAL16.CLOUDBLUE);
|
||||
btn = new MenuButton("Bouncy", PAL16.CLOUDBLUE);
|
||||
btn.setAction(new Action() {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -38,7 +38,7 @@ public abstract class PlayerControl {
|
||||
};
|
||||
|
||||
|
||||
private Entity getPlayerEntity()
|
||||
public Entity getPlayerEntity()
|
||||
{
|
||||
if (getWorld2() == null) return null;
|
||||
|
||||
@@ -103,16 +103,14 @@ public abstract class PlayerControl {
|
||||
return getLevel().getTile(getCoord().add(side)).isWalkable();
|
||||
}
|
||||
|
||||
|
||||
public boolean clickTile(Step side)
|
||||
{
|
||||
return clickTile(getCoord().add(side));
|
||||
}
|
||||
|
||||
|
||||
public boolean clickTile(Coord pos)
|
||||
{
|
||||
if (pos.dist(getCoord()) > 8) return false; // too far
|
||||
if(pos.dist(getCoord()) > 8) return false; // too far
|
||||
|
||||
return getLevel().getTile(pos).onClick();
|
||||
}
|
||||
|
||||
@@ -204,5 +204,11 @@ public class EntityModulePosition extends EntityModule {
|
||||
{
|
||||
return entityPos.getVisualPos();
|
||||
}
|
||||
|
||||
|
||||
public boolean isMoving()
|
||||
{
|
||||
return walking;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ package mightypork.rogue.world.gen;
|
||||
import java.util.Random;
|
||||
|
||||
import mightypork.gamecore.util.math.algo.Coord;
|
||||
import mightypork.rogue.world.gen.rooms.DeadEndRoom;
|
||||
import mightypork.rogue.world.gen.rooms.Rooms;
|
||||
import mightypork.rogue.world.gen.themes.ThemeBrick;
|
||||
import mightypork.rogue.world.level.Level;
|
||||
|
||||
@@ -21,7 +21,7 @@ public interface MapTheme {
|
||||
|
||||
|
||||
TileModel passage();
|
||||
|
||||
|
||||
|
||||
|
||||
TileModel secretDoor();
|
||||
}
|
||||
|
||||
@@ -42,8 +42,8 @@ public class ScratchMap {
|
||||
@Override
|
||||
public boolean isAccessible(Coord pos)
|
||||
{
|
||||
if (!isIn(pos)) return false;
|
||||
final Tile t = get(pos);
|
||||
if(!isIn(pos)) return false;
|
||||
Tile t = get(pos);
|
||||
return t.isPotentiallyWalkable() || (t.genData.protection != TileProtectLevel.STRONG);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,15 +21,15 @@ public abstract class AbstractRectRoom implements RoomBuilder {
|
||||
{
|
||||
// half width, half height actually
|
||||
final Coord innerSize = getInnerSize(rand);
|
||||
final int width = 2 + innerSize.x;
|
||||
final int height = 2 + innerSize.y;
|
||||
final int width = 2+innerSize.x;
|
||||
final int height = 2+innerSize.y;
|
||||
|
||||
final int wLow = width / 2;
|
||||
final int wHigh = width - wLow;
|
||||
final int hLow = height / 2;
|
||||
final int hHigh = height - hLow;
|
||||
int wLow = width/2;
|
||||
int wHigh = width - wLow;
|
||||
int hLow = height/2;
|
||||
int hHigh = height - hLow;
|
||||
|
||||
final Coord min = new Coord(center.x - wLow, center.y - hLow);
|
||||
final Coord min = new Coord(center.x-wLow, center.y-hLow);
|
||||
final Coord max = new Coord(center.x + wHigh, center.y + hHigh);
|
||||
|
||||
if (!map.isClear(min.add(-1, -1), max)) return null;
|
||||
@@ -48,8 +48,8 @@ public abstract class AbstractRectRoom implements RoomBuilder {
|
||||
|
||||
protected void placeDoors(ScratchMap map, MapTheme theme, Random rand, Coord min, Coord max)
|
||||
{
|
||||
final int width = max.x - min.x;
|
||||
final int height = max.y - min.y;
|
||||
int width = max.x - min.x;
|
||||
int height = max.y - min.y;
|
||||
|
||||
for (int i = 0, j = 0; i <= getDoorCount(rand) && j < 100; j++) { // j is to prevent inf loop
|
||||
final Coord door = min.copy();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package mightypork.rogue.world.gui;
|
||||
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -21,6 +22,7 @@ import mightypork.rogue.world.WorldProvider;
|
||||
import mightypork.rogue.world.WorldRenderer;
|
||||
import mightypork.rogue.world.entity.modules.EntityMoveListener;
|
||||
import mightypork.rogue.world.gui.interaction.MapInteractionPlugin;
|
||||
import mightypork.rogue.world.tile.Tile;
|
||||
|
||||
|
||||
/**
|
||||
@@ -71,7 +73,7 @@ public class MapView extends InputComponent implements KeyListener, MouseButtonL
|
||||
public void onStepFinished()
|
||||
{
|
||||
for (final MapInteractionPlugin p : plugins) {
|
||||
if (p.onStepEnd(this, pc)) break;
|
||||
if(p.onStepEnd(this, pc)) break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +82,7 @@ public class MapView extends InputComponent implements KeyListener, MouseButtonL
|
||||
public void onPathFinished()
|
||||
{
|
||||
for (final MapInteractionPlugin p : plugins) {
|
||||
if (p.onStepEnd(this, pc)) break;
|
||||
if(p.onStepEnd(this, pc)) break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +91,7 @@ public class MapView extends InputComponent implements KeyListener, MouseButtonL
|
||||
public void onPathInterrupted()
|
||||
{
|
||||
for (final MapInteractionPlugin p : plugins) {
|
||||
if (p.onStepEnd(this, pc)) break;
|
||||
if(p.onStepEnd(this, pc)) break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +102,7 @@ public class MapView extends InputComponent implements KeyListener, MouseButtonL
|
||||
if (!event.isOver(this)) return;
|
||||
|
||||
for (final MapInteractionPlugin p : plugins) {
|
||||
if (p.onClick(this, pc, event.getPos(), event.getButton(), event.isDown())) {
|
||||
if(p.onClick(this, pc, event.getPos(), event.getButton(), event.isDown())) {
|
||||
event.consume();
|
||||
break;
|
||||
}
|
||||
@@ -112,7 +114,7 @@ public class MapView extends InputComponent implements KeyListener, MouseButtonL
|
||||
public void receive(KeyEvent event)
|
||||
{
|
||||
for (final MapInteractionPlugin p : plugins) {
|
||||
if (p.onKey(this, pc, event.getKey(), event.isDown())) break;
|
||||
if(p.onKey(this, pc, event.getKey(), event.isDown())) break;
|
||||
}
|
||||
|
||||
if (event.getKey() == Keys.Z) {
|
||||
|
||||
@@ -34,7 +34,7 @@ public class Minimap extends InputComponent implements MouseButtonListener {
|
||||
Color.pushAlpha(translucency);
|
||||
|
||||
final Level lvl = WorldProvider.get().getCurrentLevel();
|
||||
unit = (int) Math.min(Math.max(2, Math.ceil((height().value() / 2) / (lvl.getHeight() + 2))), 6);
|
||||
unit = (int) Math.min(Math.max(2, Math.ceil((height().value() / 2) / (lvl.getHeight() + 2))), 10);
|
||||
|
||||
final Entity e = WorldProvider.get().getPlayerEntity();
|
||||
final Vect plCoord = e.pos.getVisualPos();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package mightypork.rogue.world.gui.interaction;
|
||||
|
||||
|
||||
import mightypork.gamecore.input.InputSystem;
|
||||
import mightypork.gamecore.util.math.algo.Coord;
|
||||
import mightypork.gamecore.util.math.constraints.vect.Vect;
|
||||
import mightypork.rogue.world.PlayerControl;
|
||||
@@ -14,12 +15,13 @@ public class MIPClickPathfWalk implements MapInteractionPlugin {
|
||||
|
||||
|
||||
@Override
|
||||
public void update(MapView view, PlayerControl player, double delta)
|
||||
public void update(MapView view, PlayerControl pc, double delta)
|
||||
{
|
||||
// if (InputSystem.isMouseButtonDown(BTN)) {
|
||||
//
|
||||
// troToNav(view, player, InputSystem.getMousePos());
|
||||
// }
|
||||
if(pc.getPlayerEntity().pos.isMoving()) return;
|
||||
if (InputSystem.isMouseButtonDown(BTN)) {
|
||||
|
||||
troToNav(view, pc, InputSystem.getMousePos());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,13 +32,13 @@ public class MIPClickPathfWalk implements MapInteractionPlugin {
|
||||
|
||||
return troToNav(view, player, mouse);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private boolean troToNav(MapView view, PlayerControl player, Vect mouse)
|
||||
{
|
||||
final Coord clicked = view.toWorldPos(mouse);
|
||||
|
||||
final Tile t = player.getLevel().getTile(clicked);
|
||||
Tile t = player.getLevel().getTile(clicked);
|
||||
if (!t.isWalkable() || !t.isExplored()) return false;
|
||||
|
||||
player.navigateTo(clicked);
|
||||
@@ -49,8 +51,8 @@ public class MIPClickPathfWalk implements MapInteractionPlugin {
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onStepEnd(MapView mapView, PlayerControl player)
|
||||
{
|
||||
|
||||
@@ -12,6 +12,10 @@ import mightypork.rogue.world.gui.MapView;
|
||||
|
||||
public class MIPKeyWalk implements MapInteractionPlugin {
|
||||
|
||||
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 };
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onStepEnd(MapView view, PlayerControl player)
|
||||
{
|
||||
@@ -29,27 +33,32 @@ public class MIPKeyWalk implements MapInteractionPlugin {
|
||||
@Override
|
||||
public boolean onKey(MapView view, PlayerControl player, int key, boolean down)
|
||||
{
|
||||
if (down) return walkByKey(player);
|
||||
if(down) return false; // not interested
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (key == keys[i]) {
|
||||
return player.clickTile(sides[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private boolean walkByKey(PlayerControl player)
|
||||
private boolean walkByKey(PlayerControl pc)
|
||||
{
|
||||
final int[] keys = { Keys.LEFT, Keys.RIGHT, Keys.UP, Keys.DOWN };
|
||||
final Step[] sides = { Sides.W, Sides.E, Sides.N, Sides.S };
|
||||
if(pc.getPlayerEntity().pos.isMoving()) return false;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (InputSystem.isKeyDown(keys[i])) {
|
||||
|
||||
final Step side = sides[i];
|
||||
if (player.canGo(side)) {
|
||||
player.go(side);
|
||||
Step side = sides[i];
|
||||
if (pc.canGo(side)) {
|
||||
pc.go(side);
|
||||
return true;
|
||||
} else {
|
||||
return player.clickTile(side);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -59,5 +68,6 @@ public class MIPKeyWalk implements MapInteractionPlugin {
|
||||
@Override
|
||||
public void update(MapView mapView, PlayerControl pc, double delta)
|
||||
{
|
||||
walkByKey(pc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,24 +14,31 @@ import mightypork.rogue.world.tile.Tile;
|
||||
public class MIPMouseWalk implements MapInteractionPlugin {
|
||||
|
||||
@Override
|
||||
public void update(MapView world, PlayerControl player, double delta)
|
||||
public void update(MapView view, PlayerControl pc, double delta)
|
||||
{
|
||||
if (InputSystem.isMouseButtonDown(0)) {
|
||||
// walk by holding btn
|
||||
onClick(world, player, InputSystem.getMousePos(), 0, true);
|
||||
tryWalk(view, pc, InputSystem.getMousePos());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onClick(MapView world, PlayerControl player, Vect mouse, int button, boolean down)
|
||||
public boolean onClick(MapView view, PlayerControl pc, Vect mouse, int button, boolean down)
|
||||
{
|
||||
if (!down || button != 0) return false;
|
||||
|
||||
final Coord plpos = player.getCoord();
|
||||
final Coord clicked = world.toWorldPos(mouse);
|
||||
tryWalk(view, pc, mouse);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private void tryWalk(MapView view, PlayerControl pc, Vect pos)
|
||||
{
|
||||
if (pc.getPlayerEntity().pos.isMoving()) return;
|
||||
|
||||
final Tile t = player.getLevel().getTile(clicked);
|
||||
final Coord plpos = pc.getCoord();
|
||||
final Coord clicked = view.toWorldPos(pos);
|
||||
|
||||
final Polar p = Polar.fromCoord(clicked.x - plpos.x, clicked.y - plpos.y);
|
||||
|
||||
@@ -39,22 +46,21 @@ public class MIPMouseWalk implements MapInteractionPlugin {
|
||||
|
||||
switch (dir) {
|
||||
case 0:
|
||||
player.goEast();
|
||||
pc.goEast();
|
||||
break;
|
||||
|
||||
case 1:
|
||||
player.goSouth();
|
||||
pc.goSouth();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
player.goWest();
|
||||
pc.goWest();
|
||||
break;
|
||||
|
||||
case 3:
|
||||
player.goNorth();
|
||||
pc.goNorth();
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -66,9 +72,12 @@ public class MIPMouseWalk implements MapInteractionPlugin {
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onStepEnd(MapView mapView, PlayerControl player)
|
||||
public boolean onStepEnd(MapView view, PlayerControl pc)
|
||||
{
|
||||
return false;
|
||||
if(!InputSystem.isMouseButtonDown(0)) return false;
|
||||
|
||||
tryWalk(view, pc, InputSystem.getMousePos());
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ package mightypork.rogue.world.gui.interaction;
|
||||
import mightypork.gamecore.util.math.algo.Coord;
|
||||
import mightypork.gamecore.util.math.constraints.vect.Vect;
|
||||
import mightypork.rogue.world.PlayerControl;
|
||||
import mightypork.rogue.world.WorldProvider;
|
||||
import mightypork.rogue.world.gui.MapView;
|
||||
|
||||
|
||||
@@ -19,9 +20,10 @@ public class MIPTileClick implements MapInteractionPlugin {
|
||||
@Override
|
||||
public boolean onClick(MapView wv, PlayerControl player, Vect mouse, int button, boolean down)
|
||||
{
|
||||
if (down && button == 1) { // right button
|
||||
final Coord pos = wv.toWorldPos(mouse);
|
||||
if (!down && button == 0) {
|
||||
Coord pos = wv.toWorldPos(mouse);
|
||||
player.clickTile(pos);
|
||||
System.out.println("~");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -35,7 +37,6 @@ public class MIPTileClick implements MapInteractionPlugin {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update(MapView mapView, PlayerControl pc, double delta)
|
||||
{
|
||||
|
||||
@@ -15,8 +15,8 @@ public interface MapInteractionPlugin {
|
||||
|
||||
|
||||
boolean onKey(MapView mapView, PlayerControl player, int key, boolean down);
|
||||
|
||||
|
||||
void update(MapView mapView, PlayerControl pc, double delta);
|
||||
|
||||
|
||||
void update(MapView mapView, PlayerControl pc, double delta);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package mightypork.rogue.world.tile;
|
||||
|
||||
|
||||
import mightypork.rogue.world.gen.TileProtectLevel;
|
||||
|
||||
|
||||
|
||||
@@ -27,8 +27,7 @@ public final class Tiles {
|
||||
public static final TileModel BRICK_WALL = new TileModel(11, WallTile.class, new BasicTileRenderer("tile.brick.wall"));
|
||||
public static final TileModel BRICK_DOOR = new TileModel(12, DoorTile.class, new DoorRenderer("tile.brick.door.closed", "tile.brick.door.open"));
|
||||
public static final TileModel BRICK_PASSAGE = new TileModel(13, WallPassageTile.class, new BasicTileRenderer("tile.brick.passage"));
|
||||
public static final TileModel BRICK_HIDDEN_DOOR = new TileModel(14, SecretDoorTile.class, new LockedDoorRenderer("tile.brick.door.secret",
|
||||
"tile.brick.door.closed", "tile.brick.door.open"));
|
||||
public static final TileModel BRICK_HIDDEN_DOOR = new TileModel(14, SecretDoorTile.class, new LockedDoorRenderer("tile.brick.door.secret", "tile.brick.door.closed", "tile.brick.door.open"));
|
||||
|
||||
|
||||
public static void register(int id, TileModel model)
|
||||
|
||||
@@ -7,6 +7,7 @@ import mightypork.gamecore.util.math.constraints.rect.Rect;
|
||||
import mightypork.rogue.Res;
|
||||
import mightypork.rogue.world.level.render.TileRenderContext;
|
||||
import mightypork.rogue.world.tile.Tile;
|
||||
import mightypork.rogue.world.tile.TileRenderer;
|
||||
|
||||
|
||||
public class LockedDoorRenderer extends DoorRenderer {
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
package mightypork.rogue.world.tile.tiles;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import mightypork.gamecore.util.ion.IonInput;
|
||||
import mightypork.gamecore.util.ion.IonOutput;
|
||||
import mightypork.gamecore.util.math.color.Color;
|
||||
import mightypork.gamecore.util.math.timing.TimedTask;
|
||||
import mightypork.rogue.world.level.Level;
|
||||
import mightypork.rogue.world.tile.TileModel;
|
||||
import mightypork.rogue.world.tile.TileRenderer;
|
||||
import mightypork.rogue.world.tile.TileType;
|
||||
@@ -9,6 +15,9 @@ import mightypork.rogue.world.tile.TileType;
|
||||
|
||||
public class SecretDoorTile extends LockedDoorTile {
|
||||
|
||||
private int clicks = 2 + rand.nextInt(2);
|
||||
|
||||
|
||||
public SecretDoorTile(TileModel model, TileRenderer renderer)
|
||||
{
|
||||
super(model, renderer);
|
||||
@@ -20,7 +29,9 @@ public class SecretDoorTile extends LockedDoorTile {
|
||||
{
|
||||
if (!locked) return false;
|
||||
|
||||
locked = false;
|
||||
if (clicks > 0) clicks--;
|
||||
|
||||
if (clicks == 0) locked = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -32,4 +43,20 @@ public class SecretDoorTile extends LockedDoorTile {
|
||||
if (locked) return TileType.WALL.getMapColor();
|
||||
return super.getMapColor();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void save(IonOutput out) throws IOException
|
||||
{
|
||||
super.save(out);
|
||||
out.writeIntByte(clicks);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void load(IonInput in) throws IOException
|
||||
{
|
||||
super.load(in);
|
||||
clicks = in.readIntByte();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user