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<>();

    //---------------------------------------------------------------
    //---------------------------------------------------------------
    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 < 20; i++) {
            double x = 32 * newTile.getScaleValue() * i;

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

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

        if (tileType)
            newTile = new TileRenderer("resources/tile.png", new Pair<>((double) GLConfigVariable.WIDTH, offsetY), 2);
        else
            newTile = new TileRenderer("resources/hole.png", new Pair<>((double) GLConfigVariable.WIDTH, offsetY), 2);

        tiles.add(newTile);
        System.out.println("New tile created.");
    }

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