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

import entities.Pair;
import models.IModel;
import models.JumpGameModel;

//---------------------------------------------------------------
// タイルの描画
public class TileRenderer implements IView {
    private Sprite sprite;
    private Pair<Double> initPositionValue;

    //---------------------------------------------------------------
    //---------------------------------------------------------------
    //
    public TileRenderer(String path, Pair<Double> initPosition) {
        this.initPositionValue = initPosition;
        this.sprite = new Sprite(path);
        this.sprite.setScaleValue(1);
        this.sprite.setPositionValue(initPosition);
    }

    //---------------------------------------------------------------
    public TileRenderer(String path, Pair<Double> initPosition, double scale) {
        this.initPositionValue = initPosition;
        this.sprite = new Sprite(path);
        this.sprite.setScaleValue(scale);
        this.sprite.setPositionValue(initPosition);
    }

    //---------------------------------------------------------------
    //---------------------------------------------------------------
    // getter
    public double getScaleValue() {
        return this.sprite.getScaleValue();
    }

    //---------------------------------------------------------------
    //---------------------------------------------------------------
    // setter
    public void setScaleValue(double scaleValue) {
        this.sprite.setScaleValue(scaleValue);
    }

    //---------------------------------------------------------------
    //---------------------------------------------------------------
    //
    @Override
    public void update(IModel model) {
        JumpGameModel jumpGameModel = (JumpGameModel) model;

        Double x = this.initPositionValue.getLeft() - (jumpGameModel.getPosition().getLeft() * 64);
        Double y = this.sprite.getPositionValue().getRight();

        this.sprite.setPositionValue(new Pair<>(x, y));
    }

    //---------------------------------------------------------------
    // 描画
    @Override
    public void display() {
        sprite.draw();
    }

    //---------------------------------------------------------------
    // テクスチャの開放
    @Override
    public void delete() {
        sprite.delete();
    }
}