//Just plops down a spawner and some blocks - haphazard and crappy atm but functional! protected void buildRoom(int RX,int RY,bool Spawners) { //first place the spawn point (if necessary) int rw = 20; int sx = 0; int sy = 0; if(Spawners) { sx = (int) (2+FlxG.random()*(rw-7)); sy = (int) (2+FlxG.random()*(rw-7)); } //then place a bunch of blocks int numBlocks = (int) (3+FlxG.random()*4); if(!Spawners) numBlocks++; int maxW = 10; int minW = 2; int maxH = 8; int minH = 1; int bx; int by; int bw; int bh; bool check; for(int i = 0; i < numBlocks; i++) { do { //keep generating different specs if they overlap the spawner bw = (int) (minW + FlxG.random()*(maxW-minW)); bh = (int) (minH + FlxG.random()*(maxH-minH)); bx = (int) (-1 + FlxG.random()*(rw+1-bw)); by = (int) (-1 + FlxG.random()*(rw+1-bh)); if(Spawners) check = ((sx>bx+bw) || (sx+3<bx) || (sy>by+bh) || (sy+3<by)); else check = true; } while(!check); FlxTileblock b; b = new FlxTileblock(RX+bx*8,RY+by*8,bw*8,bh*8); b.loadTiles(ImgTech); _blocks.add(b); //If the block has room, add some non-colliding "dirt" graphics for variety if((bw >= 4) && (bh >= 5)) { b = new FlxTileblock(RX+bx*8+8,RY+by*8,bw*8-16,8); b.loadTiles(ImgDirtTop); _decorations.add(b); b = new FlxTileblock(RX+bx*8+8,RY+by*8+8,bw*8-16,bh*8-24); b.loadTiles(ImgDirt); _decorations.add(b); } } if(Spawners) { //Finally actually add the spawner Spawner sp = new Spawner(RX+sx*8,RY+sy*8,_bigGibs,_enemies,_enemyBullets,_littleGibs,_player); _spawners.add(sp); //Then create a dedicated camera to watch the spawner _hud.add(new FlxSprite(3 + (_spawners.length-1)*16, 3, ImgMiniFrame)); FlxCamera camera = new FlxCamera(10 + (_spawners.length-1)*32,10,24,24,1); camera.follow(sp); FlxG.addCamera(camera); } }
//These next two functions look crazy, but all they're doing is generating //the level structure and placing the enemy spawners. protected void generateLevel() { int r = 160; FlxTileblock b; //First, we create the walls, ceiling and floors: b = new FlxTileblock(0,0,640,16); b.loadTiles(ImgTech); _blocks.add(b); b = new FlxTileblock(0,16,16,640-16); b.loadTiles(ImgTech); _blocks.add(b); b = new FlxTileblock(640-16,16,16,640-16); b.loadTiles(ImgTech); _blocks.add(b); b = new FlxTileblock(16,640-24,640-32,8); b.loadTiles(ImgDirtTop); _blocks.add(b); b = new FlxTileblock(16,640-16,640-32,16); b.loadTiles(ImgDirt); _blocks.add(b); //Then we split the game world up into a 4x4 grid, //and generate some blocks in each area. Some grid spaces //also get a spawner! buildRoom(r*0,r*0,true); buildRoom(r*1,r*0); buildRoom(r*2,r*0); buildRoom(r*3,r*0,true); buildRoom(r*0,r*1,true); buildRoom(r*1,r*1); buildRoom(r*2,r*1); buildRoom(r*3,r*1,true); buildRoom(r*0,r*2); buildRoom(r*1,r*2); buildRoom(r*2,r*2); buildRoom(r*3,r*2); buildRoom(r*0,r*3,true); buildRoom(r*1,r*3); buildRoom(r*2,r*3); buildRoom(r*3,r*3,true); }