Heart pieces, more balanced entities & gen.

v5stable
Ondřej Hruška 11 years ago
parent 49b327b951
commit 88efff430b
  1. BIN
      res/img/gui.xcf
  2. BIN
      res/img/items.png
  3. BIN
      res/img/items.xcf
  4. 1
      src/mightypork/rogue/Res.java
  5. 1
      src/mightypork/rogue/screens/game/InvLayer.java
  6. 1
      src/mightypork/rogue/screens/game/ScreenGame.java
  7. 25
      src/mightypork/rogue/screens/game/WorldConsoleRenderer.java
  8. 16
      src/mightypork/rogue/t/TryItemDmg.java
  9. 19
      src/mightypork/rogue/world/World.java
  10. 7
      src/mightypork/rogue/world/WorldConsole.java
  11. 14
      src/mightypork/rogue/world/WorldCreator.java
  12. 6
      src/mightypork/rogue/world/entity/Entity.java
  13. 6
      src/mightypork/rogue/world/entity/entities/BrownRatAi.java
  14. 4
      src/mightypork/rogue/world/entity/entities/EntityBossRat.java
  15. 8
      src/mightypork/rogue/world/entity/entities/EntityBrownRat.java
  16. 12
      src/mightypork/rogue/world/entity/entities/EntityGrayRat.java
  17. 2
      src/mightypork/rogue/world/entity/entities/GrayRatAi.java
  18. 5
      src/mightypork/rogue/world/entity/entities/PlayerEntity.java
  19. 4
      src/mightypork/rogue/world/entity/modules/EntityModuleHealth.java
  20. 47
      src/mightypork/rogue/world/gen/LevelGenerator.java
  21. 22
      src/mightypork/rogue/world/gen/ScratchMap.java
  22. 8
      src/mightypork/rogue/world/gen/rooms/AbstractRectRoom.java
  23. 2
      src/mightypork/rogue/world/gen/rooms/EntranceRoom.java
  24. 2
      src/mightypork/rogue/world/gen/rooms/ExitRoom.java
  25. 44
      src/mightypork/rogue/world/gen/rooms/HeartPieceRoom.java
  26. 5
      src/mightypork/rogue/world/gen/rooms/Rooms.java
  27. 30
      src/mightypork/rogue/world/gen/rooms/SecretRoom.java
  28. 38
      src/mightypork/rogue/world/gen/rooms/TreasureRoom.java
  29. 9
      src/mightypork/rogue/world/item/Item.java
  30. 2
      src/mightypork/rogue/world/item/ItemType.java
  31. 8
      src/mightypork/rogue/world/item/Items.java
  32. 86
      src/mightypork/rogue/world/item/items/active/ItemHeartPiece.java
  33. 2
      src/mightypork/rogue/world/item/items/weapons/ItemClub.java
  34. 2
      src/mightypork/rogue/world/item/items/weapons/ItemHammer.java
  35. 2
      src/mightypork/rogue/world/item/items/weapons/ItemStone.java
  36. 2
      src/mightypork/rogue/world/item/items/weapons/ItemSword.java
  37. 6
      src/mightypork/rogue/world/level/Level.java

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

@ -167,6 +167,7 @@ public final class Res {
textures.add("item.bone", grid.makeQuad(5, 0)); textures.add("item.bone", grid.makeQuad(5, 0));
textures.add("item.cheese", grid.makeQuad(6, 0)); textures.add("item.cheese", grid.makeQuad(6, 0));
textures.add("item.sandwich", grid.makeQuad(7, 0)); textures.add("item.sandwich", grid.makeQuad(7, 0));
textures.add("item.heart_piece", grid.makeQuad(0, 1));
} }

@ -15,7 +15,6 @@ 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.strings.StringProvider; import mightypork.gamecore.util.strings.StringProvider;
import mightypork.rogue.Res; import mightypork.rogue.Res;
import mightypork.rogue.screens.game.ScreenGame.GScrState;
import mightypork.rogue.world.World; import mightypork.rogue.world.World;
import mightypork.rogue.world.World.PlayerFacade; import mightypork.rogue.world.World.PlayerFacade;
import mightypork.rogue.world.WorldProvider; import mightypork.rogue.world.WorldProvider;

@ -4,7 +4,6 @@ package mightypork.rogue.screens.game;
import java.util.Random; import java.util.Random;
import mightypork.gamecore.app.AppAccess; import mightypork.gamecore.app.AppAccess;
import mightypork.gamecore.eventbus.events.Updateable;
import mightypork.gamecore.gui.Action; import mightypork.gamecore.gui.Action;
import mightypork.gamecore.gui.ActionGroup; import mightypork.gamecore.gui.ActionGroup;
import mightypork.gamecore.gui.screens.LayeredScreen; import mightypork.gamecore.gui.screens.LayeredScreen;

