Improved renderer, rats drop meat & player picks it.

v5stable
Ondřej Hruška 11 years ago
parent 5c329e8636
commit 20bebf268b
  1. 1
      src/mightypork/gamecore/input/InputSystem.java
  2. 20
      src/mightypork/rogue/world/Inventory.java
  3. 2
      src/mightypork/rogue/world/PlayerControl.java
  4. 1
      src/mightypork/rogue/world/entity/Entity.java
  5. 16
      src/mightypork/rogue/world/entity/entities/PlayerEntity.java
  6. 18
      src/mightypork/rogue/world/entity/entities/RatEntity.java
  7. 6
      src/mightypork/rogue/world/entity/render/EntityRendererMobLR.java
  8. 11
      src/mightypork/rogue/world/item/Item.java
  9. 26
      src/mightypork/rogue/world/level/Level.java
  10. 1
      src/mightypork/rogue/world/tile/TileRenderer.java

@ -153,7 +153,6 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
// flip Y axis // flip Y axis
pos.setY(Display.getHeight() - pos.y()); pos.setY(Display.getHeight() - pos.y());
move.mul(1, -1, 1);
if (button != -1 || wheeld != 0) { if (button != -1 || wheeld != 0) {
getEventBus().send(new MouseButtonEvent(pos.freeze(), button, down, wheeld)); getEventBus().send(new MouseButtonEvent(pos.freeze(), button, down, wheeld));

@ -135,7 +135,7 @@ public class Inventory implements IonObjBinary {
// try to merge with another item // try to merge with another item
for (int i = 0; i < getSize(); i++) { for (int i = 0; i < getSize(); i++) {
final Item itm = getItem(i); final Item itm = getItem(i);
if (itm != null && itm.canStackWith(stored)) { if (itm != null) {
if (itm.addItem(stored)) return true; if (itm.addItem(stored)) return true;
} }
} }
@ -152,4 +152,22 @@ public class Inventory implements IonObjBinary {
// could not insert. // could not insert.
return false; return false;
} }
@Override
public String toString()
{
String s = "Inv[";
for (int i = 0; i < getSize(); i++) {
if (i > 0) s += ", ";
s += i + ": ";
final Item itm = getItem(i);
if (itm == null) s += "<null>";
else s += itm;
}
s += "]";
return s;
}
} }

@ -110,7 +110,7 @@ public abstract class PlayerControl {
if (pos.dist(getPlayer().getVisualPos().add(0.5, 0.5)).value() < 1.5) { if (pos.dist(getPlayer().getVisualPos().add(0.5, 0.5)).value() < 1.5) {
// 1st try to hit entity // 1st try to hit entity
final Entity prey = getLevel().getClosestEntity(pos, EntityType.MONSTER, 1.2); final Entity prey = getLevel().getClosestEntity(pos, EntityType.MONSTER, 1);
if (prey != null) { if (prey != null) {
prey.receiveAttack(getPlayer().getEntity(), getPlayer().getAttackStrength()); prey.receiveAttack(getPlayer().getEntity(), getPlayer().getAttackStrength());
return true; return true;

@ -203,7 +203,6 @@ public abstract class Entity implements IonObjBundled, Updateable {
@DefaultImpl @DefaultImpl
public void onKilled() public void onKilled()
{ {
getLevel().freeTile(getCoord());
} }

@ -13,6 +13,8 @@ import mightypork.rogue.world.entity.render.EntityRenderer;
import mightypork.rogue.world.entity.render.EntityRendererMobLR; import mightypork.rogue.world.entity.render.EntityRendererMobLR;
import mightypork.rogue.world.events.PlayerKilledEvent; import mightypork.rogue.world.events.PlayerKilledEvent;
import mightypork.rogue.world.events.PlayerStepEndEvent; import mightypork.rogue.world.events.PlayerStepEndEvent;
import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.tile.Tile;
public class PlayerEntity extends Entity { public class PlayerEntity extends Entity {
@ -35,6 +37,18 @@ public class PlayerEntity extends Entity {
{ {
entity.getLevel().explore(entity.pos.getCoord()); entity.getLevel().explore(entity.pos.getCoord());
fireEvt(); fireEvt();
// try to pickup items
final Tile t = getLevel().getTile(getCoord());
if (t.hasItem()) {
final Item item = t.pickItem();
if (getWorld().getPlayer().getInventory().addItem(item)) {
// player picked item
} else {
t.dropItem(item); // put back.
}
}
} }
@ -125,7 +139,7 @@ public class PlayerEntity extends Entity {
@Override @Override
public void onKilled() public void onKilled()
{ {
// send kill event to listeners (GUI?) // send kill event to listeners, after the entity has despawned (disappeared)
getWorld().getEventBus().sendDelayed(new PlayerKilledEvent(), getDespawnDelay()); getWorld().getEventBus().sendDelayed(new PlayerKilledEvent(), getDespawnDelay());
} }
} }

@ -8,6 +8,8 @@ import mightypork.rogue.world.entity.EntityPathFinder;
import mightypork.rogue.world.entity.EntityType; import mightypork.rogue.world.entity.EntityType;
import mightypork.rogue.world.entity.render.EntityRenderer; import mightypork.rogue.world.entity.render.EntityRenderer;
import mightypork.rogue.world.entity.render.EntityRendererMobLR; import mightypork.rogue.world.entity.render.EntityRendererMobLR;
import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.item.Items;
public class RatEntity extends Entity { public class RatEntity extends Entity {
@ -28,11 +30,11 @@ public class RatEntity extends Entity {
pos.addMoveListener(ai); pos.addMoveListener(ai);
pos.setStepTime(0.5); pos.setStepTime(0.5);
setDespawnDelay(2); setDespawnDelay(1);
health.setMaxHealth(3 + rand.nextInt(3)); health.setMaxHealth(3 + rand.nextInt(3));
health.fill(); // fill health bar to max health.fill(); // fill health bar to max
health.setHitCooldownTime(0.2); health.setHitCooldownTime(0.3);
} }
@ -64,4 +66,16 @@ public class RatEntity extends Entity {
return renderer; return renderer;
} }
@Override
public void onKilled()
{
super.onKilled();
// drop rat meat
final Item meat = Items.MEAT.createItem();
getLevel().getTile(getCoord()).dropItem(meat);
}
} }

@ -5,6 +5,7 @@ import mightypork.gamecore.render.Render;
import mightypork.gamecore.resources.textures.TxQuad; import mightypork.gamecore.resources.textures.TxQuad;
import mightypork.gamecore.resources.textures.TxSheet; import mightypork.gamecore.resources.textures.TxSheet;
import mightypork.gamecore.util.math.Calc; 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.constraints.num.Num; import mightypork.gamecore.util.math.constraints.num.Num;
import mightypork.gamecore.util.math.constraints.num.mutable.NumVar; import mightypork.gamecore.util.math.constraints.num.mutable.NumVar;
@ -70,7 +71,10 @@ public class EntityRendererMobLR extends EntityRenderer {
final double hw = spriteRect.width().half().value(); final double hw = spriteRect.width().half().value();
Render.quadTextured(Vect.ZERO.expand(hw, hw, hw, hw), q, hue.withAlpha(entity.isDead() ? 1 - hurtTime / 2 : 1)); Render.quadTextured(
Vect.ZERO.expand(hw, hw, hw, hw),
q,
hue.withAlpha(entity.isDead() ? 1 - Easing.CIRC_IN.get(hurtTime / entity.getDespawnDelay()) : 1));
Render.popMatrix(); Render.popMatrix();
} }
} }

@ -3,6 +3,7 @@ package mightypork.rogue.world.item;
import java.io.IOException; import java.io.IOException;
import mightypork.gamecore.logging.Log;
import mightypork.gamecore.util.annot.DefaultImpl; import mightypork.gamecore.util.annot.DefaultImpl;
import mightypork.gamecore.util.ion.IonInput; import mightypork.gamecore.util.ion.IonInput;
import mightypork.gamecore.util.ion.IonObjBlob; import mightypork.gamecore.util.ion.IonObjBlob;
@ -61,7 +62,7 @@ public abstract class Item implements IonObjBlob {
@DefaultImpl @DefaultImpl
protected int getMaxStackSize() protected int getMaxStackSize()
{ {
return isStackable() ? 1 : 65535; return isStackable() ? 65535 : 1;
} }
@ -85,6 +86,7 @@ public abstract class Item implements IonObjBlob {
public boolean addItem(Item added) public boolean addItem(Item added)
{ {
if (!canStackWith(added)) return false; if (!canStackWith(added)) return false;
if (added.isEmpty()) return true;
final int room = getMaxStackSize() - this.amount; final int room = getMaxStackSize() - this.amount;
final int avail = added.amount; final int avail = added.amount;
@ -148,4 +150,11 @@ public abstract class Item implements IonObjBlob {
public abstract ItemType getType(); public abstract ItemType getType();
@Override
public String toString()
{
return Log.str(getClass()) + " x " + getAmount();
}
} }

@ -72,7 +72,7 @@ public class Level implements BusAccess, Updateable, DelegatingClient, Toggleabl
private Tile[][] tiles; private Tile[][] tiles;
private final Map<Integer, Entity> entityMap = new HashMap<>(); private final Map<Integer, Entity> entityMap = new HashMap<>();
private final List<Entity> entitySet = new LinkedList<>(); private final List<Entity> entityList = new LinkedList<>();
private int playerCount = 0; private int playerCount = 0;
@ -210,10 +210,10 @@ public class Level implements BusAccess, Updateable, DelegatingClient, Toggleabl
} }
// load entities // load entities
Entities.loadEntities(in, entitySet); Entities.loadEntities(in, entityList);
// prepare entities // prepare entities
for (final Entity ent : entitySet) { for (final Entity ent : entityList) {
ent.setLevel(this); ent.setLevel(this);
occupyTile(ent.getCoord()); occupyTile(ent.getCoord());
entityMap.put(ent.getEntityId(), ent); entityMap.put(ent.getEntityId(), ent);
@ -241,7 +241,7 @@ public class Level implements BusAccess, Updateable, DelegatingClient, Toggleabl
} }
} }
Entities.saveEntities(out, entitySet); Entities.saveEntities(out, entityList);
} }
@ -258,7 +258,7 @@ public class Level implements BusAccess, Updateable, DelegatingClient, Toggleabl
timeSinceLastEntitySort += delta; timeSinceLastEntitySort += delta;
if (timeSinceLastEntitySort > 0.2) { if (timeSinceLastEntitySort > 0.2) {
Collections.sort(entitySet, ENTITY_RENDER_CMP); Collections.sort(entityList, ENTITY_RENDER_CMP);
timeSinceLastEntitySort = 0; timeSinceLastEntitySort = 0;
} }
@ -271,7 +271,7 @@ public class Level implements BusAccess, Updateable, DelegatingClient, Toggleabl
final List<Entity> toRemove = new ArrayList<>(); final List<Entity> toRemove = new ArrayList<>();
for (final Entity e : entitySet) { for (final Entity e : entityList) {
if (e.isDead() && e.canRemoveCorpse()) toRemove.add(e); if (e.isDead() && e.canRemoveCorpse()) toRemove.add(e);
} }
@ -324,7 +324,7 @@ public class Level implements BusAccess, Updateable, DelegatingClient, Toggleabl
} }
entityMap.put(entity.getEntityId(), entity); entityMap.put(entity.getEntityId(), entity);
entitySet.add(entity); entityList.add(entity);
if (entity instanceof PlayerEntity) playerCount++; if (entity instanceof PlayerEntity) playerCount++;
// join to level & world // join to level & world
@ -358,7 +358,7 @@ public class Level implements BusAccess, Updateable, DelegatingClient, Toggleabl
final Entity removed = entityMap.remove(eid); final Entity removed = entityMap.remove(eid);
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--;
entitySet.remove(removed); entityList.remove(removed);
freeTile(removed.getCoord()); freeTile(removed.getCoord());
} }
@ -548,7 +548,7 @@ public class Level implements BusAccess, Updateable, DelegatingClient, Toggleabl
if (type == EntityType.MONSTER) System.out.println("Finding entity in range " + radius + " of " + pos); if (type == EntityType.MONSTER) System.out.println("Finding entity in range " + radius + " of " + pos);
for (final Entity e : entitySet) { for (final Entity e : entityList) {
if (e.isDead()) continue; if (e.isDead()) continue;
if (e.getType() == type) { if (e.getType() == type) {
@ -578,7 +578,7 @@ public class Level implements BusAccess, Updateable, DelegatingClient, Toggleabl
{ {
if (getTile(pos).isOccupied()) { if (getTile(pos).isOccupied()) {
final Set<Entity> toButcher = new HashSet<>(); final Set<Entity> toButcher = new HashSet<>();
for (final Entity e : entitySet) { for (final Entity e : entityList) {
if (e.getCoord().equals(pos)) { if (e.getCoord().equals(pos)) {
toButcher.add(e); toButcher.add(e);
break; break;
@ -602,7 +602,7 @@ public class Level implements BusAccess, Updateable, DelegatingClient, Toggleabl
*/ */
public boolean isEntityPresent(Entity entity) public boolean isEntityPresent(Entity entity)
{ {
return entitySet.contains(entity); return entityList.contains(entity);
} }
@ -625,7 +625,7 @@ public class Level implements BusAccess, Updateable, DelegatingClient, Toggleabl
*/ */
public Collection<Entity> getEntities() public Collection<Entity> getEntities()
{ {
return entitySet; return entityList;
} }
@ -647,7 +647,7 @@ public class Level implements BusAccess, Updateable, DelegatingClient, Toggleabl
@Override @Override
public Collection getChildClients() public Collection getChildClients()
{ {
return entitySet; return entityList;
} }

@ -61,6 +61,7 @@ public abstract class TileRenderer implements Updateable {
UFOG_NE = Res.txq("tile.ufog.ne"); UFOG_NE = Res.txq("tile.ufog.ne");
UFOG_SW = Res.txq("tile.ufog.sw"); UFOG_SW = Res.txq("tile.ufog.sw");
UFOG_SE = Res.txq("tile.ufog.se"); UFOG_SE = Res.txq("tile.ufog.se");
inited = true;
} }
} }

Loading…
Cancel
Save