Advertisement
Guest User

world

a guest
Nov 17th, 2015
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.93 KB | None | 0 0
  1. package Core;
  2.  
  3. import java.awt.Rectangle;
  4. import java.util.Set;
  5. import java.util.Stack;
  6.  
  7. import Base.custom.Indexer;
  8. import Base.custom.IntArr;
  9. import Base.custom.PairMap;
  10. import Base.custom.SetPairMap;
  11.  
  12. public class World {
  13.     CellGrid cg;
  14.    
  15.     PairMap<Rectangle,Rectangle> testRoomMap = new PairMap<>();
  16.     PairMap<Rectangle,int[][]> roomObjects = new PairMap<>();
  17.    
  18.     PairMap<Rectangle,Rectangle> wallmap = new PairMap<>();
  19.     public World(){
  20.         cg = new CellGrid();
  21.         cg.setupGrid(3,3);
  22.         setupRooms(cg.pathGrid(cg.cellDivisions.getValues()));
  23.        
  24.     }
  25.    
  26.     public void append(Set<IntArr> pos){       
  27.         setupRooms(cg.appendGrid(pos));    
  28.  
  29.     }
  30.     int scale = 10;
  31.     int div = 8;
  32.    
  33.     public void setupRooms(Set<Rectangle> roomSet){
  34.         Rectangle hold;
  35.         int nX = 0;
  36.         int nY = 0;
  37.         int nW = 0;
  38.         int nH = 0;
  39.         int[][] tiles;
  40.         for(Rectangle added: roomSet){
  41.             nX = added.x*scale;
  42.             nY = added.y*scale;
  43.             nW = added.width*scale;
  44.             nH = added.height*scale;
  45.             testRoomMap.put(added.getBounds(),hold= new Rectangle(nX,nY,nW,nH));
  46.             roomObjects.put(hold,tiles=new int[nH/div][nW/div]);   
  47.            
  48.             Set<Rectangle> walls = cg.rooms.get(added);
  49.             IntArr cell = new IntArr(added.x/cg.CELL_SIZE,added.y/cg.CELL_SIZE);
  50.             SetPairMap<Integer,Rectangle> wallCheck = new SetPairMap<>();
  51.             for(Rectangle w: walls){
  52.                 int walltype = 0;
  53.                 int wallX = w.x*scale;
  54.                 int wallY = w.y*scale;
  55.                 int wallW = w.width*scale;
  56.                 int wallH = w.height*scale;
  57.                 Rectangle wallTransform;
  58.                 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));
  59.                 if(walltype == 2){
  60.                     wallmap.put(wallTransform, added.getBounds());
  61.                 }
  62.             }
  63.             Rectangle tile;
  64.             for(int o = 0; o < tiles.length; o++){
  65.                 for(int i = 0; i < tiles[0].length; i++){
  66.                     tile = new Rectangle(nX+(i*div),nY+(o*div),div,div);
  67.                     if(i == 0 || o == 0 || i == tiles[0].length-1 || o == tiles.length-1){                                         
  68.                         for(Rectangle w: wallCheck.get(2)){
  69.                             if(w.intersects(tile)){
  70.                                 tiles[o][i] = 2;                               
  71.                             }
  72.                         }
  73.                        
  74.                         for(Rectangle w: wallCheck.get(1)){
  75.                             if(w.intersects(tile)){
  76.                                 if(tiles[o][i] != 2){
  77.                                 tiles[o][i] = 1;
  78.                                 }
  79.                             }
  80.                         }
  81.                     }
  82.                 }
  83.             }
  84.            
  85.         }
  86.                     Indexer indX = new Indexer();
  87.                 for(int[][] rTiles: roomObjects.getValues()){
  88.                     Stack<Stack<IntArr>> StackMinO = new Stack<>();
  89.                     Stack<Stack<IntArr>> StackMinI = new Stack<>();
  90.                     Stack<Stack<IntArr>> StackMaxO = new Stack<>();
  91.                     Stack<Stack<IntArr>> StackMaxI = new Stack<>();
  92.  
  93.                     //StackMinO.push(new Stack<>());
  94.                     //StackMinI.push(new Stack<>());
  95.                     //StackMaxO.push(new Stack<>());
  96.                     //StackMaxI.push(new Stack<>());
  97.                    
  98.                     int lastMinO = -1;
  99.                     int lastMinI = -1;
  100.                     int lastMaxO = -1;
  101.                     int lastMaxI = -1;
  102.                     for(int o = 0; o < rTiles.length; o++){
  103.                         for(int i = 0; i < rTiles[0].length; i++){
  104.                             if(i == 0 || o == 0 || i == rTiles[0].length-1 || o == rTiles.length-1){
  105.                             //  if(rTiles[o][i] == 2){
  106.                                     if(o == 0){
  107.                                         if(rTiles[o][i] == 2){
  108.                                             if(lastMinO != 2){
  109.                                                 StackMinO.push(new Stack<IntArr>());
  110.                                             }
  111.                                             StackMinO.peek().push(new IntArr(i,o));
  112.                                         }
  113.                                             lastMinO = rTiles[o][i];
  114.                                     }
  115.                                     if(o == rTiles.length-1){
  116.                                         if(rTiles[o][i] == 2){
  117.                                             if(lastMaxO != 2){
  118.                                                 StackMaxO.push(new Stack<IntArr>());
  119.                                             }
  120.                                             StackMaxO.peek().push(new IntArr(i,o));
  121.                                         }
  122.                                             lastMaxO = rTiles[o][i];
  123.                                     }
  124.                                     if(i == 0){
  125.                                         if(rTiles[o][i] == 2){
  126.                                             if(lastMinI != 2){
  127.                                                 StackMinI.push(new Stack<IntArr>());
  128.                                             }
  129.                                             StackMinI.peek().push(new IntArr(i,o));
  130.                                         }
  131.                                             lastMinI = rTiles[o][i];
  132.                                     }
  133.                                     if(i == rTiles[o].length-1){
  134.                                         if(rTiles[o][i] == 2){
  135.                                             if(lastMaxI != 2){
  136.                                                 StackMaxI.push(new Stack<IntArr>());
  137.                                             }
  138.                                             StackMaxI.peek().push(new IntArr(i,o));
  139.                                         }
  140.                                             lastMaxI = rTiles[o][i];                                   
  141.                                     }
  142.                             }
  143.                         }
  144.                     }
  145.  
  146.                     for(int i = 0; StackMinO.size() != 0; i++){
  147.                         Stack<IntArr> s = StackMinO.pop();
  148.                         if(s.size() < 4){
  149.                             continue;
  150.                         }
  151.                         s.pop();
  152.                         IntArr ia = s.pop();
  153.                         rTiles[ia.get(1)][ia.get(0)] = 0;
  154.                         ia = s.pop();
  155.                         rTiles[ia.get(1)][ia.get(0)] = 0;
  156.                         ia = s.pop();
  157.                         rTiles[ia.get(1)][ia.get(0)] = 0;
  158.                         ia = s.pop();
  159.                         rTiles[ia.get(1)][ia.get(0)] = 0;
  160.                     }
  161.                    
  162.                     for(int i = 0; StackMinI.size() != 0 ; i++){
  163.                         Stack<IntArr> s = StackMinI.pop();
  164.                         if(s.size() < 4){
  165.                             continue;
  166.                         }
  167.                         s.pop();
  168.                         IntArr ia = s.pop();                       
  169.                         rTiles[ia.get(1)][ia.get(0)] = 0;
  170.                         ia = s.pop();
  171.                         rTiles[ia.get(1)][ia.get(0)] = 0;
  172.                         ia = s.pop();
  173.                         rTiles[ia.get(1)][ia.get(0)] = 0;
  174.                         ia = s.pop();
  175.                         rTiles[ia.get(1)][ia.get(0)] = 0;
  176.                     }
  177.                    
  178.                     for(int i = 0; StackMaxO.size() != 0; i++){
  179.                         Stack<IntArr> s = StackMaxO.pop();
  180.                         if(s.size() < 4){
  181.                             continue;
  182.                         }
  183.                         s.pop();
  184.                         IntArr ia = s.pop();
  185.                         rTiles[ia.get(1)][ia.get(0)] = 0;
  186.                         ia = s.pop();
  187.                         rTiles[ia.get(1)][ia.get(0)] = 0;
  188.                         ia = s.pop();
  189.                         rTiles[ia.get(1)][ia.get(0)] = 0;
  190.                         ia = s.pop();
  191.                         rTiles[ia.get(1)][ia.get(0)] = 0;
  192.                     }
  193.                    
  194.                     for(int i = 0; StackMaxI.size() != 0; i++){
  195.                         Stack<IntArr> s = StackMaxI.pop();
  196.                         if(s.size() < 4){
  197.                             continue;
  198.                         }
  199.                         s.pop();
  200.                         IntArr ia = s.pop();
  201.                         rTiles[ia.get(1)][ia.get(0)] = 0;
  202.                         ia = s.pop();
  203.                         rTiles[ia.get(1)][ia.get(0)] = 0;
  204.                         ia = s.pop();
  205.                         rTiles[ia.get(1)][ia.get(0)] = 0;
  206.                         ia = s.pop();
  207.                         rTiles[ia.get(1)][ia.get(0)] = 0;
  208.                     }
  209.                    
  210.                    
  211.                 }
  212.        
  213.     //  System.out.println(wallSet);
  214.     }
  215.    
  216. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement