fixed buggy controls

v5stable
Ondřej Hruška 11 years ago
parent ecbb2c8615
commit 78035ced7a
  1. 2
      src/mightypork/gamecore/render/Render.java
  2. 3
      src/mightypork/gamecore/resources/fonts/Glyphs.java
  3. 2
      src/mightypork/gamecore/resources/fonts/impl/CachedFont.java
  4. 2
      src/mightypork/rogue/Res.java
  5. 7
      src/mightypork/rogue/screens/menu/MenuLayer.java
  6. 4
      src/mightypork/rogue/world/PlayerControl.java
  7. 6
      src/mightypork/rogue/world/entity/modules/EntityModulePosition.java
  8. 1
      src/mightypork/rogue/world/gen/LevelGenerator.java
  9. 2
      src/mightypork/rogue/world/gen/ScratchMap.java
  10. 12
      src/mightypork/rogue/world/gen/rooms/AbstractRectRoom.java
  11. 2
      src/mightypork/rogue/world/gui/MapView.java
  12. 2
      src/mightypork/rogue/world/gui/Minimap.java
  13. 14
      src/mightypork/rogue/world/gui/interaction/MIPClickPathfWalk.java
  14. 28
      src/mightypork/rogue/world/gui/interaction/MIPKeyWalk.java
  15. 35
      src/mightypork/rogue/world/gui/interaction/MIPMouseWalk.java
  16. 7
      src/mightypork/rogue/world/gui/interaction/MIPTileClick.java
  17. 1
      src/mightypork/rogue/world/tile/TileGenData.java
  18. 3
      src/mightypork/rogue/world/tile/Tiles.java
  19. 1
      src/mightypork/rogue/world/tile/renderers/LockedDoorRenderer.java
  20. 29
      src/mightypork/rogue/world/tile/tiles/SecretDoorTile.java

@ -455,7 +455,7 @@ public class Render {
final RectDigest q = quad.digest(); final RectDigest q = quad.digest();
final RectDigest u = txquad.uvs.digest(); final RectDigest u = txquad.uvs.digest();
final double offs = 0.0001;// hack to avoid white stitching double offs = 0.0001;// hack to avoid white stitching
double tL = u.left+offs, tR = u.right-offs, tT = u.top+offs, tB = u.bottom-offs; double tL = u.left+offs, tR = u.right-offs, tT = u.top+offs, tB = u.bottom-offs;

@ -8,7 +8,6 @@ package mightypork.gamecore.resources.fonts;
*/ */
public class Glyphs { public class Glyphs {
public static final String space = " ";
public static final String latin = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; public static final String latin = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
public static final String latin_extra = "ŒÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜŸÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿĚŠČŘŽŤŇĎŮěščřžťňďůŁłđ"; public static final String latin_extra = "ŒÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜŸÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿĚŠČŘŽŤŇĎŮěščřžťňďůŁłđ";
public static final String numbers = "0123456789"; public static final String numbers = "0123456789";
@ -17,7 +16,7 @@ public class Glyphs {
public static final String symbols = "[]{}#$%&§*+/<=>@\\^_|~°"; public static final String symbols = "[]{}#$%&§*+/<=>@\\^_|~°";
public static final String symbols_extra = "¥€£¢`ƒ†‡ˆ‰•¤¦¨ªº¹²³¬­¯±´µ¶·¸¼½¾×÷™©­®→↓←↑"; public static final String symbols_extra = "¥€£¢`ƒ†‡ˆ‰•¤¦¨ªº¹²³¬­¯±´µ¶·¸¼½¾×÷™©­®→↓←↑";
public static final String basic = space + latin + numbers + punctuation + symbols; public static final String basic = latin + numbers + punctuation + symbols;
public static final String extra = latin_extra + punctuation_extra + symbols_extra; public static final String extra = latin_extra + punctuation_extra + symbols_extra;
public static final String all = basic + extra; public static final String all = basic + extra;

@ -88,7 +88,7 @@ public class CachedFont implements GLFont {
*/ */
public CachedFont(java.awt.Font font, boolean antialias, FilterMode filter, String chars) public CachedFont(java.awt.Font font, boolean antialias, FilterMode filter, String chars)
{ {
this(font, antialias, filter, chars.toCharArray()); this(font, antialias, filter, (" "+chars).toCharArray());
} }

@ -49,7 +49,7 @@ public final class Res {
private static void loadFonts() private static void loadFonts()
{ {
fonts.loadFont("polygon_pixel", new DeferredFont("/res/font/PolygonPixel5x7Standard.ttf", Glyphs.basic, 16)); 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 // aliases based on concrete usage
fonts.addAlias("default", "polygon_pixel"); fonts.addAlias("default", "polygon_pixel");

@ -11,8 +11,10 @@ import mightypork.gamecore.gui.screens.Screen;
import mightypork.gamecore.gui.screens.ScreenLayer; import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.gamecore.util.math.color.pal.COMMODORE; import mightypork.gamecore.util.math.color.pal.COMMODORE;
import mightypork.gamecore.util.math.color.pal.PAL16; 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.num.Num;
import mightypork.gamecore.util.math.constraints.rect.Rect; import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.rogue.Res; import mightypork.rogue.Res;
@ -40,7 +42,8 @@ class MenuLayer extends ScreenLayer {
root.add(layout); root.add(layout);
int r = 0; 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); layout.put(tp, r, 0, 3, 1);
r += 5; r += 5;
@ -62,7 +65,7 @@ class MenuLayer extends ScreenLayer {
// bouncy text button // bouncy text button
btn = new MenuButton("Bouncy Cubes Test", PAL16.CLOUDBLUE); btn = new MenuButton("Bouncy", PAL16.CLOUDBLUE);
btn.setAction(new Action() { btn.setAction(new Action() {
@Override @Override

@ -38,7 +38,7 @@ public abstract class PlayerControl {
}; };
private Entity getPlayerEntity() public Entity getPlayerEntity()
{ {
if (getWorld2() == null) return null; if (getWorld2() == null) return null;
@ -103,13 +103,11 @@ public abstract class PlayerControl {
return getLevel().getTile(getCoord().add(side)).isWalkable(); return getLevel().getTile(getCoord().add(side)).isWalkable();
} }
public boolean clickTile(Step side) public boolean clickTile(Step side)
{ {
return clickTile(getCoord().add(side)); return clickTile(getCoord().add(side));
} }
public boolean clickTile(Coord pos) public boolean clickTile(Coord pos)
{ {
if(pos.dist(getCoord()) > 8) return false; // too far if(pos.dist(getCoord()) > 8) return false; // too far

@ -205,4 +205,10 @@ public class EntityModulePosition extends EntityModule {
return entityPos.getVisualPos(); return entityPos.getVisualPos();
} }
public boolean isMoving()
{
return walking;
}
} }

@ -4,6 +4,7 @@ package mightypork.rogue.world.gen;
import java.util.Random; import java.util.Random;
import mightypork.gamecore.util.math.algo.Coord; 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.rooms.Rooms;
import mightypork.rogue.world.gen.themes.ThemeBrick; import mightypork.rogue.world.gen.themes.ThemeBrick;
import mightypork.rogue.world.level.Level; import mightypork.rogue.world.level.Level;

@ -43,7 +43,7 @@ public class ScratchMap {
public boolean isAccessible(Coord pos) public boolean isAccessible(Coord pos)
{ {
if(!isIn(pos)) return false; if(!isIn(pos)) return false;
final Tile t = get(pos); Tile t = get(pos);
return t.isPotentiallyWalkable() || (t.genData.protection != TileProtectLevel.STRONG); return t.isPotentiallyWalkable() || (t.genData.protection != TileProtectLevel.STRONG);
} }

@ -24,10 +24,10 @@ public abstract class AbstractRectRoom implements RoomBuilder {
final int width = 2+innerSize.x; final int width = 2+innerSize.x;
final int height = 2+innerSize.y; final int height = 2+innerSize.y;
final int wLow = width / 2; int wLow = width/2;
final int wHigh = width - wLow; int wHigh = width - wLow;
final int hLow = height / 2; int hLow = height/2;
final int hHigh = height - hLow; 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); final Coord max = new Coord(center.x + wHigh, center.y + hHigh);
@ -48,8 +48,8 @@ public abstract class AbstractRectRoom implements RoomBuilder {
protected void placeDoors(ScratchMap map, MapTheme theme, Random rand, Coord min, Coord max) protected void placeDoors(ScratchMap map, MapTheme theme, Random rand, Coord min, Coord max)
{ {
final int width = max.x - min.x; int width = max.x - min.x;
final int height = max.y - min.y; int height = max.y - min.y;
for (int i = 0, j = 0; i <= getDoorCount(rand) && j < 100; j++) { // j is to prevent inf loop for (int i = 0, j = 0; i <= getDoorCount(rand) && j < 100; j++) { // j is to prevent inf loop
final Coord door = min.copy(); final Coord door = min.copy();

@ -1,6 +1,7 @@
package mightypork.rogue.world.gui; package mightypork.rogue.world.gui;
import java.util.HashSet;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Set; import java.util.Set;
@ -21,6 +22,7 @@ import mightypork.rogue.world.WorldProvider;
import mightypork.rogue.world.WorldRenderer; import mightypork.rogue.world.WorldRenderer;
import mightypork.rogue.world.entity.modules.EntityMoveListener; import mightypork.rogue.world.entity.modules.EntityMoveListener;
import mightypork.rogue.world.gui.interaction.MapInteractionPlugin; import mightypork.rogue.world.gui.interaction.MapInteractionPlugin;
import mightypork.rogue.world.tile.Tile;
/** /**

@ -34,7 +34,7 @@ public class Minimap extends InputComponent implements MouseButtonListener {
Color.pushAlpha(translucency); Color.pushAlpha(translucency);
final Level lvl = WorldProvider.get().getCurrentLevel(); 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 Entity e = WorldProvider.get().getPlayerEntity();
final Vect plCoord = e.pos.getVisualPos(); final Vect plCoord = e.pos.getVisualPos();

@ -1,6 +1,7 @@
package mightypork.rogue.world.gui.interaction; package mightypork.rogue.world.gui.interaction;
import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.util.math.algo.Coord; import mightypork.gamecore.util.math.algo.Coord;
import mightypork.gamecore.util.math.constraints.vect.Vect; import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.rogue.world.PlayerControl; import mightypork.rogue.world.PlayerControl;
@ -14,12 +15,13 @@ public class MIPClickPathfWalk implements MapInteractionPlugin {
@Override @Override
public void update(MapView view, PlayerControl player, double delta) public void update(MapView view, PlayerControl pc, double delta)
{ {
// if (InputSystem.isMouseButtonDown(BTN)) { if(pc.getPlayerEntity().pos.isMoving()) return;
// if (InputSystem.isMouseButtonDown(BTN)) {
// troToNav(view, player, InputSystem.getMousePos());
// } troToNav(view, pc, InputSystem.getMousePos());
}
} }
@ -36,7 +38,7 @@ public class MIPClickPathfWalk implements MapInteractionPlugin {
{ {
final Coord clicked = view.toWorldPos(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; if (!t.isWalkable() || !t.isExplored()) return false;
player.navigateTo(clicked); player.navigateTo(clicked);

@ -12,6 +12,10 @@ import mightypork.rogue.world.gui.MapView;
public class MIPKeyWalk implements MapInteractionPlugin { 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 @Override
public boolean onStepEnd(MapView view, PlayerControl player) public boolean onStepEnd(MapView view, PlayerControl player)
{ {
@ -29,27 +33,32 @@ public class MIPKeyWalk implements MapInteractionPlugin {
@Override @Override
public boolean onKey(MapView view, PlayerControl player, int key, boolean down) 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; return false;
} }
private boolean walkByKey(PlayerControl player) private boolean walkByKey(PlayerControl pc)
{ {
final int[] keys = { Keys.LEFT, Keys.RIGHT, Keys.UP, Keys.DOWN }; if(pc.getPlayerEntity().pos.isMoving()) return false;
final Step[] sides = { Sides.W, Sides.E, Sides.N, Sides.S };
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
if (InputSystem.isKeyDown(keys[i])) { if (InputSystem.isKeyDown(keys[i])) {
final Step side = sides[i]; Step side = sides[i];
if (player.canGo(side)) { if (pc.canGo(side)) {
player.go(side); pc.go(side);
return true; return true;
} else { } else {
return player.clickTile(side); return false;
} }
} }
} }
return false; return false;
@ -59,5 +68,6 @@ public class MIPKeyWalk implements MapInteractionPlugin {
@Override @Override
public void update(MapView mapView, PlayerControl pc, double delta) 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 { public class MIPMouseWalk implements MapInteractionPlugin {
@Override @Override
public void update(MapView world, PlayerControl player, double delta) public void update(MapView view, PlayerControl pc, double delta)
{ {
if (InputSystem.isMouseButtonDown(0)) { if (InputSystem.isMouseButtonDown(0)) {
// walk by holding btn // walk by holding btn
onClick(world, player, InputSystem.getMousePos(), 0, true); tryWalk(view, pc, InputSystem.getMousePos());
} }
} }
@Override @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; if (!down || button != 0) return false;
final Coord plpos = player.getCoord(); tryWalk(view, pc, mouse);
final Coord clicked = world.toWorldPos(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); final Polar p = Polar.fromCoord(clicked.x - plpos.x, clicked.y - plpos.y);
@ -39,22 +46,21 @@ public class MIPMouseWalk implements MapInteractionPlugin {
switch (dir) { switch (dir) {
case 0: case 0:
player.goEast(); pc.goEast();
break; break;
case 1: case 1:
player.goSouth(); pc.goSouth();
break; break;
case 2: case 2:
player.goWest(); pc.goWest();
break; break;
case 3: case 3:
player.goNorth(); pc.goNorth();
break; break;
} }
return true;
} }
@ -66,9 +72,12 @@ public class MIPMouseWalk implements MapInteractionPlugin {
@Override @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.algo.Coord;
import mightypork.gamecore.util.math.constraints.vect.Vect; import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.rogue.world.PlayerControl; import mightypork.rogue.world.PlayerControl;
import mightypork.rogue.world.WorldProvider;
import mightypork.rogue.world.gui.MapView; import mightypork.rogue.world.gui.MapView;
@ -19,9 +20,10 @@ public class MIPTileClick implements MapInteractionPlugin {
@Override @Override
public boolean onClick(MapView wv, PlayerControl player, Vect mouse, int button, boolean down) public boolean onClick(MapView wv, PlayerControl player, Vect mouse, int button, boolean down)
{ {
if (down && button == 1) { // right button if (!down && button == 0) {
final Coord pos = wv.toWorldPos(mouse); Coord pos = wv.toWorldPos(mouse);
player.clickTile(pos); player.clickTile(pos);
System.out.println("~");
return true; return true;
} }
@ -35,7 +37,6 @@ public class MIPTileClick implements MapInteractionPlugin {
return false; return false;
} }
@Override @Override
public void update(MapView mapView, PlayerControl pc, double delta) public void update(MapView mapView, PlayerControl pc, double delta)
{ {

@ -1,6 +1,5 @@
package mightypork.rogue.world.tile; package mightypork.rogue.world.tile;
import mightypork.rogue.world.gen.TileProtectLevel; 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_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_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_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", 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"));
"tile.brick.door.closed", "tile.brick.door.open"));
public static void register(int id, TileModel model) 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.Res;
import mightypork.rogue.world.level.render.TileRenderContext; import mightypork.rogue.world.level.render.TileRenderContext;
import mightypork.rogue.world.tile.Tile; import mightypork.rogue.world.tile.Tile;
import mightypork.rogue.world.tile.TileRenderer;
public class LockedDoorRenderer extends DoorRenderer { public class LockedDoorRenderer extends DoorRenderer {

@ -1,7 +1,13 @@
package mightypork.rogue.world.tile.tiles; 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.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.TileModel;
import mightypork.rogue.world.tile.TileRenderer; import mightypork.rogue.world.tile.TileRenderer;
import mightypork.rogue.world.tile.TileType; import mightypork.rogue.world.tile.TileType;
@ -9,6 +15,9 @@ import mightypork.rogue.world.tile.TileType;
public class SecretDoorTile extends LockedDoorTile { public class SecretDoorTile extends LockedDoorTile {
private int clicks = 2 + rand.nextInt(2);
public SecretDoorTile(TileModel model, TileRenderer renderer) public SecretDoorTile(TileModel model, TileRenderer renderer)
{ {
super(model, renderer); super(model, renderer);
@ -20,7 +29,9 @@ public class SecretDoorTile extends LockedDoorTile {
{ {
if (!locked) return false; if (!locked) return false;
locked = false; if (clicks > 0) clicks--;
if (clicks == 0) locked = false;
return true; return true;
} }
@ -32,4 +43,20 @@ public class SecretDoorTile extends LockedDoorTile {
if (locked) return TileType.WALL.getMapColor(); if (locked) return TileType.WALL.getMapColor();
return super.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();
}
} }

Loading…
Cancel
Save