@ -8,6 +8,8 @@ import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.BaseComponent; import mightypork.gamecore.gui.components.BaseComponent;
import mightypork.gamecore.logging.Log; import mightypork.gamecore.logging.Log;
import mightypork.gamecore.resources.fonts.FontRenderer; import mightypork.gamecore.resources.fonts.FontRenderer;
import mightypork.gamecore.util.math.Calc;
import mightypork.gamecore.util.math.Easing;
import mightypork.gamecore.util.math.color.Color; import mightypork.gamecore.util.math.color.Color;
import mightypork.gamecore.util.math.color.pal.RGB; import mightypork.gamecore.util.math.color.pal.RGB;
import mightypork.gamecore.util.math.constraints.num.Num; import mightypork.gamecore.util.math.constraints.num.Num;
@ -22,12 +24,17 @@ public class WorldConsoleRenderer extends BaseComponent {
private final Num rowHeight; private final Num rowHeight;
private final FontRenderer fr; private final FontRenderer fr;
private final Rect itemViewRect;
public WorldConsoleRenderer(Num rowHeight) public WorldConsoleRenderer(Num rowHeight)
{ {
this.rowHeight = rowHeight; this.rowHeight = rowHeight;
this.fr = new FontRenderer(Res.getFont("tiny")); this.fr = new FontRenderer(Res.getFont("tiny"));
final Num itmsize = height().perc(25).min(256).max(16);
this.itemViewRect = bottomRight().sub(itmsize.perc(25), itmsize.perc(25)).startRect().grow(itmsize, Num.ZERO, itmsize, Num.ZERO);
} }
@ -38,7 +45,8 @@ public class WorldConsoleRenderer extends BaseComponent {
final Rect lowRow = bottomEdge().growUp(rowHeight); final Rect lowRow = bottomEdge().growUp(rowHeight);
final Collection<WorldConsole.Entry> entries = WorldProvider.get().getWorld().getConsole().getEntries(); final WorldConsole console = WorldProvider.get().getWorld().getConsole();
final Collection<WorldConsole.Entry> entries = console.getEntries();
int cnt = 0; int cnt = 0;
@ -54,7 +62,7 @@ public class WorldConsoleRenderer extends BaseComponent {
final Rect rrr = lowRow.moveY(-rh * cnt); final Rect rrr = lowRow.moveY(-rh * cnt);
fr.draw(entry.getMessage(), rrr.move(rh / 12, rh / 12), AlignX.LEFT, RGB.BLACK_60); fr.draw(entry.getMessage(), rrr.move(rh / 8D, rh / 8D), AlignX.LEFT, RGB.BLACK_60);
fr.draw(entry.getMessage(), rrr, AlignX.LEFT, RGB.WHITE); fr.draw(entry.getMessage(), rrr, AlignX.LEFT, RGB.WHITE);
cnt++; cnt++;
@ -64,7 +72,20 @@ public class WorldConsoleRenderer extends BaseComponent {
Log.e(e); // this should not happen anymore Log.e(e); // this should not happen anymore
} }
if (console.lastPickupItem != null) {
double alpha = 1;
if (console.timeSinceLastPickup > 2) {
alpha = 1 - Easing.CIRC_OUT.get(Calc.clamp((console.timeSinceLastPickup - 2) / 1, 0, 1));
}
alph.setTo(alpha);
console.lastPickupItem.render(itemViewRect);
}
Color.popAlpha(); Color.popAlpha();
} }
} }

@ -0,0 +1,16 @@
package mightypork.rogue.t;
import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.item.Items;
public class TryItemDmg {
public static void main(String[] args)
{
final Item itm = Items.CLUB.createItemDamaged(80);
System.out.println(itm.getMaxUses() + " - remaining: " + itm.getRemainingUses());
}
}

@ -10,7 +10,6 @@ import mightypork.gamecore.eventbus.clients.DelegatingClient;
import mightypork.gamecore.eventbus.events.Updateable; import mightypork.gamecore.eventbus.events.Updateable;
import mightypork.gamecore.util.ion.IonBundle; import mightypork.gamecore.util.ion.IonBundle;
import mightypork.gamecore.util.ion.IonObjBundled; import mightypork.gamecore.util.ion.IonObjBundled;
import mightypork.gamecore.util.math.Calc;
import mightypork.gamecore.util.math.algo.Coord; import mightypork.gamecore.util.math.algo.Coord;
import mightypork.gamecore.util.math.algo.Step; import mightypork.gamecore.util.math.algo.Step;
import mightypork.gamecore.util.math.constraints.vect.Vect; import mightypork.gamecore.util.math.constraints.vect.Vect;
@ -159,7 +158,7 @@ public class World implements DelegatingClient, BusAccess, IonObjBundled, Pausea
public int getHealthMax() public int getHealthMax()
{ {
return playerEntity.health.getMaxHealth(); return playerEntity.health.getHealthMax();
} }
@ -349,6 +348,18 @@ public class World implements DelegatingClient, BusAccess, IonObjBundled, Pausea
return true; return true;
} }
public void setHealth(int health)
{
playerEntity.health.setHealth(health);
}
public void setHealthMax(int health)
{
playerEntity.health.setHealthMax(health);
}
} }
// not saved stuffs // not saved stuffs
@ -540,6 +551,8 @@ public class World implements DelegatingClient, BusAccess, IonObjBundled, Pausea
public void msgPick(Item item) public void msgPick(Item item)
{ {
console.addMessage("You've picked a " + item.getVisualName() + "."); console.addMessage("You've picked a " + item.getVisualName() + ".");
console.lastPickupItem = item;
console.timeSinceLastPickup = 0;
} }
@ -599,6 +612,6 @@ public class World implements DelegatingClient, BusAccess, IonObjBundled, Pausea
public void msgEnterFloor(int floor) public void msgEnterFloor(int floor)
{ {
console.addMessage("~ " + Calc.ordinal(floor + 1) + " floor ~"); console.addMessage("~ Floor " + floor + " ~");
} }
} }

@ -9,10 +9,15 @@ import java.util.concurrent.LinkedBlockingDeque;
import mightypork.gamecore.eventbus.events.Updateable; import mightypork.gamecore.eventbus.events.Updateable;
import mightypork.gamecore.util.math.Easing; import mightypork.gamecore.util.math.Easing;
import mightypork.gamecore.util.math.constraints.num.mutable.NumAnimated; import mightypork.gamecore.util.math.constraints.num.mutable.NumAnimated;
import mightypork.rogue.world.item.Item;
public class WorldConsole implements Updateable { public class WorldConsole implements Updateable {
/** Used only for display */
public Item lastPickupItem;
public double timeSinceLastPickup = Integer.MAX_VALUE;
private static final double DURATION = 5; private static final double DURATION = 5;
public class Entry implements Updateable { public class Entry implements Updateable {
@ -87,6 +92,8 @@ public class WorldConsole implements Updateable {
iter.remove(); iter.remove();
} }
} }
timeSinceLastPickup += delta;
} }

