NathansSandbox

scr_starGrid (Ep. 16)

Jul 17th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ///===STAR GRID===///
  2. randomize();
  3. //Clean Up Stars
  4. if (room = rm_game) {
  5.     with (obj_star) {
  6.         instance_destroy();
  7.     }
  8. }
  9. //Initialize Stars (6 Star Variables, 60 Stars)
  10. starGrid = ds_grid_create(obj_core.starVariables,obj_core.starsAmount);
  11. starNameList = ds_list_create();
  12. var gridHeight = ds_grid_height(starGrid);
  13. //Grid Values (Column)
  14. obj_core.starNameNr = 0; obj_core.imageIndex = 1;
  15. obj_core.xPos = 2; obj_core.yPos = 3;
  16. obj_core.alive = 4; obj_core.discovered = 5;
  17. //Switch Check
  18. switch (obj_core.newGame) {
  19.     //LOAD GAME
  20.     case (false):
  21.         //Load Star Grid & List
  22.         ini_open("Star_Grid.ini");
  23.         ds_grid_read(starGrid,ini_read_string("Star Grid","Grid",""));
  24.         ds_list_read(starNameList,ini_read_string("Star Grid","Names",""));
  25.         ini_close();
  26.         //Create Stars
  27.         for (starIndex=0; starIndex<gridHeight; starIndex++) {
  28.             scr_createStars();
  29.         }
  30.     break;
  31.     //NEW GAME
  32.     case (true):
  33.         for (starIndex=0; starIndex<gridHeight; starIndex++) {
  34.             //Add Star Names
  35.             scr_randomNameGenerator();
  36.             randName = obj_core.nameTemp;
  37.             ds_grid_set(starGrid,obj_core.starNameNr,starIndex,starIndex);
  38.             ds_list_add(starNameList,randName);
  39.             //Add Image Index
  40.             randImageIndex = floor(random(obj_core.starSpritesTotal));
  41.             ds_grid_set(starGrid,obj_core.imageIndex,starIndex,randImageIndex);
  42.             //Add X-Positions
  43.             randX = 100+random(room_width-200);
  44.             ds_grid_set(starGrid,obj_core.xPos,starIndex,randX);
  45.             //Add Y-Positions
  46.             randY = 100+random(room_height-200);
  47.             ds_grid_set(starGrid,obj_core.yPos,starIndex,randY);
  48.             //Add Alive Status
  49.             ds_grid_set(starGrid,obj_core.alive,starIndex,1);
  50.             //Add Discovered Status
  51.             ds_grid_set(starGrid,obj_core.discovered,starIndex,0);
  52.             //Create Stars & Transfer Values
  53.             scr_createStars();
  54.             //Save Star Grid & List
  55.             ini_open("Star_Grid.ini");
  56.             ini_write_string("Star Grid","Grid",ds_grid_write(starGrid));
  57.             ini_write_string("Star Grid","Names",ds_list_write(starNameList));
  58.             ini_close();
  59.         }
  60.         //Disable New Game
  61.         obj_core.newGame = false;
  62.     break;
  63. }  
  64. //Clean Up
  65. ds_grid_destroy(starGrid);
  66. ds_list_destroy(starNameList);
Add Comment
Please, Sign In to add comment