diff --git a/core/src/com/dungeoncrawler/view/Map.java b/core/src/com/dungeoncrawler/view/Map.java index bd9e7cc..7d2ad04 100644 --- a/core/src/com/dungeoncrawler/view/Map.java +++ b/core/src/com/dungeoncrawler/view/Map.java @@ -11,6 +11,9 @@ import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.maps.MapLayers; import com.badlogic.gdx.maps.tiled.TiledMap; +import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; +import com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell; +import com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile; /** * @@ -28,8 +31,56 @@ public class Map { } private void generateMap(){ - TextureRegion[][] splitTiles = TextureRegion.split(tiles, 48, 48); - MapLayers layers = map.getLayers(); + TextureRegion[][] splitTiles = TextureRegion.split(getTiles(), 48, 48); + MapLayers layers = getMap().getLayers(); + + for(int i=0;i<6;i++){ + TiledMapTileLayer layer = new TiledMapTileLayer(6, 6, 48, 48); + + for(int x=0;x<6;x++){ + for(int y=0;y<6;y++){ + + int ty = (int)(Math.random() * splitTiles.length); + int tx = (int)(Math.random() * splitTiles[ty].length); + + Cell cell = new Cell(); + cell.setTile(new StaticTiledMapTile(splitTiles[ty][tx])); + layer.setCell(x, y, cell); + + } + layers.add(layer); + } + } + } + + /** + * @return the map + */ + public TiledMap getMap() { + return map; } + + /** + * @param map the map to set + */ + public void setMap(TiledMap map) { + this.map = map; + } + + /** + * @return the tiles + */ + public Texture getTiles() { + return tiles; + } + + /** + * @param tiles the tiles to set + */ + public void setTiles(Texture tiles) { + this.tiles = tiles; + } + + } diff --git a/core/src/com/dungeoncrawler/view/View.java b/core/src/com/dungeoncrawler/view/View.java index 6884f34..b47ede9 100644 --- a/core/src/com/dungeoncrawler/view/View.java +++ b/core/src/com/dungeoncrawler/view/View.java @@ -3,9 +3,12 @@ package com.dungeoncrawler.view; import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.Sprite; +import com.badlogic.gdx.maps.tiled.TiledMapRenderer; +import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer; public class View extends ApplicationAdapter { SpriteBatch batch; @@ -13,6 +16,10 @@ public class View extends ApplicationAdapter { Texture t; Sprite button; Sprite title; + Map map; + TiledMapRenderer tmr; + OrthographicCamera camera; + @Override public void create () { @@ -28,6 +35,12 @@ public class View extends ApplicationAdapter { title.setY(h - 200); button.setX(wc - (button.getWidth()/2)); button.setY(400); + + map = new Map(); + tmr = new OrthogonalTiledMapRenderer(map.getMap()); + + camera = new OrthographicCamera(1, h/w); + } @Override @@ -35,6 +48,13 @@ public class View extends ApplicationAdapter { Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + tmr.setView(camera); + tmr.render(); + + camera.zoom = 1000f; + camera.update(); + batch.setProjectionMatrix(camera.combined); + batch.begin(); title.draw(batch); button.draw(batch);