Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Core;
- import java.awt.Rectangle;
- import java.util.Set;
- import java.util.Stack;
- import Base.custom.Indexer;
- import Base.custom.IntArr;
- import Base.custom.PairMap;
- import Base.custom.SetPairMap;
- public class World {
- CellGrid cg;
- PairMap<Rectangle,Rectangle> testRoomMap = new PairMap<>();
- PairMap<Rectangle,int[][]> roomObjects = new PairMap<>();
- PairMap<Rectangle,Rectangle> wallmap = new PairMap<>();
- public World(){
- cg = new CellGrid();
- cg.setupGrid(3,3);
- setupRooms(cg.pathGrid(cg.cellDivisions.getValues()));
- }
- public void append(Set<IntArr> pos){
- setupRooms(cg.appendGrid(pos));
- }
- int scale = 10;
- int div = 8;
- public void setupRooms(Set<Rectangle> roomSet){
- Rectangle hold;
- int nX = 0;
- int nY = 0;
- int nW = 0;
- int nH = 0;
- int[][] tiles;
- for(Rectangle added: roomSet){
- nX = added.x*scale;
- nY = added.y*scale;
- nW = added.width*scale;
- nH = added.height*scale;
- testRoomMap.put(added.getBounds(),hold= new Rectangle(nX,nY,nW,nH));
- roomObjects.put(hold,tiles=new int[nH/div][nW/div]);
- Set<Rectangle> walls = cg.rooms.get(added);
- IntArr cell = new IntArr(added.x/cg.CELL_SIZE,added.y/cg.CELL_SIZE);
- SetPairMap<Integer,Rectangle> wallCheck = new SetPairMap<>();
- for(Rectangle w: walls){
- int walltype = 0;
- int wallX = w.x*scale;
- int wallY = w.y*scale;
- int wallW = w.width*scale;
- int wallH = w.height*scale;
- Rectangle wallTransform;
- wallCheck.put(walltype=cg.roomLanding.get(cell)[w.y-((w.y/cg.CELL_SIZE)*cg.CELL_SIZE)][w.x-((w.x/cg.CELL_SIZE)*cg.CELL_SIZE)],wallTransform = new Rectangle(wallX,wallY,wallW,wallH));
- if(walltype == 2){
- wallmap.put(wallTransform, added.getBounds());
- }
- }
- Rectangle tile;
- for(int o = 0; o < tiles.length; o++){
- for(int i = 0; i < tiles[0].length; i++){
- tile = new Rectangle(nX+(i*div),nY+(o*div),div,div);
- if(i == 0 || o == 0 || i == tiles[0].length-1 || o == tiles.length-1){
- for(Rectangle w: wallCheck.get(2)){
- if(w.intersects(tile)){
- tiles[o][i] = 2;
- }
- }
- for(Rectangle w: wallCheck.get(1)){
- if(w.intersects(tile)){
- if(tiles[o][i] != 2){
- tiles[o][i] = 1;
- }
- }
- }
- }
- }
- }
- }
- Indexer indX = new Indexer();
- for(int[][] rTiles: roomObjects.getValues()){
- Stack<Stack<IntArr>> StackMinO = new Stack<>();
- Stack<Stack<IntArr>> StackMinI = new Stack<>();
- Stack<Stack<IntArr>> StackMaxO = new Stack<>();
- Stack<Stack<IntArr>> StackMaxI = new Stack<>();
- //StackMinO.push(new Stack<>());
- //StackMinI.push(new Stack<>());
- //StackMaxO.push(new Stack<>());
- //StackMaxI.push(new Stack<>());
- int lastMinO = -1;
- int lastMinI = -1;
- int lastMaxO = -1;
- int lastMaxI = -1;
- for(int o = 0; o < rTiles.length; o++){
- for(int i = 0; i < rTiles[0].length; i++){
- if(i == 0 || o == 0 || i == rTiles[0].length-1 || o == rTiles.length-1){
- // if(rTiles[o][i] == 2){
- if(o == 0){
- if(rTiles[o][i] == 2){
- if(lastMinO != 2){
- StackMinO.push(new Stack<IntArr>());
- }
- StackMinO.peek().push(new IntArr(i,o));
- }
- lastMinO = rTiles[o][i];
- }
- if(o == rTiles.length-1){
- if(rTiles[o][i] == 2){
- if(lastMaxO != 2){
- StackMaxO.push(new Stack<IntArr>());
- }
- StackMaxO.peek().push(new IntArr(i,o));
- }
- lastMaxO = rTiles[o][i];
- }
- if(i == 0){
- if(rTiles[o][i] == 2){
- if(lastMinI != 2){
- StackMinI.push(new Stack<IntArr>());
- }
- StackMinI.peek().push(new IntArr(i,o));
- }
- lastMinI = rTiles[o][i];
- }
- if(i == rTiles[o].length-1){
- if(rTiles[o][i] == 2){
- if(lastMaxI != 2){
- StackMaxI.push(new Stack<IntArr>());
- }
- StackMaxI.peek().push(new IntArr(i,o));
- }
- lastMaxI = rTiles[o][i];
- }
- }
- }
- }
- for(int i = 0; StackMinO.size() != 0; i++){
- Stack<IntArr> s = StackMinO.pop();
- if(s.size() < 4){
- continue;
- }
- s.pop();
- IntArr ia = s.pop();
- rTiles[ia.get(1)][ia.get(0)] = 0;
- ia = s.pop();
- rTiles[ia.get(1)][ia.get(0)] = 0;
- ia = s.pop();
- rTiles[ia.get(1)][ia.get(0)] = 0;
- ia = s.pop();
- rTiles[ia.get(1)][ia.get(0)] = 0;
- }
- for(int i = 0; StackMinI.size() != 0 ; i++){
- Stack<IntArr> s = StackMinI.pop();
- if(s.size() < 4){
- continue;
- }
- s.pop();
- IntArr ia = s.pop();
- rTiles[ia.get(1)][ia.get(0)] = 0;
- ia = s.pop();
- rTiles[ia.get(1)][ia.get(0)] = 0;
- ia = s.pop();
- rTiles[ia.get(1)][ia.get(0)] = 0;
- ia = s.pop();
- rTiles[ia.get(1)][ia.get(0)] = 0;
- }
- for(int i = 0; StackMaxO.size() != 0; i++){
- Stack<IntArr> s = StackMaxO.pop();
- if(s.size() < 4){
- continue;
- }
- s.pop();
- IntArr ia = s.pop();
- rTiles[ia.get(1)][ia.get(0)] = 0;
- ia = s.pop();
- rTiles[ia.get(1)][ia.get(0)] = 0;
- ia = s.pop();
- rTiles[ia.get(1)][ia.get(0)] = 0;
- ia = s.pop();
- rTiles[ia.get(1)][ia.get(0)] = 0;
- }
- for(int i = 0; StackMaxI.size() != 0; i++){
- Stack<IntArr> s = StackMaxI.pop();
- if(s.size() < 4){
- continue;
- }
- s.pop();
- IntArr ia = s.pop();
- rTiles[ia.get(1)][ia.get(0)] = 0;
- ia = s.pop();
- rTiles[ia.get(1)][ia.get(0)] = 0;
- ia = s.pop();
- rTiles[ia.get(1)][ia.get(0)] = 0;
- ia = s.pop();
- rTiles[ia.get(1)][ia.get(0)] = 0;
- }
- }
- // System.out.println(wallSet);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement