Package game.layers

Source Code of game.layers.BlocksLayer

package game.layers;

import engine.classes.Colour;
import engine.hierarchy.DefaultLayer;
import engine.interfaces.RenderTarget;
import game.scenes.LevelScene;
import game.terrain.Block;

public class BlocksLayer extends DefaultLayer {
    private Block[][] blocks;

    public BlocksLayer(Block[][] blocks) {
        this.blocks = blocks;
    }

    @Override
    protected void onDraw(RenderTarget target) {
        double viewX = ((LevelScene) getScene()).getViewX();
        double viewY = ((LevelScene) getScene()).getViewY();

        int r1 = (int) Math.max(0, Math.floor(viewY / Block.HEIGHT));
        int r2 = (int) Math.min(blocks.length - 1, Math.ceil((viewY + 480) / Block.HEIGHT));
        int c1 = (int) Math.max(0, Math.floor(viewX / Block.WIDTH));
        int c2 = (int) Math.min(blocks[0].length - 1, Math.ceil((viewX + 640) / Block.WIDTH));

        Colour grey = new Colour(128, 128, 128, 128);
        for (int r = r1; r <= r2; r++) {
            for (int c = c1; c <= c2; c++) {
                if (blocks[r][c].getPolygon() != null) {
                    target.fillPolygon(blocks[r][c].getPolygon(), grey);
                }
            }
        }
    }
}
TOP

Related Classes of game.layers.BlocksLayer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.