Newer
Older
JumpingGame / src / main / java / views / PlayerRenderer.java
package views;

import entities.Pair;
import models.IModel;
import models.JumpingGameModel;



public class PlayerRenderer implements IView {
    private Sprite sprite;

    public PlayerRenderer(String path) {
        this.sprite = new Sprite(path);
        this.sprite.setScaleValue(0.1);
        this.sprite.setPositionValue(new Pair<>(640d, 480d));
    }

    @Override
    public void update(IModel model) {
        JumpingGameModel jumpGameModel = (JumpingGameModel) model;

        double x = this.sprite.getPositionValue().getLeft();
        double y = 112 + jumpGameModel.getPosition().getRight();
        this.sprite.setPositionValue(new Pair<>(x, y));
    }

    @Override
    public void display() {
        sprite.draw();
    }

    @Override
    public void delete() {
        sprite.delete();
    }
}