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

import entities.GLConfigVariable;
import entities.Pair;
import entities.TileType;
import models.IModel;

import java.util.ArrayList;

//---------------------------------------------------------------
// タイル生成
public class TileMapRenderer implements IView {

    private double offsetY = 256d;
    private TileRenderer newTile = new TileRenderer("resources/tile.png", null, 2);
    private ArrayList<TileRenderer> tiles = new ArrayList<>();
    private int tileLen = 150; //

    //---------------------------------------------------------------
    //---------------------------------------------------------------
    public TileMapRenderer() {
        initTiles();
    }

    //---------------------------------------------------------------
    //---------------------------------------------------------------
    //
    @Override
    public void update(IModel model) {
        for (TileRenderer tile : tiles) tile.update(model);
    }

    //---------------------------------------------------------------
    //
    @Override
    public void display() {
        for (TileRenderer tile : tiles) tile.display();
    }

    //---------------------------------------------------------------
    // 破棄
    @Override
    public void delete() {
        for (TileRenderer tile : tiles) tile.delete();
    }


    //--------------------------------------------------------------
    //---------------------------------------------------------------
    // 初期タイル作成
    private void initTiles() {

        for (int i = 0; i < tileLen; i++) {
            double x = 32 * newTile.getScaleValue() * i;

            newTile = new TileRenderer("resources/tile.png", new Pair<>(x, offsetY));
            newTile.setScaleValue(2);
            tiles.add(newTile);
        }
    }

    //--------------------------------------------------------------
    // タイルをフラグに応じて生成する
    private void createTile(TileType tileType) {

        switch (tileType) {
            case CLOSE:
                newTile = new TileRenderer("resources/tile.png", new Pair<>((double) GLConfigVariable.WIDTH, 0d), 2);
                break;

            case OPEN:
                newTile = new TileRenderer("resources/hole.png", new Pair<>((double) GLConfigVariable.WIDTH, 0d), 2);
                break;
        }

        tiles.add(newTile);
    }

    //---------------------------------------------------------------
}