public void powerMapCoords(int x, int y, boolean enable) { if (cableMask.atGrid(x, y, false)) { TiledMapTileLayer cableLayer = (TiledMapTileLayer) mapSystem.map.getLayers().get("cables"); final TiledMapTileLayer.Cell cell = cableLayer.getCell(x, y); if (cell != null) { MapProperties properties = cell.getTile().getProperties(); if (properties.containsKey("cable-state")) { if ((Boolean) properties.get("cable-state") != enable) { cell.setTile(enable ? tilesOn.get((Integer) properties.get("cable-type")) : tilesOff.get((Integer) properties.get("cable-type"))); powerMapCoordsAround(x, y, enable); } } } } }
public PathFindingSystem(int mapHeight, int mapWidth, TiledMap tiledMap) { super(Family.all(PathComponent.class, TransformComponent.class).get()); this.mapHeight = mapHeight; this.mapWidth = mapWidth; map = new TileType[mapWidth][mapHeight]; TiledMapTileLayer path = (TiledMapTileLayer) tiledMap.getLayers().get("Path"); TiledMapTileLayer rocks = (TiledMapTileLayer) tiledMap.getLayers().get("Rocks"); TiledMapTileLayer bushes = (TiledMapTileLayer) tiledMap.getLayers().get("Bushes"); for (int x = 0; x < map.length; x++) { for (int y = 0; y < map[x].length; y++) { if (path.getCell(x, y) != null) { map[x][y] = TileType.FLOOR; } else if (rocks.getCell(x, y) != null || bushes.getCell(x, y) != null) { map[x][y] = TileType.WALL; } else { map[x][y] = TileType.EMPTY; } } } }
/** * Rendert alle Layer und alle Objekte * * @param deltaTime die Zeit, die seit dem letztem Frame vergangen ist */ public void renderAll(float deltaTime) { beginRender(); for (MapLayer layer : map.getLayers()) { if (layer.isVisible()) { if (layer instanceof TiledMapTileLayer) { if (layer == displayLayer) renderDisplayLayer((TiledMapTileLayer) layer, deltaTime); else renderTileLayer((TiledMapTileLayer)layer); } else if (layer instanceof TiledMapImageLayer) { renderImageLayer((TiledMapImageLayer)layer); } else { renderObjects(layer); } } } endRender(); }
@Override public void update(final long elapsedTime) { timeInAnimation = (timeInAnimation + elapsedTime) % getTotalAnimationTimeMs(); final int frameIndex = (int) (timeInAnimation / timePerFrameMs); TiledMapTile currentTile = tileFrames.get(indexOrder[frameIndex]); for (MapLayer layer : tiledMap.getLayers()) { TiledMapTileLayer tiledMapLayer = (TiledMapTileLayer) layer; for (int x = 0; x < tiledMapLayer.getWidth(); x++) { for (int y = 0; y < tiledMapLayer.getHeight(); y++) { final TiledMapTileLayer.Cell cell = tiledMapLayer.getCell(x, y); if (cell != null) { TiledMapTile tile = cell.getTile(); final MapProperties tileProperties = tile.getProperties(); if (tileProperties.containsKey(JRPG_TILE_ANIMATION_ID) && tileProperties.get(JRPG_TILE_ANIMATION_ID).equals(id)) { cell.setTile(currentTile); } } } } } }
private List<MapTile> getDoorTiles(final TiledMapTileLayer layer) { final List<MapTile> mapTiles = new LinkedList<>(); final int layerIndex = layer.getProperties().get(GameMap.MAP_LAYER_PROP_MAP_LAYER, 0, Integer.class); for (int x = 0; x < layer.getWidth(); x++) { for (int y = 0; y < layer.getHeight(); y++) { final TiledMapTileLayer.Cell cell = layer.getCell(x, y); TiledMapTile tile = (cell != null) ? cell.getTile() : null; if (tile != null && tile.getProperties().get(JRPG_TILE_IS_DOOR, false, Boolean.class)) { mapTiles.add(new MapTile( new TileCoordinate(x, y, layerIndex), layer.getName(), tile )); } } } return mapTiles; }
private void buildMapLayers(final TiledMap map) { for (com.badlogic.gdx.maps.MapLayer mapLayer : map.getLayers()) { TiledMapTileLayer tiledMapLayer = (TiledMapTileLayer) mapLayer; if (tiledMapLayer.getProperties().containsKey(MAP_LAYER_PROP_MAP_LAYER)) { int mapLayerIndex = tiledMapLayer.getProperties().get(MAP_LAYER_PROP_MAP_LAYER, Integer.class); MapLayer gameMapLayer = mapLayers.computeIfAbsent(mapLayerIndex, i -> new MapLayer(i, mapRenderer)); switch (tiledMapLayer.getProperties().get(MAP_LAYER_PROP_LAYER_TYPE, String.class)) { case MAP_LAYER_TYPE_BACKGRAOUND: gameMapLayer.addBackgroundLayer(tiledMapLayer); break; case MAP_LAYER_TYPE_FOREGRAOUND: gameMapLayer.addForegroundLayer(tiledMapLayer); break; case MAP_LAYER_TYPE_COLLISION: gameMapLayer.setCollisionLayer(tiledMapLayer); break; default: } } } }
public static <T> T getCellPropertyFromTopMostTile(final TiledMap tiledMap, final TileCoordinate coordinate, final String propertyName, final Class<T> clazz) { T value = null; for (MapLayer mapLayer : tiledMap.getLayers()) { if (mapLayer instanceof TiledMapTileLayer && matchProperty(mapLayer, GameMap.MAP_LAYER_PROP_MAP_LAYER, coordinate.getMapLayer())) { TiledMapTileLayer tiledMapTileLayer = (TiledMapTileLayer) mapLayer; TiledMapTileLayer.Cell cell = tiledMapTileLayer.getCell(coordinate.getX(), coordinate.getY()); if (cell != null) { final MapProperties cellProps = cell.getTile().getProperties(); value = (cellProps.get(propertyName, clazz) != null) ? cellProps.get(propertyName, clazz) : value; } } } return value; }
public Item(MapCellCoordinates cellPos, TextureRegion itemTexture, MapLoader map, EntityManager entityManager) { super(new ThinGridCoordinates(cellPos.getX(), cellPos.getY()), new ThinGridCoordinates(0,0), map, entityManager); this.emptyBlock = TextureManager.emptyBlock; this.cellPos = cellPos; this.sendCommand = entityManager.getSendCommand(); if(!map.isCellBlocked(cellPos)){ //Render Item once TiledMapTileLayer.Cell cell = new TiledMapTileLayer.Cell(); cell.setTile(new StaticTiledMapTile(itemTexture)); map.getItemLayer().setCell(cellPos.getX(), cellPos.getY(), cell); }else{ collected = true; } }
@Override public void render() { if(!map.isCellBlocked(cellPos)) { //Create new cell and set its animation texture TiledMapTileLayer.Cell cell = new TiledMapTileLayer.Cell(); cell.setTile(new StaticTiledMapTile(animEffects.getFrame(blockAnim, true))); cell.getTile().getProperties().put("poisonGas", null); //Set texture into block layer blockLayer.setCell(super.cellPos.getX(), super.cellPos.getY(), cell); }else { super.destroyed = true; } }
public void deleteUp(){ for(int y=1; y <= explosionRange; y++){ TiledMapTileLayer.Cell cell = new TiledMapTileLayer.Cell(); cell.setTile(new StaticTiledMapTile(emptyBlock)); //If explosion hits block if(map.isCellBlocked(new MapCellCoordinates(cellPos.getX(), cellPos.getY() + y))) { //Delete explosion effect map.getBombLayer().setCell(cellPos.getX(), cellPos.getY() + y, cell); //Delete block deleteBlock(new MapCellCoordinates(cellPos.getX(), cellPos.getY() + y)); break; } //Explosion down map.getBombLayer().setCell(cellPos.getX(), cellPos.getY() + y, cell); deleteBlock(new MapCellCoordinates(cellPos.getX(), cellPos.getY() + y)); } }
public void deleteRight(){ for(int x=1; x <= explosionRange; x++){ TiledMapTileLayer.Cell cell = new TiledMapTileLayer.Cell(); cell.setTile(new StaticTiledMapTile(emptyBlock)); //If explosion hits block if(map.isCellBlocked(new MapCellCoordinates(cellPos.getX() + x, cellPos.getY()))) { //Delete explosion effect map.getBombLayer().setCell(cellPos.getX() + x, cellPos.getY(), cell); //Delete block deleteBlock(new MapCellCoordinates(cellPos.getX() + x, cellPos.getY())); break; } //Explosion down map.getBombLayer().setCell(cellPos.getX() + x, cellPos.getY(), cell); deleteBlock(new MapCellCoordinates(cellPos.getX() + x, cellPos.getY())); } }
public void deleteDown(){ for(int y=1; y <= explosionRange; y++){ TiledMapTileLayer.Cell cell = new TiledMapTileLayer.Cell(); cell.setTile(new StaticTiledMapTile(emptyBlock)); //If explosion hits block if(map.isCellBlocked(new MapCellCoordinates(cellPos.getX(), cellPos.getY() - y))) { //Delete explosion effect map.getBombLayer().setCell(cellPos.getX(), cellPos.getY() - y, cell); //Delete block deleteBlock(new MapCellCoordinates(cellPos.getX(), cellPos.getY() - y)); break; } //Explosion down map.getBombLayer().setCell(cellPos.getX(), cellPos.getY() - y, cell); deleteBlock(new MapCellCoordinates(cellPos.getX(), cellPos.getY() - y)); } }
public void deleteLeft(){ for(int x=1; x <= explosionRange; x++){ TiledMapTileLayer.Cell cell = new TiledMapTileLayer.Cell(); cell.setTile(new StaticTiledMapTile(emptyBlock)); //If explosion hits block if(map.isCellBlocked(new MapCellCoordinates(cellPos.getX() - x, cellPos.getY()))) { //Delete explosion effect map.getBombLayer().setCell(cellPos.getX() - x, cellPos.getY(), cell); //Delete block deleteBlock(new MapCellCoordinates(cellPos.getX() - x, cellPos.getY())); break; } //Explosion down map.getBombLayer().setCell(cellPos.getX() - x, cellPos.getY(), cell); deleteBlock(new MapCellCoordinates(cellPos.getX() - x, cellPos.getY())); } }
public MapLoader(OrthographicCamera camera, SendCommand sendCommand) { this.camera = camera; this.tiledMap = new TmxMapLoader().load(Constants.TESTMAPPATH); this.tiledMapRenderer = new OrthogonalTiledMapRenderer(tiledMap); this.blockLayer = (TiledMapTileLayer) tiledMap.getLayers().get("Blocks"); this.floorLayer = (TiledMapTileLayer) tiledMap.getLayers().get("Floor"); this.bombLayer = (TiledMapTileLayer) tiledMap.getLayers().get("Bombs"); this.itemLayer = (TiledMapTileLayer) tiledMap.getLayers().get("Items"); this.sendCommand = sendCommand; Constants.MAPTEXTUREWIDTH = blockLayer.getTileWidth(); Constants.MAPTEXTUREHEIGHT = blockLayer.getTileWidth(); findAllItemFields(); }
/**-------------------Getter & Setter-------------------**/ public void setNewMap(String path) { this.tiledMap = new TmxMapLoader().load(path); this.tiledMapRenderer = new OrthogonalTiledMapRenderer(tiledMap); this.blockLayer = (TiledMapTileLayer) tiledMap.getLayers().get("Blocks"); this.floorLayer = (TiledMapTileLayer) tiledMap.getLayers().get("Floor"); this.bombLayer = (TiledMapTileLayer) tiledMap.getLayers().get("Bombs"); this.itemLayer = (TiledMapTileLayer) tiledMap.getLayers().get("Items"); Constants.MAPTEXTUREWIDTH = blockLayer.getTileWidth(); Constants.MAPTEXTUREHEIGHT = blockLayer.getTileWidth(); findAllItemFields(); }
private Array<TiledMapTileLayer.Cell> DFS(int x, int y) { if (layer.getCell(x, y) == null) { return null; } Array<TiledMapTileLayer.Cell> object = new Array<TiledMapTileLayer.Cell>(); Array<Vector2> stack = new Array<Vector2>(); stack.add(new Vector2(x, y)); while (stack.size > 0) { Vector2 curr = stack.pop(); if (!isVisited(curr)) { object.add(layer.getCell((int)curr.x, (int)curr.y)); setVisited(curr, true); for (Vector2 neighbor : getNeighbors(curr)) { stack.add(neighbor); } } } return object; }
public void renderGrid (int row1, int row2, int col1, int col2, float xStart, float tileWidth, float tileHeight, TiledMapTileLayer layer) { spriteBatch.setColor(1, 1, 1, 0.3f); if (xStart < 0) { xStart = 0; } float xMax = map.getWidth(); float y = row1 * tileHeight; TextureRegion texture = map.getGridTexture(); float width = map.getTileSizeX() * map.getScaleX(); float height = map.getTileSizeY() * map.getScaleY(); for (int row = row1; row < row2; row++) { float x = xStart; if (x < 0) { x = 0; } for (int col = col1; col < col2 && x < xMax; col++) { final TiledMapTileLayer.Cell cell = layer.getCell(col, row); if (cell != null && cell.getTile() != null && map.shouldRenderTile(col, row)) { spriteBatch.draw(texture, x, y, width, height); } x += tileWidth; } y += tileHeight; } spriteBatch.setColor(1, 1, 1, 1); }
protected void renderLayersExcludingSpecial(float delta) { for (MapLayer layer : map.getTiledMap().getLayers()) { boolean groundLayer = layer.getProperties().get( GameMapLoader.PROPERTY_GROUND_LAYER) != null; boolean collisionLayer = layer.getProperties().get( GameMapLoader.PROPERTY_COLISIONS_LAYER) != null; boolean objectLayer = layer.getProperties().get( GameMapLoader.PROPERTY_OBJECT_LAYER) != null; boolean overheadLayer = layer.getProperties().get( GameMapLoader.PROPERTY_OVERHEAD_LAYER) != null; boolean alwaysAboveLayer = layer.getProperties().get( GameMapLoader.PROPERTY_ALWAYSABOVE_LAYER) != null; if (groundLayer || collisionLayer || objectLayer || overheadLayer || alwaysAboveLayer) { continue; } if (layer.isVisible()) { if (layer instanceof TiledMapTileLayer) { renderTileLayer(delta, (TiledMapTileLayer) layer); } } } }
public void renderGrid (int yMin, int yMax, int xMin, int xMax, float halfTileWidth, float halfTileHeight, TiledMapTileLayer layer) { spriteBatch.setColor(1, 1, 1, 0.3f); TextureRegion texture = map.getGridTexture(); float width = map.getTileSizeX() * 2 * unitScaleX; float height = map.getTileSizeY() * unitScaleY; for (int row = yMax; row >= yMin; row--) { for (int col = xMin; col <= xMax; col++) { float x = (col * halfTileWidth) + (row * halfTileWidth); float y = (row * halfTileHeight) - (col * halfTileHeight); final TiledMapTileLayer.Cell cell = layer.getCell(col, row); if (cell == null) { continue; } if (cell.getTile() != null && map.shouldRenderTile(col, row)) { spriteBatch.draw(texture, x, y,width,height); } } } spriteBatch.setColor(1, 1, 1, 1); }
public TiledMapObject(MapTileObjectGround ground, int[] objectTiles, GameMap map, Array<TiledMapTileLayer> layers, boolean shouldDrawAsAWhole) { this.ground = ground; alreadySeenTiles = new ObjectSet<Tile>(); objectTilesVectors = new Array<Tile>(); for (int i = 0; i < objectTiles.length; i += 2) { objectTilesVectors.add(new Tile(objectTiles[i],objectTiles[i+1])); } this.shouldDrawAsAWhole = shouldDrawAsAWhole; this.map = map; this.layers = new Array<TiledMapTileLayer>(layers); this.position = new Position(); wasDiscovered = false; isVisibleByPC = false; fogColor = Color.toFloatBits(Configuration.getFogColor().r, Configuration.getFogColor().g, Configuration.getFogColor().b, 1f); visibleColor = Color.toFloatBits(1, 1, 1, 1f); notVisibleColor = Color.toFloatBits(0f,0f,0f,1f); calculateDimensions(); removeEmptyLayers(); }
private void removeEmptyLayers() { Iterator<TiledMapTileLayer> layerIterator = layers.iterator(); while (layerIterator.hasNext()) { TiledMapTileLayer layer = layerIterator.next(); boolean isEmpty = true; for (Tile tile: objectTilesVectors) { int x = tile.getX(); int y = tile.getY(); TiledMapTileLayer.Cell cell = layer.getCell(x, y); if (cell == null) { continue; } if (cell.getTile() != null) { isEmpty = false; break; } } if (isEmpty) { layerIterator.remove(); } } }
private void initSolidTiles(TiledMap map){ TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get("CollisionTiles"); for(int x = 0; x < layer.getWidth(); x++){ for(int y = 0; y < layer.getHeight(); y++){ Cell cell = layer.getCell(x, y); if(cell == null){ solids[x][y] = false; continue; } if(cell.getTile() == null){ solids[x][y] = false; continue; } else{ solids[x][y] = true; } } } }
public void populate(TiledMap tiledMap, State state, Camera camera, MapLayerRendererFactory rendererFactory, TiledMapConfig config) { MapLayers mapLayers = tiledMap.getLayers(); handleMapProperties(tiledMap.getProperties(), state, config); List<String> layerIds = new ArrayList<String>(); int lastTileLayerIndex = 0; for (int i = 0; i < mapLayers.getCount(); ++i) { MapLayer mapLayer = mapLayers.get(i); if (mapLayer instanceof TiledMapTileLayer) { if (i > 0) { lastTileLayerIndex++; } String layerId = handleTiledMapTileLayer((TiledMapTileLayer) mapLayer, i, tiledMap, camera, rendererFactory, config); layerIds.add(layerId); populateStaticMapData(lastTileLayerIndex, (TiledMapTileLayer) mapLayer, state, config); } else { // Not a tiledlayer so consider it as an object layer handleObjectLayer(lastTileLayerIndex, mapLayer, state, config); } } state.setLayerIds(layerIds); }
public TmxMap(String levelName) { map = new TmxMapLoader().load(levelName); tileLayer = (TiledMapTileLayer) map.getLayers().get(0); objectsLayer = map.getLayers().get(1); MapProperties properties = tileLayer.getProperties(); worldType = WorldTypeEnum.valueOf(((String)properties.get(TilemapPropertiesConstants.WORLD)).toUpperCase()); musicTheme = ((String)properties.get("music")).toUpperCase(); String sScrollableTo = (String)properties.get("scrollableTo"); scrollMaxValue = sScrollableTo!=null && !sScrollableTo.equals("") ? Float.parseFloat(sScrollableTo) : 1000; String sCastle = (String)properties.get("castle"); endLevelCastleType = worldType !=WorldTypeEnum.CASTLE ? sCastle!=null && !sCastle.equals("") ? CastleTypeEnum.valueOf(sCastle.toUpperCase()) : CastleTypeEnum.SMALL : null; initBlocks(worldType); initMapObjects(); initBackgrounds(properties); }
public void createL0Animation(Texture tileTexture, String tag){ //hardcoded grass texture region Tile = new Array<StaticTiledMapTile>(); Tile.add(new StaticTiledMapTile(new TextureRegion(tileTexture,0,0,32,32))); Tile.add(new StaticTiledMapTile(new TextureRegion(tileTexture,32,0,32,32))); Tile.add(new StaticTiledMapTile(new TextureRegion(tileTexture,64,0,32,32))); TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get(0); for(int x = 0; x < layer.getWidth();x++){ for(int y = 0; y < layer.getHeight();y++){ TiledMapTileLayer.Cell cell = layer.getCell(x,y); Object property = cell.getTile().getProperties().get(tag); if(property != null){ cell.setTile(new AnimatedTiledMapTile(1.5f,Tile)); } } } }
public void createL1SmallAnimation(Texture tileTexture, String tag){ //hardcoded grass texture region Tile = new Array<StaticTiledMapTile>(); Tile.add(new StaticTiledMapTile(new TextureRegion(tileTexture,0,0,32,32))); Tile.add(new StaticTiledMapTile(new TextureRegion(tileTexture,32,0,32,32))); Tile.add(new StaticTiledMapTile(new TextureRegion(tileTexture,64,0,32,32))); TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get(1); for(int x = 0; x < layer.getWidth();x++){ for(int y = 0; y < layer.getHeight();y++){ TiledMapTileLayer.Cell cell = layer.getCell(x,y); if(cell!=null && cell.getTile().getProperties().get(tag)!=null){ cell.setTile(new AnimatedTiledMapTile(1.5f,Tile)); } } } }
public void createL1LargeAnimation(Texture tileTexture, String tag){ //hardcoded grass texture region Tile = new Array<StaticTiledMapTile>(); Tile.add(new StaticTiledMapTile(new TextureRegion(tileTexture,0,0,64,64))); Tile.add(new StaticTiledMapTile(new TextureRegion(tileTexture,64,0,64,64))); Tile.add(new StaticTiledMapTile(new TextureRegion(tileTexture,128,0,64,64))); TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get(1); for(int x = 0; x < layer.getWidth();x++){ for(int y = 0; y < layer.getHeight();y++){ TiledMapTileLayer.Cell cell = layer.getCell(x,y); if(cell!=null && cell.getTile().getProperties().get(tag)!=null){ cell.setTile(new AnimatedTiledMapTile(1.5f,Tile)); } } } }
public void render(){ beginRender(); int layerCourant = 0; for(MapLayer layer : map.getLayers()){ if(layer instanceof TiledMapTileLayer){ renderTileLayer((TiledMapTileLayer)layer); layerCourant++; if(layerCourant==numberOfSpriteLayer){//if we are in the layer for the Sprite //just draw it up!!!! for(Sprite dropOfKoffee : superStrongKoffee){ System.out.println("Fuck OFFF!!!!"); dropOfKoffee.draw(this.batch); } } }else{ for(MapObject wtfIsThisObject : layer.getObjects()){ renderObject(wtfIsThisObject); } } } endRender(); }
@Override public IMap<T> generateMap(TiledMap map) { tm = map; mainLayer = (TiledMapTileLayer) tm.getLayers().get(0); pixelwidth = (int) (mainLayer.getWidth() * mainLayer.getTileWidth()); pixelheight = (int) (mainLayer.getHeight() * mainLayer.getTileHeight()); int resolution = (int) mainLayer.getTileWidth(); // generate the quad tree QuadTree<T> tree = new QuadTree<T>(resolution); QuadNode<T> headNode = generateSquare(0, 0, pixelwidth, pixelheight, tree, null); tree.root = headNode; headNode.genVisibilityGraph(); return tree; }
/** * * @param tileMap ширина, высота и размер тайла берется из первого слоя: * TiledMapTileLayer bg = (TiledMapTileLayer) tileMap.getLayers().get(0); * cellSize = (int) bg.getTileHeight(); mapW = bg.getWidth(); mapH = * bg.getHeight(); */ public ScrollMap(TiledMap tileMap) { mapCamera = new OrthographicCamera(); mapRenderer = new OrthogonalTiledMapRenderer(tileMap, 1f/* / cellSize */); stageViewport = new ScreenViewport(new OrthographicCamera()); TiledMapTileLayer bg = (TiledMapTileLayer) tileMap.getLayers().get(0); cellSize = (int) bg.getTileHeight(); mapW = bg.getWidth() * cellSize; mapH = bg.getHeight() * cellSize; mapHolder = new Actor(); mapHolder.setSize(mapW, mapH); scrollPane = new ScrollPane(mapHolder); scrollPane.setOverscroll(false, false); root = new Table(); root.setFillParent(true); root.add(scrollPane).fill().expand(); stage = new Stage(stageViewport); stage.addActor(root); im = new InputMultiplexer(); gameBatch = mapRenderer.getSpriteBatch(); sprites = new Array<Sprite>(); gestureDetector = new GestureDetector(gestureListener); }
public static TiledMap genVoidMap(int w, int h) { ImpassableCells.clear(); tileAtlas = ResKeeper.get(AtlasId.MAP_TILES); TiledMap map = new TiledMap(); MapLayers layers = map.getLayers(); TiledMapTileLayer layerBg = new TiledMapTileLayer(w, h, CELL_SIZE, CELL_SIZE); MapCell cell = getCell(TileCode.GRASS, true); for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { layerBg.setCell(i, j, cell); } } layers.add(layerBg); cells.clear(); return map; }
/** * <p> * Scans every cell in the layer and indiscriminately marks it as solid in a * collision map, and returns the map. * </p> * * @param layer * The layer to use to generate the map. * @param mirrorLayer * The mirror layer corresponding to the layer. * @return A boolean array where map[layer.getWidth() * y + x] is a cell, * and true means "solid". */ public static ArrayList<Integer> generateCollisionArray(TiledMapTileLayer layer, TiledMapTileLayer mirrorLayer) { ArrayList<Integer> collisionMap = new ArrayList<Integer>(); collisionMap.ensureCapacity((layer.getWidth() + mirrorLayer.getWidth()) * layer.getHeight()); for (int y = 0; y < layer.getHeight(); y++) { for (int x = 0; x < (layer.getWidth() + mirrorLayer.getWidth()); x++) { if (x < layer.getWidth()) { collisionMap.add((layer.getCell(x, y) != null ? 1 : 0)); } else { collisionMap.add((mirrorLayer.getCell(x - layer.getWidth(), y) != null ? 1 : 0)); } } } return collisionMap; }
public static TiledMap generateInvertedMap(TiledMap map) { TiledMap invertedMap = new TiledMap(); MapLayers invertedLayers = invertedMap.getLayers(); for (int i = 0; i < map.getLayers().getCount(); i++) { TiledMapTileLayer origLayer = (TiledMapTileLayer) map.getLayers().get(i); TiledMapTileLayer tempLayer = invertLayer(origLayer); tempLayer.setOpacity(origLayer.getOpacity()); tempLayer.setName(origLayer.getName()); tempLayer.setVisible(origLayer.isVisible()); copyLayerProperties(origLayer, tempLayer); invertedLayers.add(tempLayer); } return invertedMap; }
/** * <p> * Finds the first non-null cell in a layer. Only really meaningful in some * layers. * </p> * <p> * Cells are searched across x before y is incremented. * </p> * * @param layer * The layer whose cell we'll find. * @return An initialised {@link Vector2} with the x and y coordinates (in * tile coordinates), or null if the layer is empty. x is right, y * is down. */ public static Vector2 findFirstCell(TiledMapTileLayer layer) { for (int y = 0; y < layer.getHeight(); y++) { for (int x = 0; x < layer.getWidth(); x++) { if (layer.getCell(x, y) != null) { // found first Vector2 retVal = new Vector2(); retVal.x = (float) x; retVal.y = (float) y; return retVal; } } } return null; }
public static void loadMap(String fileName) { TiledMap map = new TmxMapLoader().load(fileName); for (int i = 0; i < map.getLayers().getCount(); i++) { TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers() .get(i); for (int x = 0; x < layer.getWidth(); x++) { for (int y = 0; y < layer.getHeight(); y++) { Cell cell = layer.getCell(x, layer.getHeight() - 1 - y); if (cell == null) { continue; } Entity e = EntityManager.createTile((String) cell.getTile() .getProperties().get("name"), x * 16, y * 16); EntityManager.setEntityLayer(e, Name.LAYER_FLOOR); } } } }
public SpriteManager(Robin2DX game) { this.game = game; // Inicia la cámara para jugar camera = new OrthographicCamera(); // La cámara mostrará 30 celdas de ancho por 30 celdas de alto camera.setToOrtho(false, 30, 30); camera.zoom = 1 / 2f; camera.update(); // Carga el mapa y obtiene la capa de colisión (objetos con los que el personaje puede chocar) map = new TmxMapLoader().load("levels/tiledmap1.tmx"); collisionLayer = (TiledMapTileLayer) map.getLayers().get("base"); // Crea el renderizador del tiledmap mapRenderer = new OrthogonalTiledMapRenderer(map); // Hay que utilizar el spritebatch del mapa para pintar el nivel. // En caso contrario no ubica ni escala bien al personaje en el mapa batch = mapRenderer.getSpriteBatch(); // Posiciona al jugador en el mapa player = new Player(15 * Constants.TILE_WIDTH, 10 * Constants.TILE_HEIGHT); }
public Player(TiledMapTileLayer collisionLayer, Jumper2DX game) { position = new Vector2(); velocity = new Vector2(); state = State.IDLE_RIGHT; this.collisionLayer = collisionLayer; this.game = game; // Posiciones estáticas del personaje para izquierda y derecha en parado y salto idleLeft = new Sprite(new Texture(Gdx.files.internal("characters/mario_idle_left.png"))); idleRight = new Sprite(new Texture(Gdx.files.internal("characters/mario_idle_right.png"))); walkLeft = new Sprite(new Texture(Gdx.files.internal("characters/mario_walk_left2.png"))); walkRight = new Sprite(new Texture(Gdx.files.internal("characters/mario_walk_right2.png"))); // Crea la animación para correr hacia la derecha TextureRegion[] rightMovements = new TextureRegion[2]; rightMovements[0] = new Sprite(new Texture(Gdx.files.internal("characters/mario_walk_right1.png"))); rightMovements[1] = new Sprite(new Texture(Gdx.files.internal("characters/mario_walk_right2.png"))); rightAnimation = new Animation(0.15f, rightMovements); // Crea la animación para correr hacia la izquierda TextureRegion[] leftMovements = new TextureRegion[2]; leftMovements[0] = new Sprite(new Texture(Gdx.files.internal("characters/mario_walk_left1.png"))); leftMovements[1] = new Sprite(new Texture(Gdx.files.internal("characters/mario_walk_left2.png"))); leftAnimation = new Animation(0.15f, leftMovements); }
public void loadLayer(int layerNo){ Scene.log("Tiles Layer no: "+layerNo); TiledMapTileLayer layer = (TiledMapTileLayer)mlayers.get(layerNo); NoOfColumns = layer.getWidth(); Scene.log("MapColumns: "+NoOfColumns); NoOfRows = layer.getHeight(); Scene.log("MapRows: "+NoOfRows); tiles .add(new MapActor[NoOfRows][NoOfColumns]); for(int i=0; i<NoOfRows; i++) for(int j=0; j<NoOfColumns; j++){ Cell c = layer.getCell(j, i); if(c != null){ tiles.get(layerNo)[i][j] = new MapActor(c.getTile().getTextureRegion(), i, j, c.getTile().getId(), tileSize); addActor(tiles.get(layerNo)[i][j]); } else{ tiles.get(layerNo)[i][j] = new MapActor((TextureRegion)null,i, j, 0, tileSize); addActor(tiles.get(layerNo)[i][j]); } } mapWidth = tileSize * NoOfColumns; mapHeight = tileSize * NoOfRows; //Stage.mapOffsetX = mapWidth - Stage.camOffsetX; //Stage.mapOffsetY = mapHeight - Stage.camOffsetYTop; }
/** * Spawn map entities. */ protected void setup() { for (TiledMapTileLayer layer : layers) { // private HashMap<String, TiledMapTileLayer> layerIndex = new HashMap<String, TiledMapTileLayer>(); // layerIndex.put(layer.getName(), layer); for (int ty = 0; ty < height; ty++) { for (int tx = 0; tx < width; tx++) { final TiledMapTileLayer.Cell cell = layer.getCell(tx, ty); if (cell != null) { final MapProperties properties = cell.getTile().getProperties(); if ( properties.containsKey("entity")) { entitySpawnerSystem.spawnEntity(tx * G.CELL_SIZE, ty * G.CELL_SIZE, properties); layer.setCell(tx, ty, null); } } } } } }
public void generate(Array<TiledMapTileLayer> layers, String propertyKey) { for (int ty = 0; ty < height; ty++) { for (int tx = 0; tx < width; tx++) { v[ty][tx] = false; } } for (TiledMapTileLayer layer : layers) { for (int ty = 0; ty < height; ty++) { for (int tx = 0; tx < width; tx++) { final TiledMapTileLayer.Cell cell = layer.getCell(tx, ty); if (cell != null && cell.getTile() != null && cell.getTile().getProperties().containsKey(propertyKey)) { v[ty][tx] = true; } } } } }