GML How do you make a Mini Map[SLOVED]

W

White_heart_of_Blood

Guest
I have been trying to make a game with a mini map but all the tutorials out there involve checking for objects when I am using a random world generator with ds-grids. I this from the Beast Heart Tutorials on how to do it, but with using the ds-grids idk how to add a mini-map. Here is my level generator code if u need it:
Code:
/// Create the level
// Resize the room
room_width = (CELL_WIDTH/16) * 720;
room_height = (CELL_HEIGHT/16) * 720;

// set grid width and height
var width = room_width div CELL_WIDTH;
var height = room_height div CELL_HEIGHT;

// Create the grid
grid = ds_grid_create(width, height);

// Fill the grid with the void
ds_grid_set_region(grid, 0, 0, width - 1, height - 1, VOID);

// Load a room
if (show_question("Would you like to load a room")) {
    var key = get_string("What is the name of the room?", "default");
    ini_open("Save.ini");
    var seed = ini_read_real("Rooms", key, 0);
    random_set_seed(seed);
} else {
    // Randomize the world
    randomize();
}

// Create the controller in the center of the grid
var cx = width div 2;
var cy = height div 2;

// Create the player
instance_create(cx*CELL_WIDTH+CELL_WIDTH/2, cy*CELL_HEIGHT+CELL_HEIGHT/2, ob_player);

// Give the controller a random direction
var cdir = irandom(3);

// The odds variable for changing direction
var odds = 1;

