Improved renderer, rats drop meat & player picks it.
This commit is contained in:
@@ -153,7 +153,6 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
|
||||
|
||||
// flip Y axis
|
||||
pos.setY(Display.getHeight() - pos.y());
|
||||
move.mul(1, -1, 1);
|
||||
|
||||
if (button != -1 || wheeld != 0) {
|
||||
getEventBus().send(new MouseButtonEvent(pos.freeze(), button, down, wheeld));
|
||||
|
||||
@@ -135,7 +135,7 @@ public class Inventory implements IonObjBinary {
|
||||
// try to merge with another item
|
||||
for (int i = 0; i < getSize(); i++) {
|
||||
final Item itm = getItem(i);
|
||||
if (itm != null && itm.canStackWith(stored)) {
|
||||
if (itm != null) {
|
||||
if (itm.addItem(stored)) return true;
|
||||
}
|
||||
}
|
||||
@@ -152,4 +152,22 @@ public class Inventory implements IonObjBinary {
|
||||
// could not insert.
|
||||
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) {
|
||||
|
||||
// 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) {
|
||||
prey.receiveAttack(getPlayer().getEntity(), getPlayer().getAttackStrength());
|
||||
return true;
|
||||
|
||||
@@ -203,7 +203,6 @@ public abstract class Entity implements IonObjBundled, Updateable {
|
||||
@DefaultImpl
|
||||
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.events.PlayerKilledEvent;
|
||||
import mightypork.rogue.world.events.PlayerStepEndEvent;
|
||||
import mightypork.rogue.world.item.Item;
|
||||
import mightypork.rogue.world.tile.Tile;
|
||||
|
||||
|
||||
public class PlayerEntity extends Entity {
|
||||
@@ -35,6 +37,18 @@ public class PlayerEntity extends Entity {
|
||||
{
|
||||
entity.getLevel().explore(entity.pos.getCoord());
|
||||
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
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ import mightypork.rogue.world.entity.EntityPathFinder;
|
||||
import mightypork.rogue.world.entity.EntityType;
|
||||
import mightypork.rogue.world.entity.render.EntityRenderer;
|
||||
import mightypork.rogue.world.entity.render.EntityRendererMobLR;
|
||||
import mightypork.rogue.world.item.Item;
|
||||
import mightypork.rogue.world.item.Items;
|
||||
|
||||
|
||||
public class RatEntity extends Entity {
|
||||
@@ -28,11 +30,11 @@ public class RatEntity extends Entity {
|
||||
pos.addMoveListener(ai);
|
||||
|
||||
pos.setStepTime(0.5);
|
||||
setDespawnDelay(2);
|
||||
setDespawnDelay(1);
|
||||
|
||||
health.setMaxHealth(3 + rand.nextInt(3));
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@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.TxSheet;
|
||||
import mightypork.gamecore.util.math.Calc;
|
||||
import mightypork.gamecore.util.math.Easing;
|
||||
import mightypork.gamecore.util.math.color.Color;
|
||||
import mightypork.gamecore.util.math.constraints.num.Num;
|
||||
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();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package mightypork.rogue.world.item;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import mightypork.gamecore.logging.Log;
|
||||
import mightypork.gamecore.util.annot.DefaultImpl;
|
||||
import mightypork.gamecore.util.ion.IonInput;
|
||||
import mightypork.gamecore.util.ion.IonObjBlob;
|
||||
@@ -61,7 +62,7 @@ public abstract class Item implements IonObjBlob {
|
||||
@DefaultImpl
|
||||
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)
|
||||
{
|
||||
if (!canStackWith(added)) return false;
|
||||
if (added.isEmpty()) return true;
|
||||
|
||||
final int room = getMaxStackSize() - this.amount;
|
||||
final int avail = added.amount;
|
||||
@@ -148,4 +150,11 @@ public abstract class Item implements IonObjBlob {
|
||||
|
||||
|
||||
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 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;
|
||||
|
||||
@@ -210,10 +210,10 @@ public class Level implements BusAccess, Updateable, DelegatingClient, Toggleabl
|
||||
}
|
||||
|
||||
// load entities
|
||||
Entities.loadEntities(in, entitySet);
|
||||
Entities.loadEntities(in, entityList);
|
||||
|
||||
// prepare entities
|
||||
for (final Entity ent : entitySet) {
|
||||
for (final Entity ent : entityList) {
|
||||
ent.setLevel(this);
|
||||
occupyTile(ent.getCoord());
|
||||
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;
|
||||
|
||||
if (timeSinceLastEntitySort > 0.2) {
|
||||
Collections.sort(entitySet, ENTITY_RENDER_CMP);
|
||||
Collections.sort(entityList, ENTITY_RENDER_CMP);
|
||||
timeSinceLastEntitySort = 0;
|
||||
}
|
||||
|
||||
@@ -271,7 +271,7 @@ public class Level implements BusAccess, Updateable, DelegatingClient, Toggleabl
|
||||
|
||||
final List<Entity> toRemove = new ArrayList<>();
|
||||
|
||||
for (final Entity e : entitySet) {
|
||||
for (final Entity e : entityList) {
|
||||
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);
|
||||
entitySet.add(entity);
|
||||
entityList.add(entity);
|
||||
if (entity instanceof PlayerEntity) playerCount++;
|
||||
|
||||
// join to level & world
|
||||
@@ -358,7 +358,7 @@ public class Level implements BusAccess, Updateable, DelegatingClient, Toggleabl
|
||||
final Entity removed = entityMap.remove(eid);
|
||||
if (removed == null) throw new NullPointerException("No such entity in level: " + eid);
|
||||
if (removed instanceof PlayerEntity) playerCount--;
|
||||
entitySet.remove(removed);
|
||||
entityList.remove(removed);
|
||||
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);
|
||||
|
||||
for (final Entity e : entitySet) {
|
||||
for (final Entity e : entityList) {
|
||||
if (e.isDead()) continue;
|
||||
|
||||
if (e.getType() == type) {
|
||||
@@ -578,7 +578,7 @@ public class Level implements BusAccess, Updateable, DelegatingClient, Toggleabl
|
||||
{
|
||||
if (getTile(pos).isOccupied()) {
|
||||
final Set<Entity> toButcher = new HashSet<>();
|
||||
for (final Entity e : entitySet) {
|
||||
for (final Entity e : entityList) {
|
||||
if (e.getCoord().equals(pos)) {
|
||||
toButcher.add(e);
|
||||
break;
|
||||
@@ -602,7 +602,7 @@ public class Level implements BusAccess, Updateable, DelegatingClient, Toggleabl
|
||||
*/
|
||||
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()
|
||||
{
|
||||
return entitySet;
|
||||
return entityList;
|
||||
}
|
||||
|
||||
|
||||
@@ -647,7 +647,7 @@ public class Level implements BusAccess, Updateable, DelegatingClient, Toggleabl
|
||||
@Override
|
||||
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_SW = Res.txq("tile.ufog.sw");
|
||||
UFOG_SE = Res.txq("tile.ufog.se");
|
||||
inited = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user