Grundstruktur MapGenerator

master
Jonathan Hager 6 years ago
parent d0440e3886
commit 926c517495

@ -73,9 +73,6 @@ public class DungeonGenerator {
xPos -= 1;
}
break;
default:
System.out.println("Die Random Methode ist kacke!!!!!!!!!!!!!!!!!!");
break;
}
// An der neuen Stelle vom Cursor gibt es noch keinen Raum

@ -6,91 +6,32 @@
package com.dungeoncrawler.view;
import com.badlogic.gdx.Gdx;
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;
import com.badlogic.gdx.utils.Timer;
/**
*
* @author jonathan
*/
public class Map {
private TiledMap map;
private Texture tiles;
private TiledMap[][][] maps;
public Map(){
map = new TiledMap();
tiles = new Texture(Gdx.files.internal("tiles.gif"));
generateMap();
}
private void generateMap(){
TextureRegion[][] splitTiles = TextureRegion.split(getTiles(), 48, 48);
MapLayers layers = getMap().getLayers();
//for(int i=0;i<6;i++){
int size = 10;
TiledMapTileLayer layer = new TiledMapTileLayer(size, size, 48, 48);
for(int x=0;x<size;x++){
for(int y=0;y<size;y++){
if(x == 0 || x == size -1 || y == 0 || y == size -1){
Cell cell = new Cell();
cell.setTile(new StaticTiledMapTile(splitTiles[0][5]));
layer.setCell(x, y, cell);
continue;
}
//int ty = (int)(Math.random() * splitTiles.length);
//int tx = (int)(Math.random() * splitTiles[ty].length);
Cell cell = new Cell();
cell.setTile(new StaticTiledMapTile(splitTiles[0][0]));
layer.setCell(x, y, cell);
}
layers.add(layer);
}
//}
}
/**
* @return the map
*/
public TiledMap getMap() {
return map;
}
/**
* @param map the map to set
* @return the maps
*/
public void setMap(TiledMap map) {
this.map = map;
public TiledMap[][][] getMaps() {
return maps;
}
/**
* @return the tiles
* @param maps the maps to set
*/
public Texture getTiles() {
return tiles;
public void setMaps(TiledMap[][][] maps) {
this.maps = maps;
}
/**
* @param tiles the tiles to set
*/
public void setTiles(Texture tiles) {
this.tiles = tiles;
}
}

@ -0,0 +1,66 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.dungeoncrawler.view;
import com.badlogic.gdx.Gdx;
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.tiles.StaticTiledMapTile;
import com.dungeoncrawler.model.Dungeon;
import com.dungeoncrawler.model.Level;
import com.dungeoncrawler.model.Room;
/**
*
* @author jonathan
*/
public class MapGenerator {
Texture tiles;
TextureRegion[][] splitTiles;
public MapGenerator(String tiles){
this.tiles = new Texture(Gdx.files.internal(tiles));
splitTiles = TextureRegion.split(this.tiles, 48, 48);
}
public TiledMap[][][] generateMap(int levelAmount, Dungeon d){
TiledMap[][][] tempMap = new TiledMap[levelAmount][][];
for(int i = 0; i < levelAmount; i++){
TiledMap[][] tempLevel = generateLevel(i, d.getLevel()[i]);
tempMap[i] = tempLevel;
}
return tempMap;
}
private TiledMap[][] generateLevel(int i, Level l){
int width = l.getRooms().length;
int height = l.getRooms()[0].length;
TiledMap[][] tempLevel = new TiledMap[width][height];
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
Room room = l.getRooms()[x][y];
TiledMap tempRoom = generateRoom(room);
tempLevel[x][y] = tempRoom;
}
}
return tempLevel;
}
private TiledMap generateRoom(Room r){
TiledMap tempRoom = new TiledMap();
return tempRoom;
}
}
Loading…
Cancel
Save