Rogue: Savage Rats, a retro-themed dungeon crawler
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.
rogue-savage-rats/src/mightypork/rogue/world/tile/DroppedItemRenderer.java

45 lines
1.2 KiB

package mightypork.rogue.world.tile;
import mightypork.gamecore.util.math.Easing;
import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.gamecore.util.math.constraints.rect.proxy.RectBoundAdapter;
import mightypork.gamecore.util.math.timing.Animator;
import mightypork.gamecore.util.math.timing.AnimatorBounce;
import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.level.render.TileRenderContext;
public class DroppedItemRenderer {
private Animator itemAnim = new AnimatorBounce(2, Easing.SINE_BOTH);
// prepared constraints, to avoid re-building each frame
private final RectBoundAdapter tileRectAdapter = new RectBoundAdapter();
10 years ago
private final Rect itemRect = tileRectAdapter
.shrink(tileRectAdapter.height().perc(10))
.moveY(itemAnim.neg().mul(tileRectAdapter.height().mul(0.2)));
public Animator getItemAnim()
{
if (itemAnim == null) {
itemAnim = new AnimatorBounce(2, Easing.SINE_BOTH);
}
return itemAnim;
}
public void render(Item item, TileRenderContext context)
{
tileRectAdapter.setRect(context);
item.render(itemRect);
}
10 years ago
public void update(double delta)
{
itemAnim.update(delta);
}
}