// Create the level using 1000 steps
repeat (1000)  {
    // Place a floor tile at the controller postion
    grid[# cx, cy] = FLOOR;
    
    // Randomize the direction of the controllr
    if (irandom(odds) == odds) {
        cdir = irandom(3);
    }
    
    // Move the controller
    var xdir = lengthdir_x(1, cdir * 90);
    var ydir = lengthdir_y(1, cdir * 90);
    cx += xdir;
    cy += ydir;
    
    // make sure we dont move outside the grid
    cx = clamp(cx, 1, width-2);
    cy = clamp(cy, 1, height-2);
}

// Add the walls
for (var yy = 1; yy < height-1; yy++) {
    for (xx = 1; xx < width-1; xx++) {
        if (grid[# xx, yy] == FLOOR) {
            // Check for walls
            if (grid[# xx+1, yy] != FLOOR) grid[# xx+1, yy] = WALL;
            if (grid[# xx-1, yy] != FLOOR) grid[# xx-1, yy] = WALL;
            if (grid[# xx, yy+1] != FLOOR) grid[# xx, yy+1] = WALL;
            if (grid[# xx, yy-1] != FLOOR) grid[# xx, yy-1] = WALL;
        }
    }
}

// Add the walls
for (var yy = 1; yy < height-1; yy++) {
    for (xx = 1; xx < width-1; xx++) {
        if (grid[# xx, yy] == WALL && grid[# xx+1, yy] == FLOOR && grid[# xx-1, yy] == FLOOR && grid[# xx, yy+1] == FLOOR && grid[# xx, yy-1] == FLOOR) {
            grid[# xx, yy] = FLOOR;
        }
    }
}

// Draw the level using the grid
for (var yy = 0; yy < height; yy++) {
    for (xx = 0; xx < width; xx++) {
        if (grid[# xx, yy] == FLOOR) {
            // Draw the floor
            tile_add(bg_floor, 0, 0, CELL_WIDTH, CELL_HEIGHT, xx*CELL_WIDTH, yy*CELL_HEIGHT, 0);
            
            // Add some chests
            var odds = 30;
            var chx = xx*CELL_WIDTH+CELL_WIDTH/2;
            var chy = yy*CELL_HEIGHT+CELL_HEIGHT/2;
            if (point_distance(chx, chy, ob_player.x, ob_player.y) > 400 && irandom(odds) == odds) {
                instance_create(chx, chy, ob_chest);
            }
        }
    }
}

// Get tile sizes
var tw = CELL_WIDTH/2;
var th = CELL_HEIGHT/2;

// Add the tiles
for (var yy = 0; yy < height*2; yy++) {
    for (xx = 0; xx < width*2; xx++) {
        if (grid[# xx div 2, yy div 2] == FLOOR) {
            // Get the tile's x and y postions
            var tx = xx*tw;
            var ty = yy*th;
            
            var right = grid[# (xx+1) div 2, yy div 2] != FLOOR;
            var left = grid[# (xx-1) div 2, yy div 2] != FLOOR;
            var top = grid[# xx div 2, (yy-1) div 2] != FLOOR;
            var bottom = grid[# xx div 2, (yy+1) div 2] != FLOOR;
            
            var top_right = grid[# (xx+1) div 2, (yy-1) div 2] != FLOOR;
            var top_left  = grid[# (xx-1) div 2, (yy-1) div 2] != FLOOR;
            var bottom_right  = grid[# (xx+1) div 2, (yy+1) div 2] != FLOOR;
            var bottom_left = grid[# (xx-1) div 2, (yy+1) div 2] != FLOOR;
            
            if (right) {
                if (bottom) {
                    tile_add(bg_walltiles, tw*4, th*1, tw, th, tx+tw, ty, -ty);
                } else if (top) {
                    if (top_right) {
                        tile_add(bg_walltiles, tw*4, th*0, tw, th, tx+tw, ty-th, -ty);
                    } else {
                        tile_add(bg_walltiles, tw*3, th*0, tw, th, tx, ty-th, -ty);
                    }
                    tile_add(bg_walltiles, tw*0, th*1, tw, th, tx+tw, ty, -ty);
                } else {
                    tile_add(bg_walltiles, tw*0, th*1, tw, th, tx+tw, ty, -ty);
                }
            }
            
            if (left) {
                if (bottom) {
                    tile_add(bg_walltiles, tw*3, th*1, tw, th, tx-tw, ty, -ty);
                } else if (top) {
                    if (top_left) {
                        tile_add(bg_walltiles, tw*3, th*0, tw, th, tx-tw, ty-th, -ty);
                    } else {
                        tile_add(bg_walltiles, tw*4, th*0, tw, th, tx, ty-th, -ty);
                    }
                    tile_add(bg_walltiles, tw*2, th*1, tw, th, tx-tw, ty, -ty);
                } else {
                    tile_add(bg_walltiles, tw*2, th*1, tw, th, tx-tw, ty, -ty);
                }
            }
            
            if (top) {
                if (!top_right) {
                    tile_add(bg_walltiles, tw*2, th*2, tw, th, tx, ty-th, -ty);
                } else if (!top_left) {
                    tile_add(bg_walltiles, tw*0, th*2, tw, th, tx, ty-th, -ty);
                } else {
                    tile_add(bg_walltiles, tw*1, th*2, tw, th, tx, ty-th, -ty);
                }
            }
            
            if (bottom) {
                if (!bottom_right) {
                    tile_add(bg_walltiles, tw*2, th*0, tw, th, tx, ty, -ty-tw);
                } else if (!bottom_left) {
                    tile_add(bg_walltiles, tw*0, th*0, tw, th, tx, ty, -ty-tw);
                } else {
                    tile_add(bg_walltiles, tw*1, th*0, tw, th, tx, ty, -ty-tw);
                }
            }
        }
    }
}
This is all in the create event of the object if u know how to do this pls help if u can
 

Tsa05

Member
Use a view.


;)

But really--that's a thing that views can be great at. You make a view that's your visible area, then you make another view that covers the larger area.
You assign the larger view to show in a small port on the screen, in the corner somewhere. Can be done just using the room editor, unless you need the maps to move. Then, you just move the view (or camera in GMS2) with code.
 
W

White_heart_of_Blood

Guest
Use a view.


;)

But really--that's a thing that views can be great at. You make a view that's your visible area, then you make another view that covers the larger area.
You assign the larger view to show in a small port on the screen, in the corner somewhere. Can be done just using the room editor, unless you need the maps to move. Then, you just move the view (or camera in GMS2) with code.
Ok I well try and btw I am using GMS and I well try this I do not normaly use views for this type of thing I normaly just use them to follow the player thats all

Edit: I did it! It works! thxs so much I didnt know about this thxs :D
 
Last edited by a moderator:
Z

zendraw

Guest
i used to create a sprite from a surface for static objects, and draw dynamic objects in the draw event, atleast the ones that were close.
 
Top