Package transientlibs.maps.container

Source Code of transientlibs.maps.container.TiledMapGDXContainer

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

/**
*
* @author kibertoad
*/
//import com.badlogic.gdx.Gdx;
//import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TiledMapTileSet;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
import com.badlogic.gdx.physics.box2d.World;
import java.util.ArrayList;
import transientlibs.bindedobjects.gamecontent.Terrain;
import transientlibs.slick2d.util.Log;
import transientlibs.processors.misc.Detonator;
import transientlibs.maps.implementation.TiledMapGDX;
import transientlibs.objects.primitives.Coords;
//import com.badlogic.gdx.files.*;

/**
* Describe why the hell it is needed later. One obvious thing is Box2D
* integration
*/
public class TiledMapGDXContainer extends TransientAssembledMap {

    public static ArrayList<TiledMapGDXContainer> maps = new ArrayList<TiledMapGDXContainer>();
    //public OrthographicCamera camera;
    //public TileAtlas atlas;
    //public TiledMapTileSet tileSet;
    public World world;
    private static final int[] layersList = {2, 3};

    //public TiledMap map;
    public TiledMapGDX getTiledMapGDX() {
        return (TiledMapGDX) map;
    }

    @Override
    public Coords getTileScreenCoords(int x, int y) {
       
        return Detonator.INSTANCE.screenCoordsCalculator.returnScreenCoords(x, y);
       
        /*
        int realCameraX = (int) (getCameraX());
        int realCameraY = (int) ((getHeight() * getTileHeight()) - getCameraY());

        realCameraX += (Detonator.INSTANCE.ScreenSizeX / 2);
        realCameraY += (Detonator.INSTANCE.ScreenSizeY / 2);

        realCameraX -= Detonator.INSTANCE.ScreenSizeX;
        realCameraY -= Detonator.INSTANCE.ScreenSizeY;


        int actualX = (x * Terrain.tileWidth) - realCameraX;
        int actualY = (y * Terrain.tileHeight) - realCameraY - Terrain.tileHeight;

       
        actualY = Detonator.INSTANCE.ScreenSizeY - (actualY + Terrain.tileHeight);
       
        return new Coords(actualX, actualY);
        */
    }

    /**
     * Convert screen coords to map coords
     */
    @Override
    public Coords getTileMapCoords(int x, int y) {
        int realCameraX = (int) (getCameraX());
        int realCameraY = (int) ((getHeight() * getTileHeight()) - getCameraY());

        realCameraX += (Detonator.INSTANCE.ScreenSizeX / 2);
        realCameraY += (Detonator.INSTANCE.ScreenSizeY / 2);

        realCameraX -= Detonator.INSTANCE.ScreenSizeX;
        realCameraY -= Detonator.INSTANCE.ScreenSizeY;


        int actualX = (x * Terrain.tileWidth) - realCameraX;
        int actualY = (y * Terrain.tileHeight) - realCameraY;

        return new Coords(actualX, actualY);
    }

    public TiledMapGDXContainer(String setName) {
        super(setName);



        Log.info("Init map.");
    }

    @Override
    public World getWorld() {
        return world;
    }

    @Override
    public float getCameraX() {
        return camera.position.x;
    }

    @Override
    public float getCameraY() {
        return camera.position.y;
    }

    @Override
    public int getCameraSizeX() {
        return (int) camera.viewportWidth;
    }

    @Override
    public int getCameraSizeY() {
        return (int) camera.viewportHeight;
    }

    @Override
    public void loadTiledMap(String fromFile) {
        TiledMap loadedMap = new TmxMapLoader().load(Detonator.INSTANCE.gameDataDir + "/maps/" + fromFile);
        map = new TiledMapGDX(loadedMap);
        map.setCamera(camera);


        maps.add(this);
    }

    @Override
    public int getTileHeight() {
        return map.getTileHeight();
    }
    /*
     @Override
     public void loadTiledMap (String fromFile) {
     String path = Detonator.INSTANCE.gameDataDir+"maps/";
     String mapname = fromFile;
               
     //String fileName = path + mapname;// + ".tmx";
     String fileName = path + mapname + ".tmx";

     Log.info(fileName);
     FileHandle mapHandle = Gdx.files.internal(fileName);
     FileHandle baseDir = Gdx.files.internal(path);

     Log.info("Map handle: "+mapHandle.path());
               
     if (!(StringAnalyst.isExactFileExist(mapHandle.path()))) {
     Log.error("Map doesn't exist!");
     }
               
               
     //make a derivative map that will implement teh interface
     //map = TransientTiledLoaderGDX.createMap(mapHandle);
     //atlas = new TileAtlas (getTiledMapGDX(), new FileHandle (Detonator.INSTANCE.gameDataDir +"/mappacked"));
     //atlas = new TiledMapTileSet (getTiledMapGDX(), new FileHandle (Detonator.INSTANCE.gameDataDir +"/mappacked"));
               
               
     transientMap = new Map("map");
     }
     */
}
 
TOP

Related Classes of transientlibs.maps.container.TiledMapGDXContainer

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.