parent
3e69505787
commit
6761b69b63
After Width: | Height: | Size: 835 B |
Binary file not shown.
After Width: | Height: | Size: 3.7 KiB |
Binary file not shown.
@ -0,0 +1,46 @@ |
||||
package mightypork.rogue.world; |
||||
|
||||
|
||||
import mightypork.rogue.world.entity.models.EntityMoveListener; |
||||
|
||||
|
||||
public class PlayerControl { |
||||
|
||||
private final World world; |
||||
|
||||
|
||||
public PlayerControl(World w) |
||||
{ |
||||
this.world = w; |
||||
} |
||||
|
||||
|
||||
public void walkNorth() |
||||
{ |
||||
world.playerEntity.addStep(PathStep.NORTH); |
||||
} |
||||
|
||||
|
||||
public void walkSouth() |
||||
{ |
||||
world.playerEntity.addStep(PathStep.SOUTH); |
||||
} |
||||
|
||||
|
||||
public void walkEast() |
||||
{ |
||||
world.playerEntity.addStep(PathStep.EAST); |
||||
} |
||||
|
||||
|
||||
public void walkWest() |
||||
{ |
||||
world.playerEntity.addStep(PathStep.WEST); |
||||
} |
||||
|
||||
|
||||
public void addMoveListener(EntityMoveListener eml) |
||||
{ |
||||
world.playerEntity.addMoveListener(eml); |
||||
} |
||||
} |
@ -0,0 +1,28 @@ |
||||
package mightypork.rogue.world.entity.models; |
||||
|
||||
|
||||
import mightypork.rogue.world.World; |
||||
import mightypork.rogue.world.entity.Entity; |
||||
import mightypork.rogue.world.level.Level; |
||||
|
||||
|
||||
public interface EntityMoveListener { |
||||
|
||||
/** |
||||
* One step of a path finished |
||||
*/ |
||||
void onStepFinished(Entity entity, World world, Level level); |
||||
|
||||
|
||||
/** |
||||
* Scheduled path finished |
||||
*/ |
||||
void onPathFinished(Entity entity, World world, Level level); |
||||
|
||||
|
||||
/** |
||||
* Path was aborted (bumped into a wall or entity) |
||||
*/ |
||||
void onPathAborted(Entity entity, World world, Level level); |
||||
|
||||
} |
@ -1,8 +1,15 @@ |
||||
package mightypork.rogue.world.entity.renderers; |
||||
|
||||
|
||||
public class EntityRenderer { |
||||
import mightypork.rogue.world.entity.Entity; |
||||
import mightypork.rogue.world.level.render.EntityRenderContext; |
||||
|
||||
|
||||
public abstract class EntityRenderer { |
||||
|
||||
public static final EntityRenderer NONE = new NullEntityRenderer(); |
||||
|
||||
|
||||
public abstract void render(Entity entity, EntityRenderContext context); |
||||
|
||||
} |
||||
|
@ -1,6 +1,16 @@ |
||||
package mightypork.rogue.world.entity.renderers; |
||||
|
||||
|
||||
import mightypork.rogue.world.entity.Entity; |
||||
import mightypork.rogue.world.level.render.EntityRenderContext; |
||||
|
||||
|
||||
public class NullEntityRenderer extends EntityRenderer { |
||||
|
||||
@Override |
||||
public void render(Entity entity, EntityRenderContext context) |
||||
{ |
||||
// hell no
|
||||
} |
||||
|
||||
} |
||||
|
@ -0,0 +1,43 @@ |
||||
package mightypork.rogue.world.entity.renderers; |
||||
|
||||
|
||||
import mightypork.gamecore.render.Render; |
||||
import mightypork.gamecore.render.textures.TxQuad; |
||||
import mightypork.gamecore.render.textures.TxSheet; |
||||
import mightypork.rogue.Res; |
||||
import mightypork.rogue.world.WorldPos; |
||||
import mightypork.rogue.world.entity.Entity; |
||||
import mightypork.rogue.world.level.render.EntityRenderContext; |
||||
import mightypork.util.constraints.rect.Rect; |
||||
import mightypork.util.math.Calc; |
||||
|
||||
|
||||
public class PlayerRenderer extends EntityRenderer { |
||||
|
||||
TxSheet sheet; |
||||
|
||||
|
||||
public PlayerRenderer(String sheetKey) |
||||
{ |
||||
this.sheet = Res.getTxSheet(sheetKey); // expects 1x4
|
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void render(Entity entity, EntityRenderContext context) |
||||
{ |
||||
TxQuad q = sheet.getQuad(Calc.frag(entity.getPosition().getProgress())); |
||||
|
||||
if (entity.lastXMove == -1) q = q.flipX(); |
||||
|
||||
final WorldPos pos = entity.getPosition(); |
||||
|
||||
final Rect tileRect = context.getRectForTile(pos.x, pos.y); |
||||
final double w = tileRect.width().value(); |
||||
|
||||
Rect spriteRect = tileRect.move(pos.getVisualXOffset() * w, pos.getVisualYOffset() * w + w * 0.1); |
||||
spriteRect = spriteRect.shrink(w * 0.1); |
||||
|
||||
Render.quadTextured(spriteRect, q); |
||||
} |
||||
} |
Loading…
Reference in new issue