Advertisement
Ulabael

scrSaveLoad()

Jul 23rd, 2022 (edited)
1,051
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function scrSaveLoad()
  2. {
  3.     if (file_exists("Save_Game.save"))
  4.     {
  5.         room_restart();
  6.        
  7.         with oObject instance_destroy();
  8.         with oCamera instance_destroy();
  9.         with oPlayer instance_destroy();
  10.         with oGrid instance_destroy();
  11.         with oChar instance_destroy();
  12.         ds_grid_destroy(global.grid)
  13.        
  14.        
  15.         var lay_id_blocks = layer_get_id("BlockLayer");
  16.         var map_id_blocks = layer_tilemap_get_id(lay_id_blocks)
  17.         var lay_id_block_backs = layer_get_id("Backs");
  18.         var map_id_block_backs = layer_tilemap_get_id(lay_id_block_backs)
  19.         var lay_id_shadows = layer_get_id("ShadowLayer");
  20.         var map_id_shadows = layer_tilemap_get_id(lay_id_shadows)
  21.    
  22.  
  23.         var _buffer = buffer_load("Save_Game.save");
  24.         var _string = buffer_read(_buffer, buffer_string);
  25.         buffer_delete(_buffer);
  26.         var _loadData = json_parse(_string);
  27.         for (var i = 0; i < array_length(_loadData); ++i)
  28.         {
  29.             if _loadData[i].obj == "oGameManager"
  30.             {
  31.                 global.game_fps = _loadData[i].game_fps;
  32.                 global.draw_shadows = _loadData[i].draw_shadows;
  33.                 global.CameraNum = _loadData[i].CameraNum;
  34.                 global.CameraWidth = global.CameraSizes[global.CameraNum][0]
  35.                 global.CameraHeight = global.CameraSizes[global.CameraNum][1]
  36.                 game_set_speed(global.fps_array[global.game_fps], gamespeed_fps);
  37.             }
  38.             else if _loadData[i].obj == "oPlayer"
  39.             {
  40.                 with (instance_create_layer(0, 0, "Instances", asset_get_index(_loadData[i].obj)))
  41.                 {
  42.                     x = _loadData[i].x;
  43.                     y = _loadData[i].y;
  44.                     player_speed = _loadData[i].player_speed;
  45.                 }                  
  46.             }
  47.             else if _loadData[i].obj == "oCamera"
  48.             {
  49.                 with (instance_create_layer(0, 0, "Instances", asset_get_index(_loadData[i].obj)))
  50.                 {
  51.                     cameraX = _loadData[i].cameraX;
  52.                     cameraY = _loadData[i].cameraY;
  53.                     cameraWidth = _loadData[i].cameraWidth;
  54.                     cameraHeight = _loadData[i].cameraHeight;
  55.                     camera_set_view_pos(global.Camera, cameraX, cameraY);
  56.                     camera_set_view_size(global.Camera, cameraWidth, cameraHeight);
  57.                 }                  
  58.             }
  59.             else if _loadData[i].obj == "oGrid"
  60.             {
  61.                 with (instance_create_layer(0, 0, "Instances", asset_get_index(_loadData[i].obj)))
  62.                 {
  63.                     cells_x = _loadData[i].cells_x
  64.                     cells_y = _loadData[i].cells_y
  65.                     event_user(0); // Вызываем событие создания сетки
  66.                 }                  
  67.             }
  68.             else if _loadData[i].obj == "Tile"
  69.             {
  70.                 tilemap_set(map_id_blocks, _loadData[i].tile_block, _loadData[i].cell_x, _loadData[i].cell_y)
  71.                 tilemap_set(map_id_block_backs, _loadData[i].tile_backs, _loadData[i].cell_x, _loadData[i].cell_y)
  72.                 tilemap_set(map_id_shadows, _loadData[i].tile_shadows, _loadData[i].cell_x, _loadData[i].cell_y)   
  73.                 ds_grid_set(global.grid, _loadData[i].cell_x, _loadData[i].cell_y, _loadData[i].cost)
  74.             }
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement