Fixed the bug & finished load&save mechanism

v5stable
Ondřej Hruška 10 years ago
parent f618ab4ba6
commit fda6ca1a63
  1. BIN
      res/img/gui.png
  2. BIN
      res/img/gui.xcf
  3. 2
      src/mightypork/gamecore/util/math/algo/pathfinding/PathFinder.java
  4. 2
      src/mightypork/rogue/Const.java
  5. 4
      src/mightypork/rogue/Res.java
  6. 18
      src/mightypork/rogue/screens/game/HudLayer.java
  7. 12
      src/mightypork/rogue/screens/game/InvLayer.java
  8. 27
      src/mightypork/rogue/screens/game/ScreenGame.java
  9. 32
      src/mightypork/rogue/screens/select_world/ScreenSelectWorld.java
  10. 2
      src/mightypork/rogue/world/PlayerControl.java
  11. 6
      src/mightypork/rogue/world/PlayerData.java
  12. 6
      src/mightypork/rogue/world/PlayerFacade.java
  13. 12
      src/mightypork/rogue/world/World.java
  14. 3
      src/mightypork/rogue/world/WorldConsole.java
  15. 15
      src/mightypork/rogue/world/WorldProvider.java
  16. 9
      src/mightypork/rogue/world/entity/Entity.java
  17. 2
      src/mightypork/rogue/world/entity/impl/BossRatAi.java
  18. 5
      src/mightypork/rogue/world/entity/impl/EntityBossRat.java
  19. 4
      src/mightypork/rogue/world/entity/impl/EntityBrownRat.java
  20. 7
      src/mightypork/rogue/world/entity/impl/MonsterAi.java
  21. 8
      src/mightypork/rogue/world/entity/modules/EntityModulePosition.java
  22. 2
      src/mightypork/rogue/world/item/impl/food/ItemMeat.java
  23. 2
      src/mightypork/rogue/world/item/impl/food/ItemSandwich.java
  24. 2
      src/mightypork/rogue/world/item/impl/weapons/ItemHammer.java
  25. 2
      src/mightypork/rogue/world/item/impl/weapons/ItemSword.java

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.5 KiB

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

@ -232,7 +232,7 @@ public abstract class PathFinder {
* @param pos tile pos * @param pos tile pos
* @return true if the tile is walkable * @return true if the tile is walkable
*/ */
protected abstract boolean isAccessible(Coord pos); public abstract boolean isAccessible(Coord pos);
/** /**

@ -9,7 +9,7 @@ package mightypork.rogue;
public final class Const { public final class Const {
// STRINGS // STRINGS
public static final int VERSION = 2; public static final int VERSION = 3;
public static final String APP_NAME = "Rogue"; public static final String APP_NAME = "Rogue";
public static final String TITLEBAR = APP_NAME + " v." + VERSION; public static final String TITLEBAR = APP_NAME + " v." + VERSION;

@ -94,11 +94,13 @@ public final class Res {
textures.add("nav.button.fg.eat", grid.makeQuad(0, 6)); textures.add("nav.button.fg.eat", grid.makeQuad(0, 6));
textures.add("nav.button.fg.inventory", grid.makeQuad(1, 6)); textures.add("nav.button.fg.inventory", grid.makeQuad(1, 6));
textures.add("nav.button.fg.attack", grid.makeQuad(2, 6)); textures.add("nav.button.fg.attack", grid.makeQuad(2, 6));
textures.add("nav.button.fg.options", grid.makeQuad(3, 6)); textures.add("nav.button.fg.menu", grid.makeQuad(3, 6));
textures.add("nav.button.fg.help", grid.makeQuad(4, 6)); textures.add("nav.button.fg.help", grid.makeQuad(4, 6));
textures.add("nav.button.fg.map", grid.makeQuad(5, 6)); textures.add("nav.button.fg.map", grid.makeQuad(5, 6));
textures.add("nav.button.fg.pause", grid.makeQuad(6, 6)); textures.add("nav.button.fg.pause", grid.makeQuad(6, 6));
textures.add("nav.button.fg.magnify", grid.makeQuad(7, 6)); textures.add("nav.button.fg.magnify", grid.makeQuad(7, 6));
textures.add("nav.button.fg.save", grid.makeQuad(7, 5));
textures.add("nav.button.fg.load", grid.makeQuad(6, 5));
textures.add("inv.slot.base", grid.makeQuad(0, 5)); textures.add("inv.slot.base", grid.makeQuad(0, 5));
textures.add("inv.slot.selected", grid.makeQuad(1, 5)); textures.add("inv.slot.selected", grid.makeQuad(1, 5));

@ -34,7 +34,7 @@ public class HudLayer extends ScreenLayer {
} }
}; };
protected Minimap mm; protected Minimap miniMap;
private final ScreenGame gameScreen; private final ScreenGame gameScreen;
@ -70,9 +70,9 @@ public class HudLayer extends ScreenLayer {
private void buildMinimap() private void buildMinimap()
{ {
mm = new Minimap(); miniMap = new Minimap();
mm.setRect(root.shrink(root.width().perc(5), root.height().perc(15))); miniMap.setRect(root.shrink(root.width().perc(5), root.height().perc(15)));
root.add(mm); root.add(miniMap);
} }
@ -130,12 +130,22 @@ public class HudLayer extends ScreenLayer {
// TODO actions // TODO actions
//nav.addLeft(new NavButton(Res.txq("nav.button.fg.options"))); //nav.addLeft(new NavButton(Res.txq("nav.button.fg.options")));
//nav.addLeft(new NavButton(Res.txq("nav.button.fg.help"))); //nav.addLeft(new NavButton(Res.txq("nav.button.fg.help")));
nav.addLeft(btn = new NavButton(Res.txq("nav.button.fg.menu")));
btn.setAction(gameScreen.actionMenu);
nav.addLeft(btn = new NavButton(Res.txq("nav.button.fg.save")));
btn.setAction(gameScreen.actionSave);
nav.addLeft(btn = new NavButton(Res.txq("nav.button.fg.load")));
btn.setAction(gameScreen.actionLoad);
nav.addLeft(btn = new NavButton(Res.txq("nav.button.fg.map"))); nav.addLeft(btn = new NavButton(Res.txq("nav.button.fg.map")));
btn.setAction(gameScreen.actionToggleMinimap); btn.setAction(gameScreen.actionToggleMinimap);
nav.addLeft(btn = new NavButton(Res.txq("nav.button.fg.magnify"))); nav.addLeft(btn = new NavButton(Res.txq("nav.button.fg.magnify")));
btn.setAction(gameScreen.actionToggleZoom); btn.setAction(gameScreen.actionToggleZoom);
} }

@ -139,8 +139,16 @@ public class InvLayer extends ScreenLayer {
gl.put(txp2, pos, 0, 1, 1); gl.put(txp2, pos, 0, 1, 1);
txp2.setPaddingHPerc(0, 25); txp2.setPaddingHPerc(0, 25);
bindKey(new KeyStroke(Keys.ESCAPE), screen.actionToggleInv); bindKey(new KeyStroke(Keys.ESCAPE), new Runnable() {
// TODO needs some rewrite of keys system
@Override
public void run()
{
if(isEnabled()) {
screen.actionToggleInv.run();
}
}
});
bindKey(new KeyStroke(Keys.E), new Runnable() { bindKey(new KeyStroke(Keys.E), new Runnable() {

@ -14,6 +14,8 @@ import mightypork.gamecore.input.Keys;
import mightypork.gamecore.logging.Log; import mightypork.gamecore.logging.Log;
import mightypork.gamecore.util.math.Calc; import mightypork.gamecore.util.math.Calc;
import mightypork.rogue.Config; import mightypork.rogue.Config;
import mightypork.rogue.GameStateManager.GameState;
import mightypork.rogue.events.GameStateRequest;
import mightypork.rogue.world.PlayerFacade; import mightypork.rogue.world.PlayerFacade;
import mightypork.rogue.world.WorldProvider; import mightypork.rogue.world.WorldProvider;
import mightypork.rogue.world.events.WorldPauseRequest; import mightypork.rogue.world.events.WorldPauseRequest;
@ -66,7 +68,7 @@ public class ScreenGame extends LayeredScreen {
@Override @Override
public void execute() public void execute()
{ {
hudLayer.mm.setVisible(!hudLayer.mm.isVisible()); hudLayer.miniMap.setVisible(!hudLayer.miniMap.isVisible());
} }
}; };
@ -103,7 +105,7 @@ public class ScreenGame extends LayeredScreen {
} }
}; };
public Action actionRestore = new Action() { public Action actionLoad = new Action() {
@Override @Override
public void execute() public void execute()
@ -119,7 +121,17 @@ public class ScreenGame extends LayeredScreen {
} }
} }
}; };
public Action actionMenu = new Action() {
@Override
public void execute()
{
// TODO ask to save
getEventBus().send(new GameStateRequest(GameState.MAIN_MENU));
}
};
/** /**
* Set gui state (overlay) * Set gui state (overlay)
* *
@ -175,7 +187,7 @@ public class ScreenGame extends LayeredScreen {
worldLayer.enable(true); worldLayer.enable(true);
worldLayer.setVisible(true); worldLayer.setVisible(true);
// TODO temporary here ↓ // TODO temporary, remove
bindKey(new KeyStroke(Keys.N, Keys.MOD_CONTROL), new Runnable() { bindKey(new KeyStroke(Keys.N, Keys.MOD_CONTROL), new Runnable() {
@Override @Override
@ -195,7 +207,9 @@ public class ScreenGame extends LayeredScreen {
bindKey(new KeyStroke(Keys.M), actionToggleMinimap); bindKey(new KeyStroke(Keys.M), actionToggleMinimap);
bindKey(new KeyStroke(Keys.Z), actionToggleZoom); bindKey(new KeyStroke(Keys.Z), actionToggleZoom);
bindKey(new KeyStroke(Keys.R, Keys.MOD_CONTROL), actionRestore); bindKey(new KeyStroke(Keys.R, Keys.MOD_CONTROL), actionLoad);
bindKey(new KeyStroke(Keys.L, Keys.MOD_CONTROL), actionLoad);
bindKey(new KeyStroke(Keys.S, Keys.MOD_CONTROL), actionSave); bindKey(new KeyStroke(Keys.S, Keys.MOD_CONTROL), actionSave);
// add as actions - enableables. // add as actions - enableables.
@ -208,7 +222,8 @@ public class ScreenGame extends LayeredScreen {
worldActions.add(actionToggleZoom); worldActions.add(actionToggleZoom);
worldActions.add(actionSave); worldActions.add(actionSave);
worldActions.add(actionRestore); worldActions.add(actionLoad);
worldActions.add(actionMenu);
worldActions.enable(true); worldActions.enable(true);

@ -35,6 +35,11 @@ public class ScreenSelectWorld extends LayeredScreen {
class WorldsLayer extends ScreenLayer { class WorldsLayer extends ScreenLayer {
private WorldSlot slot1;
private WorldSlot slot2;
private WorldSlot slot3;
public WorldsLayer(Screen screen) public WorldsLayer(Screen screen)
{ {
super(screen); super(screen);
@ -61,18 +66,15 @@ public class ScreenSelectWorld extends LayeredScreen {
layout.put(tp = new TextPainter(Res.getFont("thick"), AlignX.CENTER, RGB.YELLOW, "Save slot:"), 0, 0, 1, 1); layout.put(tp = new TextPainter(Res.getFont("thick"), AlignX.CENTER, RGB.YELLOW, "Save slot:"), 0, 0, 1, 1);
tp.setPaddingHPerc(0, 20); tp.setPaddingHPerc(0, 20);
tp.setShadow(RGB.BLACK_50, tp.height().mul(0.6 / 8D).toVectXY()); tp.setShadow(RGB.BLACK_50, tp.height().mul(0.6 / 8D).toVectXY());
slot1 = new WorldSlot(root, Paths.SAVE_SLOT_1);
layout.put(slot1, 1, 0, 1, 1);
slot2 = new WorldSlot(root, Paths.SAVE_SLOT_2);
layout.put(slot2, 2, 0, 1, 1);
WorldSlot wsl; slot3 = new WorldSlot(root, Paths.SAVE_SLOT_3);
layout.put(slot3, 3, 0, 1, 1);
wsl = new WorldSlot(root, Paths.SAVE_SLOT_1);
layout.put(wsl, 1, 0, 1, 1);
wsl = new WorldSlot(root, Paths.SAVE_SLOT_2);
layout.put(wsl, 2, 0, 1, 1);
wsl = new WorldSlot(root, Paths.SAVE_SLOT_3);
layout.put(wsl, 3, 0, 1, 1);
} }
@ -82,5 +84,15 @@ public class ScreenSelectWorld extends LayeredScreen {
return 2; return 2;
} }
@Override
protected void onScreenEnter()
{
super.onScreenEnter();
slot1.refresh();
slot2.refresh();
slot3.refresh();
}
} }
} }

@ -87,7 +87,7 @@ public abstract class PlayerControl {
public boolean canGo(Step side) public boolean canGo(Step side)
{ {
return getLevel().getTile(getPlayer().getCoord().add(side)).isWalkable(); return getPlayer().canGoTo(side);
} }

@ -33,9 +33,9 @@ public class PlayerData implements IonObjBundled {
@Override @Override
public void load(IonBundle bundle) throws IOException public void load(IonBundle bundle) throws IOException
{ {
eid = bundle.get("eid", eid); eid = bundle.get("eid", -1);
level = bundle.get("floor", level); level = bundle.get("floor", -1);
selectedWeapon = bundle.get("weapon", selectedWeapon); selectedWeapon = bundle.get("weapon", -1);
inventory = bundle.get("inv", inventory); inventory = bundle.get("inv", inventory);
} }

@ -366,4 +366,10 @@ public class PlayerFacade {
{ {
return world; return world;
} }
public boolean canGoTo(Step side)
{
return getEntity().pos.canGoTo(side);
}
} }

@ -85,7 +85,17 @@ public class World implements DelegatingClient, BusAccess, IonObjBundled, Pausea
playerEntity = levels.get(lvl).getEntity(eid); playerEntity = levels.get(lvl).getEntity(eid);
if (playerEntity == null) { if (playerEntity == null) {
throw new RuntimeException("Player entity not found in the world: " + eid + " on floor " + lvl);
Log.e("Player entity not found in the world: " + eid + " on floor " + lvl);
for(int i=0; i<levels.size(); i++) {
Entity ent = levels.get(i).getEntity(eid);
if(ent != null) {
Log.f3("Player entity was really on floor: "+i);
}
}
throw new RuntimeException();
} }
} }

@ -129,9 +129,6 @@ public class WorldConsole implements Updateable {
public void msgDie(Entity attacker) public void msgDie(Entity attacker)
{ {
addMessage("You've been defeated by a " + attacker.getVisualName() + "!"); addMessage("You've been defeated by a " + attacker.getVisualName() + "!");
addMessage("CTRL+M ... main menu");
addMessage("CTRL+N ... new game");
} }

@ -93,23 +93,16 @@ public class WorldProvider extends RootBusNode {
if (world == null) { if (world == null) {
throw new IllegalStateException("Trying to save a NULL world."); throw new IllegalStateException("Trying to save a NULL world.");
} }
if (file == null) {
throw new IllegalStateException("Trying to save world to a NULL file.");
}
Ion.toFile(file, world); Ion.toFile(file, world);
} }
public void saveWorld() throws IOException public void saveWorld() throws IOException
{ {
if (world == null) { saveWorld(world.getSaveFile());
throw new IllegalStateException("Trying to save a NULL world.");
}
final File f = world.getSaveFile();
if (f == null) {
throw new IllegalStateException("Trying to save world to a NULL file.");
}
Ion.toFile(f, world);
} }

@ -289,4 +289,13 @@ public abstract class Entity implements IonObjBundled, Updateable, DelegatingCli
return modules.values(); return modules.values();
} }
public Entity getLastAttacker()
{
return lastAttacker;
}
public double getLastAttackTime() {
return health.getTimeSinceLastDamage();
}
} }

@ -29,7 +29,7 @@ public class BossRatAi extends GrayRatAi {
@Override @Override
protected int getAttackStrength() protected int getAttackStrength()
{ {
return Calc.randInt(3, 11); return Calc.randInt(5, 11);
} }

@ -63,9 +63,8 @@ public class EntityBossRat extends Entity {
@Override @Override
public void onKilled() public void onKilled()
{ {
getWorld().getConsole().addMessage("YOU DEFEATED THE BOSS RAT"); getWorld().getConsole().addMessage("~~~ YOU DEFEATED THE BOSS RAT ~~~");
getWorld().getConsole().addMessage("CTRL+M ... main menu"); getWorld().getConsole().addMessage("TODO: outro");
getWorld().getConsole().addMessage("CTRL+N ... new game");
} }

@ -30,8 +30,8 @@ public class EntityBrownRat extends Entity {
setDespawnDelay(1); setDespawnDelay(1);
health.setHealthMax(20); health.setHealthMax(16);
health.setHealth(Calc.randInt(12, 20)); // tougher to kill health.setHealth(Calc.randInt(10, 16)); // tougher to kill
health.setHitCooldownTime(0.35); // a bit longer than gray rat health.setHitCooldownTime(0.35); // a bit longer than gray rat
} }

@ -56,6 +56,12 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
{ {
if (!isIdle()) return; if (!isIdle()) return;
// annoyed by attacking.
if(entity.getLastAttackTime() < 0.5) {
lookForTarget();
return;
}
if(entity.pos.isMoving()) return; if(entity.pos.isMoving()) return;
if(Calc.rand.nextInt(10) == 0) { if(Calc.rand.nextInt(10) == 0) {
@ -176,7 +182,6 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
stepTowardsPrey(prey); stepTowardsPrey(prey);
} }
} }
} }

@ -160,6 +160,8 @@ public class EntityModulePosition extends EntityModule {
public void addStep(Step step) public void addStep(Step step)
{ {
if (path.isEmpty() && !canGoTo(step)) return;
path.add(step); path.add(step);
} }
@ -240,4 +242,10 @@ public class EntityModulePosition extends EntityModule {
return isMoving() || !path.isEmpty(); return isMoving() || !path.isEmpty();
} }
public boolean canGoTo(Step side)
{
return entity.getPathFinder().isAccessible(getCoord().add(side));
}
} }

@ -26,7 +26,7 @@ public class ItemMeat extends ItemBaseFood {
@Override @Override
public int getFoodPoints() public int getFoodPoints()
{ {
return 3; return 4;
} }

@ -26,7 +26,7 @@ public class ItemSandwich extends ItemBaseFood {
@Override @Override
public int getFoodPoints() public int getFoodPoints()
{ {
return 6; return 8;
} }

@ -33,7 +33,7 @@ public class ItemHammer extends ItemBaseWeapon {
@Override @Override
public int getMaxUses() public int getMaxUses()
{ {
return 60; return 100;
} }

@ -33,7 +33,7 @@ public class ItemSword extends ItemBaseWeapon {
@Override @Override
public int getMaxUses() public int getMaxUses()
{ {
return 150; return 200;
} }

Loading…
Cancel
Save