Package transientlibs.maps.utils.grid

Source Code of transientlibs.maps.utils.grid.TerrainScreenGrid

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package transientlibs.maps.utils.grid;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import java.util.ArrayList;
import java.util.List;
import transientlibs.slick2d.util.Log;
import transientlibs.bindedobjects.gamecontent.Terrain;
import transientlibs.maps.container.TransientAssembledMap;
import transientlibs.maps.tiles.Tile;
import transientlibs.maps.units.GenericUnit;
import transientlibs.preui.objects.gui.elements.Marker;
import transientlibs.preui.objects.gui.interfaces.IImage;

/**
*
* @author kibertoad
*/
public class TerrainScreenGrid {

    //public FOVBoard fov;
    public List<List<Marker>> gridElements;
    public TransientAssembledMap map;
    public int startMapX;
    public int startMapY;
    public int endMapX;
    public int endMapY;
    public int screenWidthInTiles;
    public int screenHeightInTiles;
    public SpriteBatch batch;

    public TerrainScreenGrid(TransientAssembledMap map, SpriteBatch setBatch) {
        this.map = map;
        batch = setBatch;

        recalculateBorder();
        fillArrays();
    }

    public final void recalculateBorder() {
        screenWidthInTiles = (Gdx.graphics.getWidth() / Terrain.tileWidth) + 2;
        screenHeightInTiles = (Gdx.graphics.getHeight() / Terrain.tileHeight);
       
        if (screenWidthInTiles > map.sizeX) {
            screenWidthInTiles = map.sizeX;
        }

        if (screenHeightInTiles > map.sizeY) {
            screenHeightInTiles = map.sizeY;
        }
       
       
    }

    public final void fillArrays() {
        gridElements = new ArrayList<List<Marker>>();
        for (int y = 0; y <= screenHeightInTiles; y++) {
            gridElements.add(new ArrayList<Marker>());
            for (int x = 0; x <= screenWidthInTiles; x++) {

                gridElements.get(y).add(new Marker(null, 0, 0));

                gridElements.get(y).get(x).getScreenCoords().x = ((x - 1) * Terrain.tileWidth);
                gridElements.get(y).get(x).getScreenCoords().x -= (Terrain.tileWidth / 3);
                gridElements.get(y).get(x).getScreenCoords().x += Terrain.tileWidth * 1;


                gridElements.get(y).get(x).getScreenCoords().y = ((y) * Terrain.tileHeight);
                gridElements.get(y).get(x).getScreenCoords().y -= Terrain.tileHeight * 1;


                //Log.info("Height: "+Terrain.tileHeight);

                if ((x == 0) && (y == 0)) {
                    Log.info("ScreenCoords for 0/0: " + gridElements.get(y).get(x).getScreenCoords().toRoundedString());
                }

                Log.info("Cell coords: " + gridElements.get(y).get(x).getScreenCoords().toRoundedString());

                //gridElements.get(y).get(x).setBothImages((IImage)null);
                resetElement(x, y);
                //boolArray.get(y).add(false);
            }
        }
    }

    public void resetElement(int onX, int onY) {
        gridElements.get(onY).get(onX).setBothImages((IImage) null);
    }

    public void recalculateGrid(int setStartX, int setStartY) {
        startMapX = setStartX;
        startMapY = setStartY;
       
        //recalculateBorder();
        Log.warn("Grid size: "+screenWidthInTiles+"/"+screenHeightInTiles);
        Log.warn("Map size: "+map.sizeX+"/"+map.sizeY);
       

        for (int y = 0; y <= screenHeightInTiles; y++) {
            for (int x = 0; x <= screenWidthInTiles; x++) {

                {
                    Log.warn("Pull tile: "+x+"/"+y);

                    //GenericUnit u = map.getTile(startMapX + x, startMapY + y).units.get(0);
                    Tile t = map.getTile(startMapX + x, startMapY + y);

                    if (t != null) {
                        Log.warn("HAVE ONE");

                        //gridElements.get(y).get(x).setBothImages(u.getCreatures().visualInformation.cutImages.get(u.getDirection()).get(0).get(0).referencedImages);
                        gridElements.get(y).get(x).setBothImages(t.terrain.image);
                        gridElements.get(y).get(x).isDrawn = true;


                    } else {
                        resetElement(x, y);
                        gridElements.get(y).get(x).isDrawn = false;
                    }


                    //gridElements.get(y).get(x).isDrawn = (!(map.fov.wasVisited(startMapX + x, startMapY + y)));

                }
            }
        }
    }

    public void render() {
        for (int y = 0; y <= screenHeightInTiles; y++) {
            for (int x = 0; x <= screenWidthInTiles; x++) {

                Log.warn("GridElement isDrawn: "+gridElements.get(y).get(x).isDrawn);
                Log.warn("GridElement hasImage: "+(gridElements.get(y).get(x).getImage() != null));
               
                gridElements.get(y).get(x).drawTextureRegion(batch);
            }
        }
    }
}
TOP

Related Classes of transientlibs.maps.utils.grid.TerrainScreenGrid

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.