@ -19,15 +19,11 @@ public class WorldCreator {
final World w = new World(); final World w = new World();
w.setSeed(seed); w.setSeed(seed);
// final int count = 7; final int count = 7;
//
// for (int i = 1; i <= count; i++) { for (int lvl = 1; lvl <= count; lvl++) {
// final Level l = LevelGenerator.build(w, rand.nextLong(), i, LevelGenerator.DUNGEON_THEME, i == count); w.addLevel(LevelGenerator.build(w, rand.nextLong(), lvl, LevelGenerator.DUNGEON_THEME, lvl == count));
// w.addLevel(l); }
// }
w.addLevel(LevelGenerator.build(w, rand.nextLong(), 6, LevelGenerator.DUNGEON_THEME, false));
w.addLevel(LevelGenerator.build(w, rand.nextLong(), 7, LevelGenerator.DUNGEON_THEME, true));
w.createPlayer(); w.createPlayer();

@ -44,6 +44,7 @@ public abstract class Entity implements IonObjBundled, Updateable {
public final EntityModuleHealth health = new EntityModuleHealth(this); public final EntityModuleHealth health = new EntityModuleHealth(this);
private double despawnDelay = 1; private double despawnDelay = 1;
protected Entity lastAttacker; protected Entity lastAttacker;
private boolean freed;
public Entity(EntityModel model, int eid) public Entity(EntityModel model, int eid)
@ -171,6 +172,11 @@ public abstract class Entity implements IonObjBundled, Updateable {
@Override @Override
public void update(double delta) public void update(double delta)
{ {
if (!freed && isDead() && health.getTimeSinceLastDamage() >= 0.2) {
getLevel().freeTile(getCoord());
freed = true;
}
for (final Entry<String, EntityModule> entry : modules.entrySet()) { for (final Entry<String, EntityModule> entry : modules.entrySet()) {
entry.getValue().update(delta); entry.getValue().update(delta);
} }

@ -10,8 +10,8 @@ public class BrownRatAi extends GrayRatAi {
{ {
super(entity); super(entity);
setAttackTime(0.8); setAttackTime(1.2);
setScanTime(1); setScanTime(1.3);
} }
@ -25,7 +25,7 @@ public class BrownRatAi extends GrayRatAi {
@Override @Override
protected int getAttackStrength() protected int getAttackStrength()
{ {
return 3 + rand.nextInt(2); return 2 + rand.nextInt(3);
} }

@ -31,7 +31,7 @@ public class EntityBossRat extends Entity {
pos.setStepTime(0.4); pos.setStepTime(0.4);
setDespawnDelay(1); setDespawnDelay(1);
health.setMaxHealth(80); health.setHealthMax(80);
health.setHealth(80); health.setHealth(80);
health.setHitCooldownTime(0.35); health.setHitCooldownTime(0.35);
} }
@ -63,7 +63,7 @@ public class EntityBossRat extends Entity {
@Override @Override
public void onCorpseRemoved() public void onKilled()
{ {
// TODO drop rare stuff & fire event. // TODO drop rare stuff & fire event.

@ -28,10 +28,10 @@ public class EntityBrownRat extends Entity {
addModule("ai", ai); addModule("ai", ai);
pos.addMoveListener(ai); pos.addMoveListener(ai);
pos.setStepTime(0.37); // faster than gray rat pos.setStepTime(0.39); // faster than gray rat
setDespawnDelay(1); setDespawnDelay(1);
health.setMaxHealth(14); health.setHealthMax(14);
health.setHealth(Calc.randInt(rand, 8, 14)); // tougher to kill health.setHealth(Calc.randInt(rand, 8, 14)); // tougher to kill
health.setHitCooldownTime(0.35); // a bit longer than gray rat health.setHitCooldownTime(0.35); // a bit longer than gray rat
} }
@ -63,11 +63,11 @@ public class EntityBrownRat extends Entity {
@Override @Override
public void onCorpseRemoved() public void onKilled()
{ {
// drop rat stuff // drop rat stuff
if (rand.nextInt(8) == 0) { if (rand.nextInt(7) == 0) {
getLevel().dropNear(getCoord(), Items.BONE.createItemDamaged(10)); getLevel().dropNear(getCoord(), Items.BONE.createItemDamaged(10));
return; return;
} }

@ -31,8 +31,8 @@ public class EntityGrayRat extends Entity {
pos.setStepTime(0.5); pos.setStepTime(0.5);
setDespawnDelay(1); setDespawnDelay(1);
health.setMaxHealth(5); health.setHealthMax(6);
health.setHealth(Calc.randInt(rand, 3, 5)); health.setHealth(Calc.randInt(rand, 4, 6));
health.setHitCooldownTime(0.3); health.setHitCooldownTime(0.3);
} }
@ -63,16 +63,16 @@ public class EntityGrayRat extends Entity {
@Override @Override
public void onCorpseRemoved() public void onKilled()
{ {
// drop rat stuff // drop rat stuff
if (rand.nextInt(6) == 0) { if (rand.nextInt(4) == 0) {
getLevel().dropNear(getCoord(), Items.BONE.createItemDamaged(10)); getLevel().dropNear(getCoord(), Items.BONE.createItemDamaged(40));
return; return;
} }
if (rand.nextInt(7) == 0) { if (rand.nextInt(6) == 0) {
getLevel().dropNear(getCoord(), Items.MEAT.createItem()); getLevel().dropNear(getCoord(), Items.MEAT.createItem());
return; return;
} }

@ -26,7 +26,7 @@ public class GrayRatAi extends MonsterAi {
@Override @Override
protected double getAttackDistance() protected double getAttackDistance()
{ {
return 1.43; return 1.1;
} }

@ -21,7 +21,7 @@ public class PlayerEntity extends Entity {
super(entity); super(entity);
setDespawnDelay(2); setDespawnDelay(2);
health.setMaxHealth(12); health.setHealthMax(6); // 3 hearts
health.fill(); // fill health bar to max health.fill(); // fill health bar to max
health.setHitCooldownTime(0.5); health.setHitCooldownTime(0.5);
} }
@ -38,7 +38,8 @@ public class PlayerEntity extends Entity {
final Tile t = getLevel().getTile(getCoord()); final Tile t = getLevel().getTile(getCoord());
if (t.hasItem()) { if (t.hasItem()) {
final Item item = t.pickItem(); final Item item = t.pickItem();
if (getWorld().getPlayer().addItem(item)) {
if (item.pickUp(getWorld().getPlayer())) {
// player picked item // player picked item
} else { } else {
t.dropItem(item); // put back. t.dropItem(item); // put back.

@ -68,13 +68,13 @@ public class EntityModuleHealth extends EntityModule {
} }
public int getMaxHealth() public int getHealthMax()
{ {
return maxHealth; return maxHealth;
} }
public void setMaxHealth(int maxHealth) public void setHealthMax(int maxHealth)
{ {
if (maxHealth <= 0) throw new IllegalValueException("Max health out of allowed range: " + maxHealth); if (maxHealth <= 0) throw new IllegalValueException("Max health out of allowed range: " + maxHealth);
this.maxHealth = maxHealth; this.maxHealth = maxHealth;

@ -4,6 +4,7 @@ package mightypork.rogue.world.gen;
import java.util.Random; import java.util.Random;
import mightypork.gamecore.logging.Log; import mightypork.gamecore.logging.Log;
import mightypork.gamecore.util.math.Calc;
import mightypork.gamecore.util.math.algo.Coord; import mightypork.gamecore.util.math.algo.Coord;
import mightypork.rogue.world.World; import mightypork.rogue.world.World;
import mightypork.rogue.world.entity.Entities; import mightypork.rogue.world.entity.Entities;
@ -20,9 +21,9 @@ public class LevelGenerator {
@SuppressWarnings("fallthrough") @SuppressWarnings("fallthrough")
public static Level build(World world, long seed, int complexity, MapTheme theme, boolean lastLevel) throws WorldGenError public static Level build(World world, long seed, int level, MapTheme theme, boolean lastLevel) throws WorldGenError
{ {
Log.f3("Generating level of complexity: " + complexity); Log.f3("Generating level of complexity: " + level);
final Random rand = new Random(seed + 13); final Random rand = new Random(seed + 13);
@ -35,10 +36,15 @@ public class LevelGenerator {
throw new WorldGenError("Could not place entrance room."); throw new WorldGenError("Could not place entrance room.");
} }
for (int i = 0; i < 1 + complexity / 2 + rand.nextInt((int) (1 + complexity * 0.2)); i++) { for (int i = 0; i < Calc.randInt(rand, 1 + level, (int) (1 + level * 1.5)); i++) {
map.addRoom(Rooms.BASIC, false); map.addRoom(Rooms.BASIC, false);
if (rand.nextInt(7) > 0) map.addRoom(Rooms.SECRET, false);
if (rand.nextInt(7) > 0) map.addRoom(Rooms.DEAD_END, false); // spice it up with dead ends
if (rand.nextInt(6) > 0) map.addRoom(Rooms.DEAD_END, false);
}
for (int i = 0; i < Calc.randInt(rand, 1, level / 3); i++) {
map.addRoom(Rooms.TREASURE, false);
} }
if (!lastLevel) { if (!lastLevel) {
@ -48,39 +54,48 @@ public class LevelGenerator {
} }
if (lastLevel) { if (lastLevel) {
if (!map.addRoom(Rooms.BOSS_ROOM, true)) { if (!map.addRoom(Rooms.BOSS, true)) {
throw new WorldGenError("Could not place boss room."); throw new WorldGenError("Could not place boss room.");
} }
} }
map.addRoom(Rooms.HEART_ROOM, true);
map.buildCorridors(); map.buildCorridors();
switch (complexity) { switch (level) {
default: default:
case 3: case 3:
case 2: case 2:
if (rand.nextInt(2) == 0) map.dropInMap(Items.CLUB.createItemDamaged(60), 50); if (rand.nextInt(2) == 0) map.putItemInMap(Items.CLUB.createItemDamaged(30), 50);
case 1: case 1:
case 0: if (rand.nextInt(2) == 0) map.putItemInMap(Items.ROCK.createItemDamaged(10), 50);
if (rand.nextInt(2) == 0) map.dropInMap(Items.ROCK.createItemDamaged(10), 50); }
if (level == 1) {
map.putItemInMap(Items.BONE.createItemDamaged(20), 60);
}
if (level == 2) {
map.putItemInMap(Items.CLUB.createItemDamaged(50), 60);
} }
if (complexity == 6) { if (level == 6) {
map.dropInMap(Items.SWORD.createItemDamaged(40), 200); map.putItemInMap(Items.SWORD.createItemDamaged(60), 200);
} }
if (complexity == 5) { if (level == 4) {
map.dropInMap(Items.HAMMER.createItemDamaged(40), 100); map.putItemInMap(Items.HAMMER.createItemDamaged(60), 100);
} }
// entities - random rats // entities - random rats
for (int i = 0; i < 3 + complexity + rand.nextInt(1 + complexity); i++) { for (int i = 0; i < Calc.randInt(rand, (int) (3 + level * 1.5), (int) (3 + level * 2.5)); i++) {
Entity e; Entity e;
if (rand.nextInt((int) (complexity / 1.5) + 1) != 0) { if (level > 2 && rand.nextInt(level - 2 + 1) != 0) {
e = Entities.RAT_BROWN.createEntity(); e = Entities.RAT_BROWN.createEntity();
} else { } else {
e = Entities.RAT_GRAY.createEntity(); e = Entities.RAT_GRAY.createEntity();

@ -578,26 +578,34 @@ public class ScratchMap {
} }
public boolean dropInArea(Item item, Coord min, Coord max, int tries) public boolean putItem(Item item, Coord pos)
{
if (!isIn(pos)) return false;
final Tile t = getTile(pos);
if (t.dropItem(item)) return true;
return false;
}
public boolean putItemInArea(Item item, Coord min, Coord max, int tries)
{ {
final Coord pos = Coord.zero(); final Coord pos = Coord.zero();
for (int i = 0; i < tries; i++) { for (int i = 0; i < tries; i++) {
pos.x = min.x + rand.nextInt(max.x - min.x); pos.x = min.x + rand.nextInt(max.x - min.x);
pos.y = min.y + rand.nextInt(max.y - min.y); pos.y = min.y + rand.nextInt(max.y - min.y);
if (!isIn(pos)) continue; if (putItem(item, pos)) return true;
final Tile t = getTile(pos);
if (t.dropItem(item)) return true;
} }
return false; return false;
} }
public boolean dropInMap(Item item, int tries) public boolean putItemInMap(Item item, int tries)
{ {
return dropInArea(item, genMin, genMax, tries); return putItemInArea(item, genMin, genMax, tries);
} }

@ -21,12 +21,12 @@ public abstract class AbstractRectRoom implements RoomBuilder {
{ {
// half width, half height actually // half width, half height actually
final Coord innerSize = getInnerSize(rand); final Coord innerSize = getInnerSize(rand);
final int width = 2 + innerSize.x; final int width = 2 + innerSize.x - 1;
final int height = 2 + innerSize.y; final int height = 2 + innerSize.y - 1;
final int wLow = width / 2; final int wLow = (int) Math.round(width / 2D);
final int wHigh = width - wLow; final int wHigh = width - wLow;
final int hLow = height / 2; final int hLow = (int) Math.round(height / 2D);
final int hHigh = height - hLow; final 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);

@ -15,7 +15,7 @@ public class EntranceRoom extends AbstractRectRoom {
@Override @Override
protected Coord getInnerSize(Random rand) protected Coord getInnerSize(Random rand)
{ {
return Coord.make(3 + rand.nextInt(2) * 2, 3 + rand.nextInt(2) * 3); return Coord.make(3 + rand.nextInt(3), 3 + rand.nextInt(3));
} }

@ -15,7 +15,7 @@ public class ExitRoom extends AbstractRectRoom {
@Override @Override
protected Coord getInnerSize(Random rand) protected Coord getInnerSize(Random rand)
{ {
return Coord.make(3, 3); return Coord.make(3 + rand.nextInt(2), 3 + rand.nextInt(2));
} }

@ -0,0 +1,44 @@
package mightypork.rogue.world.gen.rooms;
import java.util.Random;
import mightypork.gamecore.util.math.algo.Coord;
import mightypork.rogue.world.gen.MapTheme;
import mightypork.rogue.world.gen.ScratchMap;
import mightypork.rogue.world.gen.WorldGenError;
import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.item.Items;
public class HeartPieceRoom extends SecretRoom {
@Override
protected int getDoorCount(Random rand)
{
return 1;
}
@Override
protected void buildExtras(ScratchMap map, MapTheme theme, Random rand, Coord min, Coord max)
{
final Item heart = Items.HEART_PIECE.createItem();
if (!map.putItem(heart, min.add(2, 2))) {
if (!map.putItemInArea(heart, min, max, 100)) {
if (!map.putItemInMap(heart, 100)) {
throw new WorldGenError("Could not place heart piece.");
}
}
}
}
@Override
protected Coord getInnerSize(Random rand)
{
return Coord.make(3, 3);
}
}

@ -7,9 +7,10 @@ import mightypork.rogue.world.gen.RoomBuilder;
public class Rooms { public class Rooms {
public static final RoomBuilder BASIC = new BasicRoom(); public static final RoomBuilder BASIC = new BasicRoom();
public static final RoomBuilder SECRET = new SecretRoom(); public static final RoomBuilder TREASURE = new TreasureRoom();
public static final RoomBuilder DEAD_END = new DeadEndRoom(); public static final RoomBuilder DEAD_END = new DeadEndRoom();
public static final RoomBuilder ENTRANCE = new EntranceRoom(); public static final RoomBuilder ENTRANCE = new EntranceRoom();
public static final RoomBuilder EXIT = new ExitRoom(); public static final RoomBuilder EXIT = new ExitRoom();
public static final RoomBuilder BOSS_ROOM = new BossRoom(); public static final RoomBuilder BOSS = new BossRoom();
public static final RoomBuilder HEART_ROOM = new HeartPieceRoom();
} }

@ -3,16 +3,13 @@ package mightypork.rogue.world.gen.rooms;
import java.util.Random; import java.util.Random;
import mightypork.gamecore.util.math.Calc;
import mightypork.gamecore.util.math.algo.Coord; import mightypork.gamecore.util.math.algo.Coord;
import mightypork.rogue.world.gen.MapTheme; import mightypork.rogue.world.gen.MapTheme;
import mightypork.rogue.world.gen.ScratchMap;
import mightypork.rogue.world.gen.TileProtectLevel; import mightypork.rogue.world.gen.TileProtectLevel;
import mightypork.rogue.world.item.Items;
import mightypork.rogue.world.tile.TileModel; import mightypork.rogue.world.tile.TileModel;
public class SecretRoom extends AbstractRectRoom { public abstract class SecretRoom extends AbstractRectRoom {
@Override @Override
protected TileModel getDoorType(MapTheme theme, Random rand) protected TileModel getDoorType(MapTheme theme, Random rand)
@ -35,31 +32,6 @@ public class SecretRoom extends AbstractRectRoom {
} }
@Override
protected void buildExtras(ScratchMap map, MapTheme theme, Random rand, Coord min, Coord max)
{
for (int i = 0; i < Calc.randInt(rand, 0, 1); i++) {
map.dropInArea(Items.SANDWICH.createItem(), min, max, 50);
}
for (int i = 0; i < Calc.randInt(rand, 0, 2); i++) {
map.dropInArea(Items.BONE.createItemDamaged(20), min, max, 50);
}
for (int i = 0; i < Calc.randInt(rand, 0, 1); i++) {
map.dropInArea(Items.ROCK.createItemDamaged(30), min, max, 50);
}
for (int i = 0; i < Calc.randInt(rand, 0, 2); i++) {
map.dropInArea(Items.MEAT.createItem(), min, max, 50);
}
for (int i = 0; i < Calc.randInt(rand, 0, 2); i++) {
map.dropInArea(Items.CHEESE.createItem(), min, max, 50);
}
}
@Override @Override
protected Coord getInnerSize(Random rand) protected Coord getInnerSize(Random rand)
{ {

@ -0,0 +1,38 @@
package mightypork.rogue.world.gen.rooms;
import java.util.Random;
import mightypork.gamecore.util.math.Calc;
import mightypork.gamecore.util.math.algo.Coord;
import mightypork.rogue.world.gen.MapTheme;
import mightypork.rogue.world.gen.ScratchMap;
import mightypork.rogue.world.item.Items;
public class TreasureRoom extends SecretRoom {
@Override
protected void buildExtras(ScratchMap map, MapTheme theme, Random rand, Coord min, Coord max)
{
for (int i = 0; i < Calc.randInt(rand, 0, 1); i++) {
map.putItemInArea(Items.SANDWICH.createItem(), min, max, 50);
}
for (int i = 0; i < Calc.randInt(rand, 0, 2); i++) {
map.putItemInArea(Items.BONE.createItemDamaged(20), min, max, 50);
}
for (int i = 0; i < Calc.randInt(rand, 0, 1); i++) {
map.putItemInArea(Items.ROCK.createItemDamaged(30), min, max, 50);
}
for (int i = 0; i < Calc.randInt(rand, 0, 2); i++) {
map.putItemInArea(Items.MEAT.createItem(), min, max, 50);
}
for (int i = 0; i < Calc.randInt(rand, 0, 2); i++) {
map.putItemInArea(Items.CHEESE.createItem(), min, max, 50);
}
}
}

@ -11,6 +11,7 @@ import mightypork.gamecore.util.ion.IonObjBlob;
import mightypork.gamecore.util.ion.IonOutput; import mightypork.gamecore.util.ion.IonOutput;
import mightypork.gamecore.util.math.Calc; import mightypork.gamecore.util.math.Calc;
import mightypork.gamecore.util.math.constraints.rect.Rect; import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.rogue.world.World.PlayerFacade;
public abstract class Item implements IonObjBlob { public abstract class Item implements IonObjBlob {
@ -139,6 +140,7 @@ public abstract class Item implements IonObjBlob {
final int realRemoved = Math.min(removed, amount); final int realRemoved = Math.min(removed, amount);
final Item newItm = model.createItem(); final Item newItm = model.createItem();
newItm.uses = uses;
newItm.amount = realRemoved; newItm.amount = realRemoved;
this.amount -= realRemoved; this.amount -= realRemoved;
@ -188,4 +190,11 @@ public abstract class Item implements IonObjBlob {
public abstract String getVisualName(); public abstract String getVisualName();
@DefaultImpl
public boolean pickUp(PlayerFacade pl)
{
return pl.addItem(this);
}
} }

@ -3,5 +3,5 @@ package mightypork.rogue.world.item;
public enum ItemType public enum ItemType
{ {
FOOD, WEAPON; FOOD, WEAPON, ACTIVE;
} }

@ -6,6 +6,7 @@ import java.util.Collection;
import mightypork.gamecore.util.ion.IonInput; import mightypork.gamecore.util.ion.IonInput;
import mightypork.gamecore.util.ion.IonOutput; import mightypork.gamecore.util.ion.IonOutput;
import mightypork.rogue.world.item.items.active.ItemHeartPiece;
import mightypork.rogue.world.item.items.food.ItemCheese; import mightypork.rogue.world.item.items.food.ItemCheese;
import mightypork.rogue.world.item.items.food.ItemMeat; import mightypork.rogue.world.item.items.food.ItemMeat;
import mightypork.rogue.world.item.items.food.ItemSandwich; import mightypork.rogue.world.item.items.food.ItemSandwich;
@ -33,6 +34,7 @@ public final class Items {
public static final ItemModel HAMMER = new ItemModel(6, ItemHammer.class); public static final ItemModel HAMMER = new ItemModel(6, ItemHammer.class);
public static final ItemModel SWORD = new ItemModel(7, ItemSword.class); public static final ItemModel SWORD = new ItemModel(7, ItemSword.class);
public static final ItemModel ROCK = new ItemModel(8, ItemStone.class); public static final ItemModel ROCK = new ItemModel(8, ItemStone.class);
public static final ItemModel HEART_PIECE = new ItemModel(9, ItemHeartPiece.class);
public static void register(int id, ItemModel model) public static void register(int id, ItemModel model)
@ -79,12 +81,6 @@ public final class Items {
} }
public static Item create(int tileId)
{
return get(tileId).createItem();
}
public static void loadItems(IonInput in, Collection<Item> items) throws IOException public static void loadItems(IonInput in, Collection<Item> items) throws IOException
{ {
items.clear(); items.clear();

@ -0,0 +1,86 @@
package mightypork.rogue.world.item.items.active;
import mightypork.rogue.Res;
import mightypork.rogue.world.World.PlayerFacade;
import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.item.ItemModel;
import mightypork.rogue.world.item.ItemRenderer;
import mightypork.rogue.world.item.ItemType;
import mightypork.rogue.world.item.render.QuadItemRenderer;
public class ItemHeartPiece extends Item {
public ItemHeartPiece(ItemModel model)
{
super(model);
}
@Override
protected ItemRenderer makeRenderer()
{
return new QuadItemRenderer(this, Res.txq("item.heart_piece"));
}
@Override
protected boolean isStackable()
{
return false;
}
@Override
public int getAttackPoints()
{
return 0;
}
@Override
public int getFoodPoints()
{
return 0;
}
@Override
public ItemType getType()
{
return ItemType.ACTIVE;
}
@Override
public int getMaxUses()
{
return 1;
}
@Override
public boolean isDamageable()
{
return false;
}
@Override
public String getVisualName()
{
return "Heart Piece";
}
@Override
public boolean pickUp(PlayerFacade pl)
{
pl.setHealthMax(pl.getHealthMax() + 2); // two points / heart
pl.setHealth(pl.getHealthMax());
return true;
}
}

@ -33,7 +33,7 @@ public class ItemClub extends ItemBaseWeapon {
@Override @Override
public int getMaxUses() public int getMaxUses()
{ {
return 25; return 40;
} }

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

@ -33,7 +33,7 @@ public class ItemStone extends ItemBaseWeapon {
@Override @Override
public int getMaxUses() public int getMaxUses()
{ {
return 20; return 30;
} }

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

@ -393,7 +393,11 @@ public class Level implements BusAccess, Updateable, DelegatingClient, Toggleabl
if (removed == null) throw new NullPointerException("No such entity in level: " + eid); if (removed == null) throw new NullPointerException("No such entity in level: " + eid);
if (removed instanceof PlayerEntity) playerCount--; if (removed instanceof PlayerEntity) playerCount--;
entityList.remove(removed); entityList.remove(removed);
freeTile(removed.getCoord());
// upon kill, entities free tile themselves.
if (!removed.isDead()) {
freeTile(removed.getCoord());
}
} }

Loading…
Cancel
Save