1. Hey! Guest! The 32nd GMC Jam will take place between Feb 22nd, 12:00 UTC (Friday noon) and Feb 25th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

Scrolling Minimap (surfaces)

Discussion in 'Programming' started by Shadowrend, Feb 13, 2019 at 9:24 PM.

  1. Shadowrend

    Shadowrend Member

    Joined:
    Jun 20, 2016
    Posts:
    20
    Hello, I've made a minimap that works good, but I can't get it to move right, following the player, and not go out of bounds.
    Here is a screenshot how it looks.
    Runner_mAKOQ7r0YZ.png
    Now the issue is that I can get it to move left/right/up/down, and I managed to make it not go off the bounds to the left and up, but as far as right/down go it just won't scroll that way when the player goes in that direction. Basically, the minimap can only move to the left, up to a certain point. Basically it should follow the player (who should be in the center) and when the player is near the edge of the actual map, it should stop scrolling and only the player dot should move on it. Here is the code I'm using, I just cant get the math right, and I tried all combinations of min,max,median etc:
    Code:
    //CREATE
    mip_x = 0;
    mip_y = 0;
    mip_w = 160;
    mip_h = 160;
    mip_res = 4;
    mip_c_x = 0;
    mip_c_y = 0;
    mim_x = 32;
    mim_y = 32;
    
    mip_surf = surface_create(ds_grid_width(global.world), ds_grid_height(global.world));
    surface_set_target(mip_surf);
    draw_clear_alpha(c_black, 0);
    surface_reset_target();
    
    mm_surf = surface_create(mip_w, mip_h);
    surface_set_target(mm_surf);
    draw_clear_alpha(c_black, 0);
    surface_reset_target();
    
    Code:
    //map_draw_block()
    draw_point(argument0, argument1); //with a switch for colour before
    
    Code:
    //DRAW
    surface_set_target(mip_surf);
    for (mm_w=0; mm_w<=room_wid; mm_w++) { //room_wid = room_width/global.grid (32)
        for (mm_h=0; mm_h<=room_hei; mm_h++) {
           minimap_draw_block(mm_w, mm_h);
       }
    }
    surface_reset_target();
    
    mip_c_x = floor((obj_player.x-16)/global.grid)*mip_res;
    mip_c_y = floor((obj_player.y-16)/global.grid)*mip_res;
    
    surface_set_target(mm_surf);
    draw_clear_alpha(c_black, 0);
    //HERE IS THE PROBLEM >
    draw_surface_ext(mip_surf, min(0, mip_c_x), mim_y+clamp(mim_y-mip_c_y, 0, room_wid), mip_res, mip_res, 0, c_white, 1);
    surface_reset_target();
    
    draw_surface(mm_surf, mim_x, mim_y);

    Thanks :)
    ~Shadowrend
     
  2. CoolGiraffe1

    CoolGiraffe1 Member

    Joined:
    Feb 3, 2019
    Posts:
    38
  3. Shadowrend

    Shadowrend Member

    Joined:
    Jun 20, 2016
    Posts:
    20
  4. Sn3akyP1xel

    Sn3akyP1xel Member

    Joined:
    Mar 13, 2018
    Posts:
    42
    Not sure if this will work, but try it anyway:
    Code:
    if (mip_c_x<0){mip_c_x=0};
    draw_surface_ext(mip_surf, mip_c_x, mim_y+clamp(mim_y-mip_c_y, 0, room_wid), mip_res, mip_res, 0, c_white, 1);
    Not had a chance to test your code as im kinda busy, but it's on a hunch.
    It just removes 'min', which might be causing the problem.
     
  5. Shadowrend

    Shadowrend Member

    Joined:
    Jun 20, 2016
    Posts:
    20
    No, doesn't work :(
    But thanks
     
  6. Sn3akyP1xel

    Sn3akyP1xel Member

    Joined:
    Mar 13, 2018
    Posts:
    42
    hmmm... maybe try flooring after the full calculation:
    Code:
    mip_c_x = floor(((obj_player.x-16)/global.grid)*mip_res);
    mip_c_y = floor(((obj_player.y-16)/global.grid)*mip_res);
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice