You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.4 KiB
51 lines
1.4 KiB
package mightypork.rogue.world.entity.renderers;
|
|
|
|
|
|
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.constraints.rect.Rect;
|
|
import mightypork.gamecore.util.math.constraints.vect.Vect;
|
|
import mightypork.rogue.Res;
|
|
import mightypork.rogue.world.entity.Entity;
|
|
import mightypork.rogue.world.level.render.MapRenderContext;
|
|
|
|
|
|
/**
|
|
* Renderer for a walking mob with only one strip (right sided), which is
|
|
* flipped for walking left.
|
|
*
|
|
* @author MightyPork
|
|
*/
|
|
public class EntityRendererMobLR extends EntityRenderer {
|
|
|
|
private final TxSheet sheet;
|
|
|
|
protected final Entity entity;
|
|
|
|
|
|
public EntityRendererMobLR(Entity entity, String sheetKey)
|
|
{
|
|
this.entity = entity;
|
|
this.sheet = Res.sheet(sheetKey);
|
|
}
|
|
|
|
|
|
@Override
|
|
public void render(MapRenderContext context)
|
|
{
|
|
TxQuad q = sheet.getQuad(Calc.frag(entity.pos.getProgress()));
|
|
|
|
if (entity.pos.lastXDir == -1) q = q.flipX();
|
|
|
|
final Rect tileRect = context.getRectForTile(entity.pos.getCoord());
|
|
final double w = tileRect.width().value();
|
|
final Vect visualPos = entity.pos.getVisualPos();
|
|
|
|
Rect spriteRect = Rect.make(visualPos.x() * w, visualPos.y() * w, w, w);
|
|
spriteRect = spriteRect.shrink(w * 0.05);
|
|
|
|
Render.quadTextured(spriteRect, q);
|
|
}
|
|
}
|
|
|