SirCumferance

Grid Map Layout

May 4th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3. // oMAP_BUILDER CREATE EVENT
  4.  
  5. */
  6.  
  7. // CREATE GRID
  8. global.rWorldOne = ds_grid_create(3, 3);
  9.  
  10. // ROW ONE
  11. ds_grid_set(global.rWorldOne, 0, 0, "rWorldOne_0");
  12.     ds_grid_set(global.rWorldOne, 1, 0, "rWorldOne_1");
  13.         ds_grid_set(global.rWorldOne, 2, 0, "rWorldOne_2");
  14.  
  15. // ROW TWO
  16. ds_grid_set(global.rWorldOne, 0, 1, "rWorldOne_3");
  17.     ds_grid_set(global.rWorldOne, 1, 1, "rWorldOne_4");
  18.         ds_grid_set(global.rWorldOne, 2, 1, "rWorldOne_5");
  19.  
  20. // ROW THREE
  21. ds_grid_set(global.rWorldOne, 0, 2, "rWorldOne_6");
  22.     ds_grid_set(global.rWorldOne, 1, 2, "rWorldOne_7");
  23.         ds_grid_set(global.rWorldOne, 2, 2, "rWorldOne_8");
  24.  
  25. -------------------------------------------------
  26.  
  27. /*
  28.  
  29. // oTRIGGER CREATE EVENT
  30.  
  31. */
  32.  
  33. current_world = global.rWorldOne;
  34.     world_width   = ds_grid_width(current_world);
  35.     world_height  = ds_grid_height(current_world);
  36.  
  37. current_room  = room_get_name(room);
  38.     width_half    = room_width / 2;
  39.     height_half   = room_height / 2;
  40.     margin = 32;
  41.  
  42. enum warp { none, north, west, east, south }
  43.     warp_state = warp.none;
  44.     warp_room  = noone;
  45.  
  46. /*
  47.  
  48. // oTRIGGER STEP EVENT
  49.  
  50. */
  51.  
  52. // FIND POSITION IN ROOM
  53. if y < height_half { warp_state = warp.north; }
  54. if x < width_half  { warp_state = warp.west;  }
  55. if x > width_half  { warp_state = warp.east;  }
  56. if y > height_half { warp_state = warp.south; }
  57.  
  58. // FIND WARP VALUE FROM WORLD GRID
  59. var xx;
  60. for (xx = 0; xx < world_width; xx++)
  61. {
  62.     var yy;
  63.     for (yy = 0; yy < world_height; yy++)
  64.     {
  65.         var check_room = ds_grid_get(current_world, xx, yy);
  66.         if check_room = current_room
  67.         {
  68.             if      warp_state = warp.north && (yy - 1) >= 0                { warp_room = ds_grid_get(current_world, xx, yy - 1); }
  69.             else if warp_state = warp.west  && (xx - 1) >= 0                { warp_room = ds_grid_get(current_world, xx - 1, yy); }
  70.             else if warp_state = warp.east  && (xx + 1) <= world_width  - 1 { warp_room = ds_grid_get(current_world, xx + 1, yy); }
  71.             else if warp_state = warp.south && (yy + 1) <= world_height - 1 { warp_room = ds_grid_get(current_world, xx, yy + 1); }
  72.         }
  73.     }
  74. }
  75.  
  76. // WARP PLAYER ON COLLISION
  77. if place_meeting(x, y, oPlayer)
  78. {
  79.     // MARGIN CHECK
  80.     var multiply;
  81.     if warp_state = warp.north || warp_state = warp.west { multiply = -1; } else { multiply = 1; }
  82.    
  83.     // Y AXIS WARP
  84.     var target_x, target_y;
  85.     if warp_state = warp.north || warp_state = warp.south
  86.     {
  87.         target_y = (room_height - oPlayer.y) + (margin * multiply);
  88.         target_x = oPlayer.x;
  89.     }
  90.    
  91.     // X AXIS WARP
  92.     else if warp_state = warp.west || warp_state = warp.east
  93.     {
  94.         target_y = oPlayer.y;
  95.         target_x = (room_width  - oPlayer.x) + (margin * multiply);
  96.     }
  97.    
  98.     // COMPLETE COLLISION WITH ROOM WARP
  99.     if warp_room = noone { instance_destroy(id); }
  100.     else {
  101.         oPlayer.y = target_y;
  102.         oPlayer.x = target_x;
  103.         room_goto(asset_get_index(warp_room));
  104.     }
  105. }
Add Comment
Please, Sign In to add comment