Guest User

islandgen_code

a guest
Dec 22nd, 2011
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.50 KB | None | 0 0
  1. package polytester;
  2.  
  3. import org.newdawn.slick.AppGameContainer;
  4. import org.newdawn.slick.BasicGame;
  5. import org.newdawn.slick.GameContainer;
  6. import org.newdawn.slick.Graphics;
  7. import org.newdawn.slick.Input;
  8. import org.newdawn.slick.geom.Polygon;
  9. import org.newdawn.slick.SlickException;
  10. import org.newdawn.slick.Color;
  11. import java.util.Random;
  12. import java.awt.Font;
  13. import java.util.Scanner;
  14.  
  15.  
  16. /*
  17.  * # # # # #
  18.  * # # 1 0 0
  19.  * # # # # #
  20.  * # # # # #
  21.  * # # # # #
  22.  */
  23.  
  24. public class hola extends BasicGame {
  25.    
  26.     Polygon[][] rand = new Polygon[25][25];
  27.     int[][][] grid = new int[5][25][25];
  28.     int tempax = 0, tempay = 0;
  29.     Random r = new Random();
  30.     int time;
  31.     Scanner input = new Scanner(System.in);
  32.     Font font = new Font("Helvetica", Font.BOLD, 30);
  33.     int x = 20, y = 20, number = 100, phase = 1;
  34.     int xc = 32, yc = 24;
  35.     String print;
  36.     boolean next;
  37.     int z, p, tempx, tempy;
  38.     int timer;
  39.     int checksum;
  40.     int chance;
  41.     int cursorx = 200, cursory = 200, cx = 1, cy = 1;
  42.     int sex = 0;
  43.     int countd=0;
  44.    
  45.  
  46.  
  47.     public hola() {
  48.         super("polygontest");
  49.     }
  50.     public void init(GameContainer container) throws SlickException {  
  51.        
  52.         container.setVSync(true);
  53.        
  54.         for(int z = 0; z < 25; z++){
  55.             for(int p = 0; p < 25; p++){
  56.  
  57.                 rand[z][p] = new Polygon(new float[]{
  58.                     0,0,
  59.                     0,y,
  60.                     x,y,
  61.                     x,0
  62.                 });
  63.                
  64.                 chance = r.nextInt(2);
  65.                 grid[0][z][p] = chance;
  66.                 if(chance == 1){
  67.                     rand[z][p].setLocation(z*x, p*y);
  68.                 }else{
  69.                     rand[z][p].setLocation(900, 900);
  70.                 }
  71.                 tempx++;
  72.             }
  73.        
  74.             tempy++;
  75.             tempx=0;
  76.         }
  77.        
  78.        
  79.        
  80.         for(int dope = 0; dope < 4; dope++){
  81.             for(int mattb = 0; mattb < 25; mattb++){
  82.                 for(int mattx = 0; mattx < 25; mattx++){
  83.                     if(mattb-1 >= 0 && mattb+1 <=24 && mattx-1 >= 0 && mattx+1 <= 24){
  84.                         checksum=grid[dope][mattb-1][mattx-1]+grid[dope][mattb-1][mattx]+grid[dope][mattb-1][mattx+1]+
  85.                                 grid[dope][mattb][mattx-1]+grid[dope][mattb][mattx+1]+grid[dope][mattb+1][mattx-1]+
  86.                                 grid[dope][mattb+1][mattx]+grid[dope][mattb+1][mattx+1];
  87.        
  88.                         if(checksum >= 4 && grid[dope][mattb][mattx] == 1){
  89.                             grid[dope+1][mattb][mattx] = 1;
  90.                         }
  91.                        
  92.                         if(checksum >= 5){
  93.                             grid[dope+1][mattb][mattx] = 1;
  94.                         }                      
  95.                     }
  96.                 }
  97.             }
  98.         }
  99.  
  100.        
  101.         for(int ax = 0; ax < 25; ax++){
  102.             for(int ay = 0; ay < 25; ay++){
  103.                 if(grid[4][ax][ay] == 1){
  104.                     rand[ax][ay].setLocation(ax*x, ay*y);
  105.                     tempax++;
  106.                 }
  107.             }
  108.             tempay++;
  109.             tempax=0;
  110.         }
  111.     }
  112.  
  113.    
  114.     public void update(GameContainer container, int delta) {
  115.         timer--;
  116.         if(container.getInput().isKeyDown(Input.KEY_SPACE) && timer < 0){
  117.             timer = 30;
  118.             countd++;
  119.             if(countd>4)countd=0;
  120.             for(int ax = 0; ax < 25; ax++){
  121.                 for(int ay = 0; ay < 25; ay++){
  122.                     if(grid[countd][ax][ay] == 1){
  123.                         rand[ax][ay].setLocation(ax*x, ay*y);
  124.                         tempax++;
  125.                     }
  126.                 }
  127.                 tempay++;
  128.                 tempax=0;
  129.             }
  130.            
  131.         }
  132.     }
  133.    
  134.     public void render(GameContainer container, Graphics g)  {
  135.  
  136.        
  137.         for(int d = 0; d < 25; d++){
  138.             for(int o = 0; o < 25; o++){
  139.     //          g.draw(rand[o][d]);
  140.                 if(grid[countd][d][o]==1){
  141.                     g.drawString("#", d*x, o*y);
  142.                     System.out.print("#");
  143.                 }else{
  144.                     g.drawString(" ", d*x, o*y);
  145.                     System.out.print(" ");
  146.                 }
  147.             }
  148.             System.out.println();
  149.         }
  150.         System.out.println("BREAKBREAKBREAK");
  151.     }
  152.    
  153.     public static void main(String[] argv) throws SlickException {
  154.         AppGameContainer container = new AppGameContainer(new hola(), 500, 500, false);
  155.         container.setShowFPS(false);
  156.         container.start();
  157.     }
  158. }
Advertisement
Add Comment
Please, Sign In to add comment