I'm making my world randomly generate stuff for a game I'm making but the problem is the world will not load after pressing reset or compiling it again. I know it is capable of loading the world because i have usually successfully loaded it on the first try but I cant load It again after that? I don't know if its because I'm using too much memory or some other reason so I'm asking for help on spotting the problem because I'm not even sure what the problem is D:
problem is most likely in the constructor because loading the world is my problem and when the world loads successfully i have no problems with it
oh yeah heres the source in case u guys need it http://www.greenfoot.org/scenarios/10478
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | public class Field extends World { public Point[][] grid; public int [][] gridState; private Mover m; private final int WATER = 2 ; private final int OCCUPIED = 1 ; private final int EMPTY = 0 ; public Field() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super ( 1000 , 800 , 1 ); m = new Mover( this ); grid = new Point[ 50 ][ 40 ]; //used for pathing, objects, and etc(maybe fog of war as well) gridState = new int [ 50 ][ 40 ]; //is the square ocupied? what occupies it for ( int x = 0 ; x < 50 ; x++) { for ( int y = 0 ; y < 40 ; y ++) { grid[x][y] = new Point(x* 20 + 10 , y* 20 + 10 ); } } spawnRiver(); spawnTrees( 16 ); } public void act() { m.move(); } public void spawnRiver() { int x = Greenfoot.getRandomNumber( 10 )+ 20 ; int y = Greenfoot.getRandomNumber( 10 )+ 15 ; int x2 = 0 ; int y2 = 0 ; while (gridState[x][y] != EMPTY) { x = Greenfoot.getRandomNumber( 10 )+ 20 ; y = Greenfoot.getRandomNumber( 10 )+ 15 ; } Point newP = new Point(x, y); if (Greenfoot.getRandomNumber( 10 ) < 5 ){x2 = x - 1 ;} else {x2 = x + 1 ;} if (Greenfoot.getRandomNumber( 10 ) < 5 ){y2 = y - 1 ;} else {y2 = y + 1 ;} Point newP2 = new Point(x2, y2); spawnRiverHelper(x2, y2, newP, newP2); spawnRiverHelper(x, y, newP2, newP); } public void spawnRiverHelper( int x, int y, Point origin, Point secondary) { if (x == 0 || x == 49 || y == 0 || y == 39 ) //at one of the edge piece { spawnWater(x, y); } else { spawnWater(x, y); int newX = 0 ; int newY = 0 ; if (Greenfoot.getRandomNumber( 10 ) < 5 ){newX = x - 1 ;} else {newX = x + 1 ;} if (Greenfoot.getRandomNumber( 10 ) < 5 ){newY = y - 1 ;} else {newY = y + 1 ;} Point newP = new Point(newX, newY); while (newP.nextTo(origin)) { if (Greenfoot.getRandomNumber( 10 ) < 5 ){newX = x - 1 ;} else {newX = x + 1 ;} if (Greenfoot.getRandomNumber( 10 ) < 5 ){newY = y - 1 ;} else {newY = y + 1 ;} newP = new Point(newX, newY); } spawnRiverHelper(newX, newY, secondary, newP); } } public void spawnWater( int x, int y) //grid's x and y!! not world's x and y { Point p = grid[x][y]; Water w = new Water(); addObject(w, p.x, p.y); gridState[x][y] = WATER; } public void spawnTrees( int amount) { for ( int n = 0 ; n < amount; n ++) //planting trees { Tree t = new Tree(); int x = Greenfoot.getRandomNumber( 50 ); int y = Greenfoot.getRandomNumber( 40 ); while (gridState[x][y] != EMPTY) { x = Greenfoot.getRandomNumber( 50 ); y = Greenfoot.getRandomNumber( 40 ); } Point p = grid[x][y]; addObject(t, p.x, p.y); gridState[x][y] = OCCUPIED; } } } |