1

I have to make a navigable map the starting point is in the center there are three worlds + the final stage pressing up I have to navigate from the base to the first level of the first world and go next level in second and third pressing down I have do go from the third to the second and from the second to the first level and from the first level of the world to the base pressing left and right I have to change the world

now: I already made a lot of menus using different methods, but alway using a 1d array

obj_menu: create event:

///menu
menu[0] = "new";
menu[1] = "load";
menu[2] = "exit";

space = 55;
mpos = 0;

step event:

///move
if(inputs) {
    var move = 0;
    move -= max(keyboard_check_pressed(vk_up),0);
    move += max(keyboard_check_pressed(vk_down),0);

    if(move != 0) {    
        mpos += move;
        if(mpos < 0) { 
            mpos = array_length_1d(saveload) -1;
        }
        if(mpos > array_length_1d(saveload) -1) {
            mpos = 0;
        }
    }

    //push
    if(keyboard_check_pressed(vk_enter)) {
        scr_menu();
    }
}

scr_menu();

switch(mpos) {
case 0: { scr_new_game(); break; } //new
case 1: { scr_load_game(); break; } //load
case 2: { game_end(); break; } //exit
default: { break; }
}

This time I have to navigate in a 2d array I did this:

obj_map: create event:

///navigation setup
if(crash_to_base)       { lvl[0,0] = true }
if(base_to_ruins_1)     { lvl[1,0] = true }
if(ruins_1_to_ruins_2)  { lvl[1,1] = true }
if(ruins_2_to_ruins_3)  { lvl[1,2] = true }
if(base_to_city_1)      { lvl[2,0] = true }
if(city_1_to_city_2)    { lvl[2,1] = true }
if(city_2_to_city_3)    { lvl[2,2] = true }
if(base_to_lab_1)       { lvl[3,0] = true }
if(lab_1_to_lab_2)      { lvl[3,1] = true }
if(lab_2_to_lab_3)      { lvl[3,2] = true }
if(base_to_castle)      { lvl[4,0] = true }
//posizione del menu
mposh = 0;
mposv = 0;
mpos[mposv,mposh] = 0;

step event:

///map navigation
if(inputs) {
    moveh -= max(keyboard_check_pressed(vk_left),0);
    moveh += max(keyboard_check_pressed(vk_right),0);
    movev -= max(keyboard_check_pressed(vk_up),0);
    movev += max(keyboard_check_pressed(vk_down),0);

    if(moveh != 0) {
        //mposh += move;
    }
    if(movev != 0) {
        //mposv += move;
    }

    push    = keyboard_check_pressed(vk_enter);
    if(push) {
        scr_map();
    }
}

how to translate the first method to de sencond need??

Heavybrush
  • 79
  • 1
  • 10

1 Answers1

1

Not quite sure what your having difficulty with, perhaps you could elaborate on what exactly the problem is? On a side note however your 1D menu navigation code can be greatly simplified to:

mpos += keyboard_check_pressed(vk_up) - keyboard_check_pressed(vk_down);

var len = array_length_1d(saveload);
if (mpos < 0) { mpos = len - 1; }
if (mpos > len - 1) { mpos = 0; }

and in terms of a 2d map navigation system, it might not be beneficial to use 2d arrays and instead you could use a ds_map which allows you to store all information on each location in one data structure. For instance

var lvlMap = ds_map_create()

lvlMap[?"base-title"] = "Base"
lvlMap[?"base-travel-right"] = "crash"
lvlMap[?"base-travel-left"] = "fortress"

then when you try to move right/left:

var next_location = lvlMap[?current_location+"-travel-"+direction]
current_location = next_location
Giraugh
  • 116
  • 6