Newer
Older
JumpingGame / src / main / java / views / TileRenderer.java
k-fujii on 30 Nov 2021 2 KB 背景を追加
package views;

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

import java.lang.reflect.Parameter;

//---------------------------------------------------------------
// タイルの描画
public class TileRenderer implements IView {
    private Sprite sprite;
    private Pair<Double> initPositionValue = new Pair<>(0d,0d);

    //---------------------------------------------------------------
    //---------------------------------------------------------------
    //
    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.getFirst() - (jumpGameModel.getPosition().getValue().getFirst() * 64);
        Double y = this.sprite.getPositionValue().getSecond();

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

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

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