SHARE
TWEET

Pingo oLevelmanager Create Event

a guest Aug 19th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// @description Load level
  2. var lvl = string(global.CurrentLevel); // current level number
  3. if (string_length(global.CurrentLevel) < 3)
  4. {
  5.     var zeros_to_add = 3 - string_length(global.CurrentLevel);
  6.     for (var i = 0; i < zeros_to_add; i++)
  7.     {
  8.         lvl = string_insert("0",lvl,1);
  9.     }
  10. }
  11.  
  12. /*
  13.     How the fuck this works?
  14.     We stringify our global.CurrentLevel var
  15.     Then we calculate how many zeros we need to add so it'll be a 3-number string
  16.     And use string_insert to insert an amount of zeros we need
  17. */
  18.  
  19. var file = file_text_open_read("levels/World1/level"+lvl+".txt");
  20. var num = 0;
  21. while (!file_text_eof(file))
  22. {
  23.     line[num] = file_text_read_string(file);
  24.     show_debug_message(line[num]);
  25.     num++;
  26.     file_text_readln(file);
  27. }
  28. file_text_close(file);
  29. LevelPlayerSteps = 0;
  30. NextSymbol = 1;
  31. LevelIndex = real(scrReadFirstString(NextSymbol,line[0]));
  32. show_debug_message("Level Index: " + string(LevelIndex));
  33. LevelName = scrReadFirstString(NextSymbol,line[0]);
  34. LevelTwoStars = real(scrReadFirstString(NextSymbol,line[0]));
  35. LevelThreeStars = real(scrReadFirstString(NextSymbol,line[0]));
  36. LevelCanThreeStars = true;
  37. LevelCanTwoStars = false;
  38.  
  39. for (var a = 1; a < array_length_1d(line); a++)
  40. {
  41.     levelarr[a-1] = line[a];
  42.     //levelarr[a-1] = scrCharToTile(line[a]);
  43. }
  44. line = 0; //free original array
  45. ds_grid_for_tiles = ds_grid_create(string_length(levelarr[0]),array_length_1d(levelarr));
  46. _LEVELX = (960 - (ds_grid_width(ds_grid_for_tiles)*30)) / 2;
  47. _LEVELY = 100;
  48. show_debug_message(string(_LEVELX));
  49. for (var i = 0; i < ds_grid_width(ds_grid_for_tiles); i++)
  50. {
  51.     for (var j = 0; j < ds_grid_height(ds_grid_for_tiles); j++)
  52.     {
  53.         if (is_undefined(ds_grid_get(ds_grid_for_tiles,i,j))) break;
  54.         ds_grid_for_tiles[# i, j] = string_copy(levelarr[i],j+1,1);
  55.         ds_grid_for_tiles[# i, j] = scrCharToTile(ds_grid_for_tiles[# i, j]);
  56.     }
  57. }
  58. global.FloorTileCount = 0;
  59. global.PaintedTileCount = 0;
  60. global.LevelComplete = false;
  61. lvlcomplete_selected = 1;
  62. global.LevelPaused = false;
  63. for (var i = 0; i < ds_grid_width(ds_grid_for_tiles); i++)
  64. {
  65.     for (var j = 0; j < ds_grid_height(ds_grid_for_tiles); j++)
  66.     {
  67.         var cur_val = ds_grid_for_tiles[# i,j];
  68.         show_debug_message(string(i) + " : " + string(j));
  69.         var _x = _LEVELX+(i*30);
  70.         var _y = _LEVELY+(j*30);
  71.         switch (cur_val)
  72.         {
  73.             case TILES.WALL_TILE:
  74.                 instance_create_layer(_x,_y,layer,oWall); break;
  75.             case TILES.START_TILE:
  76.                 instance_create_layer(_x,_y,"Player",oBall);
  77.                 instance_create_layer(_x,_y,layer,oFloor);
  78.                 break;
  79.             case TILES.FLOOR_TILE:
  80.                 instance_create_layer(_x,_y,layer,oFloor); break;
  81.             default: instance_create_layer(_x,_y,layer,oFloor); break;
  82.         }
  83.     }
  84. }
  85. ds_grid_destroy(ds_grid_for_tiles);
  86. ds_grid_for_tiles = -1;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top