Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Counter = 0 ;
- //width height div cell
- gWidth = room_width div CELL;
- gHeight = room_height div CELL;
- //create grid... be mindful of edge
- PlacesGrid = ds_grid_create(gWidth, gHeight); //not so sure about the edges
- //set entire grid region as void
- ds_grid_set_region(PlacesGrid, 0, 0, gWidth -1 , gHeight , FLOOR);
- //distribute types according to odds
- for(iX = 0; iX < gWidth; iX ++) {
- for(iY = 0; iY < gHeight; iY ++){
- var TileOdds = irandom(99);
- if TileOdds <= 33 {
- PlacesGrid[# iX,iY] = WALL;
- }
- }
- }
- //add the boarder
- for(iX = 0; iX < gWidth; iX ++) {
- for(iY = 0; iY < gHeight; iY ++){
- PlacesGrid[# iX, 0] = WALL;
- PlacesGrid[# 0, iY] = WALL;
- PlacesGrid[# iX, gHeight -1] = WALL;
- PlacesGrid[# gWidth -1, iY] = WALL;
- }
- }
- //"cellular automation" I guess
- repeat(2){
- for(iX = 1; iX < gWidth -1; iX ++) {
- for(iY = 1; iY < gHeight -1; iY ++){
- var TileCount = 0;
- if PlacesGrid[# iX, iY] = FLOOR {
- TileCount +=1;
- if (PlacesGrid[# iX +1, iY] == FLOOR) TileCount +=1;
- if (PlacesGrid[# iX +1, iY -1] == FLOOR) TileCount +=1;
- if (PlacesGrid[# iX, iY -1] == FLOOR) TileCount +=1;
- if (PlacesGrid[# iX -1, iY -1] == FLOOR) TileCount +=1;
- if (PlacesGrid[# iX -1, iY] == FLOOR) TileCount +=1;
- if (PlacesGrid[# iX -1, iY +1] == FLOOR) TileCount +=1;
- if (PlacesGrid[# iX, iY +1] == FLOOR) TileCount +=1;
- if (PlacesGrid[# iX +1, iY +1] == FLOOR) TileCount +=1;
- if (TileCount <= 4) PlacesGrid[# iX,iY] = WALL;
- }
- if PlacesGrid[# iX, iY] = WALL{
- TileCount +=1;
- if (PlacesGrid[# iX +1, iY] == WALL) TileCount +=1;
- if (PlacesGrid[# iX +1, iY -1] == WALL) TileCount +=1;
- if (PlacesGrid[# iX, iY -1] == WALL) TileCount +=1;
- if (PlacesGrid[# iX -1, iY -1] == WALL) TileCount +=1;
- if (PlacesGrid[# iX -1, iY] == WALL) TileCount +=1;
- if (PlacesGrid[# iX -1, iY +1] == WALL) TileCount +=1;
- if (PlacesGrid[# iX, iY +1] == WALL) TileCount +=1;
- if (PlacesGrid[# iX +1, iY +1] == WALL) TileCount +=1;
- if (TileCount < 4) PlacesGrid[# iX,iY] = FLOOR;
- }
- }
- }
- }
- //Get rid of alone floor tiles
- for(iX = 0; iX < gWidth -1; iX++){
- for(iY = 0; iY < gHeight -1; iY++){
- if PlacesGrid[#iX, iY] == FLOOR {
- if PlacesGrid[# iX + 1, iY] == WALL and
- PlacesGrid[# iX, iY -1] == WALL and
- PlacesGrid[# iX -1 , iY] == WALL and
- PlacesGrid[# iX, iY + 1] == WALL {
- PlacesGrid[# iX, iY] = WALL
- }
- }
- }
- }
- //Make sure there's no island FLOOR tiles or isolated clusters of them
- //add the boarder again
- for(iX = 0; iX < gWidth; iX ++) {
- for(iY = 0; iY < gHeight; iY ++){
- PlacesGrid[# iX, 0] = WALL;
- PlacesGrid[# 0, iY] = WALL;
- PlacesGrid[# iX, gHeight -1] = WALL;
- PlacesGrid[# gWidth -1, iY] = WALL;
- }
- }
- //Choose a starting CELL towards the centre that is FLOOR
- XRand = floor(irandom_range(gWidth /2 -10, gWidth /2 + 10 ));
- YRand = floor(irandom_range(gHeight /2 -10, gHeight /2 +10));
- StartCell = PlacesGrid[# XRand, YRand];
- while StartCell != FLOOR {
- XRand = irandom_range(10, gWidth -10 );
- YRand = irandom_range(10, gHeight -10);
- StartCell = PlacesGrid[# XRand, YRand];
- }
- //add objCell to FLOOR tiles
- for (var iX = 0; iX < gWidth; iX++){
- for (var iY = 0; iY < gHeight; iY++) {
- if PlacesGrid[# iX, iY] == WALL {
- NewCell = instance_create_depth(iX * CELL, iY * CELL, 0, objCell32);
- NewCell.iX = iX;
- NewCell.iY = iY;
- NewCell.gWidth = gWidth;
- NewCell.gHeight = gHeight;
- }//if PlacesGrid[# iX, iY] == FLOOR {
- }
- }
- //Landlocked = path_add();
- LandLockedGrid = mp_grid_create(0,0,gWidth,gHeight,CELL,CELL);
- mp_grid_add_instances(LandLockedGrid, objCell32,0);
- //try to trace a path back from each floor tile
- for(iX = 0; iX < gWidth; iX++) {
- for(iY = 0; iY < gHeight; iY++){
- if PlacesGrid[# iX, iY] == FLOOR {
- var Landlocked = path_add();
- if mp_grid_path(LandLockedGrid, Landlocked, iX * CELL + (CELL /2), iY * CELL + (CELL /2), XRand * CELL + (CELL /2), YRand * CELL + (CELL /2),false) == false {
- PlacesGrid[# iX, iY] = WALL;
- path_delete(Landlocked);
- }
- }
- }
- }
- with objCell32 {
- instance_destroy();
- }
- //create the move grid and add the wall instances...
- //... and THEN destroy the wall objects
- MoveGrid = mp_grid_create(CELL, CELL, gWidth -2, gHeight -2, 32,32);
- for (iX = 0; iX < gWidth; iX++){
- for(iY = 0; iY < gHeight; iY++){
- if PlacesGrid[# iX, iY] == WALL {
- instance_create_depth(iX * CELL,iY * CELL,0,objWall32);
- }
- }
- }
- mp_grid_add_instances(MoveGrid, objWall32, false);
- with objWall32 {
- instance_destroy();
- }
- //doing corner things...
- //... so we won't be taking note of EVERY corner in the room, just isolated ones
- for (iX = 0; iX < gWidth; iX++){
- for (iY = 0; iY < gHeight; iY++) {
- if PlacesGrid[# iX, iY] == FLOOR {
- var GridCount = instance_create_depth(iX * CELL, iY * CELL, global.PD +11, objCell32);
- with GridCount {
- if Places.PlacesGrid[# MyIX +1, MyIY +1] == WALL {
- Points +=1;
- }
- if Places.PlacesGrid[# MyIX +1, MyIY] == WALL {
- Points +=2;
- }
- if Places.PlacesGrid[# MyIX +1, MyIY -1] == WALL {
- Points +=1;
- }
- if Places.PlacesGrid[# MyIX, MyIY -1] == WALL {
- Points +=2;
- }
- if Places.PlacesGrid[# MyIX -1, MyIY -1] == WALL {
- Points +=1;
- }
- if Places.PlacesGrid[# MyIX -1, MyIY] == WALL {
- Points +=2;
- }
- if Places.PlacesGrid[# MyIX -1, MyIY +1] == WALL {
- Points +=1;
- }
- if Places.PlacesGrid[# MyIX, MyIY +1] == WALL {
- Points +=2;
- }
- if (Points != 1) instance_destroy();
- }
- }
- }
- }
- //get rid of clusters of diagonals
- with objCell32 {
- if place_meeting(x + CELL, y + CELL, objCell32) and
- place_meeting(x - CELL, y - CELL, objCell32) {
- instance_destroy();
- }
- if place_meeting(x - CELL, y + CELL, objCell32) and
- place_meeting(x + CELL, y - CELL, objCell32) {
- instance_destroy();
- }
- }
- var Height = instance_number(objCell32);
- //CornerIdGrid... 0=id,1=x,2=y,3=distance to center
- CornerIdGrid = ds_grid_create(4,Height);
- with objCell32 {
- ds_grid_add(Places.CornerIdGrid,0,Places.Counter,id);
- ds_grid_add(Places.CornerIdGrid,1,Places.Counter,x);
- ds_grid_add(Places.CornerIdGrid,2,Places.Counter,y);
- var Center = point_distance(x,y,room_width/2,room_height/2);
- ds_grid_add(Places.CornerIdGrid,3,Places.Counter,Center);
- Places.Counter +=1;
- }
- with objCell32 {
- instance_destroy();
- }
- ds_grid_sort(CornerIdGrid,3,true);
- //this is the actual BASIC spawner so far
- for(iN = 0; iN < 30; iN++){
- var Inst = ds_grid_get(CornerIdGrid,0,iN);
- var InstX = ds_grid_get(CornerIdGrid,1,iN);
- var InstY = ds_grid_get(CornerIdGrid,2,iN);
- instance_create_depth(InstX,InstY,global.PD +10,objTowerMount);
- //instance_create_depth(Inst.x,Inst.y,global.PD +10,objTowerMount);
- }
- //add the tiles LAST STEP
- for(iX = 0; iX < gWidth; iX ++) {
- for(iY = 0; iY < gHeight; iY ++){
- if PlacesGrid[# iX, iY] == WALL {
- //instance_create_depth(iX * CELL,iY * CELL,0,objWall)
- tile_add(sprWall32,0,0,CELL,CELL,iX *CELL, iY * CELL,global.PD + 15)
- }
- if PlacesGrid[# iX, iY] == FLOOR {
- tile_add(bgBrown32,choose(0,CELL,CELL * 2,CELL * 3) ,choose(0,CELL,CELL * 2,CELL * 3),DUnit,DUnit,iX * CELL,iY * CELL, global.PD + 15)
- }
- }
- }
- //now call "lights!"
- instance_create_depth(0,0, -1, Lights);
- //now the object to spawn the player
- instance_create_depth(room_width /2, room_height /2, -90, objPlacing);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement