Fixed the bug & finished load&save mechanism

v5stable
Ondřej Hruška 11 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
* @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 {
// STRINGS
public static final int VERSION = 2;
public static final int VERSION = 3;
public static final String APP_NAME = "Rogue";
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.inventory", grid.makeQuad(1, 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.map", grid.makeQuad(5, 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.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.selected", grid.makeQuad(1, 5));

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

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

@ -14,6 +14,8 @@ import mightypork.gamecore.input.Keys;
import mightypork.gamecore.logging.Log;
import mightypork.gamecore.util.math.Calc;
import mightypork.rogue.Config;
import mightypork.rogue.GameStateManager.GameState;
import mightypork.rogue.events.GameStateRequest;
import mightypork.rogue.world.PlayerFacade;
import mightypork.rogue.world.WorldProvider;
import mightypork.rogue.world.events.WorldPauseRequest;
@ -66,7 +68,7 @@ public class ScreenGame extends LayeredScreen {
@Override
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
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)
*
@ -175,7 +187,7 @@ public class ScreenGame extends LayeredScreen {
worldLayer.enable(true);
worldLayer.setVisible(true);
// TODO temporary here ↓
// TODO temporary, remove
bindKey(new KeyStroke(Keys.N, Keys.MOD_CONTROL), new Runnable() {
@Override
@ -195,7 +207,9 @@ public class ScreenGame extends LayeredScreen {
bindKey(new KeyStroke(Keys.M), actionToggleMinimap);
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);
// add as actions - enableables.
@ -208,7 +222,8 @@ public class ScreenGame extends LayeredScreen {
worldActions.add(actionToggleZoom);
worldActions.add(actionSave);
worldActions.add(actionRestore);
worldActions.add(actionLoad);
worldActions.add(actionMenu);
worldActions.enable(true);

@ -35,6 +35,11 @@ public class ScreenSelectWorld extends LayeredScreen {
class WorldsLayer extends ScreenLayer {
private WorldSlot slot1;
private WorldSlot slot2;
private WorldSlot slot3;
public WorldsLayer(Screen 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);
tp.setPaddingHPerc(0, 20);
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;
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);
slot3 = new WorldSlot(root, Paths.SAVE_SLOT_3);
layout.put(slot3, 3, 0, 1, 1);
}
@ -82,5 +84,15 @@ public class ScreenSelectWorld extends LayeredScreen {
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)
{
return getLevel().getTile(getPlayer().getCoord().add(side)).isWalkable();
return getPlayer().canGoTo(side);
}

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

@ -366,4 +366,10 @@ public class PlayerFacade {
{
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);
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)
{
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) {
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);
}
public void saveWorld() throws IOException
{
if (world == null) {
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);
saveWorld(world.getSaveFile());
}

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

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

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

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

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

@ -160,6 +160,8 @@ public class EntityModulePosition extends EntityModule {
public void addStep(Step step)
{
if (path.isEmpty() && !canGoTo(step)) return;
path.add(step);
}
@ -240,4 +242,10 @@ public class EntityModulePosition extends EntityModule {
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
public int getFoodPoints()
{
return 3;
return 4;
}

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

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

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

Loading…
Cancel
Save