objects/oLevelEditor/create.gml
From spelunky.gmk, Spelunky Classic 1.1's source, © 2008, 2009 Derek Yu and Mossmouth, LLC, shown whole under the Spelunky User License v1.1b. Extracted by spelunky.ai's tools, an unofficial fan project, one file per script or event; the // ==== lines are the extractor's, naming each action of the event. Some scripts are others' work that Derek Yu credits in the source's readme.txt: Martin Piecyk's platform engine, ChevyRay's view scaling scripts and tsg1zzn's Super Sound System.
oLevelEditor's create event, 283 lines of GML.
global.cleanSolids = true;window_set_cursor(cr_none);dropVal = 0;GET_FILE_NAME = 0;EDIT = 1;INFO_NAME = 2;INFO_AUTHOR = 3;INFO_MUSIC = 4;INFO_LIFE = 5;INFO_BOMBS = 6;INFO_ROPE = 7;INFO_NEXT = 8;EXIT = 9;NEW = 10;EDIT_DOOR = 11;EDIT_MSG = 12;status = 0;levelName = "";author = "ANONYMOUS";music = "CAVE";lifeStart = "4";bombStart = "4";ropeStart = "4";nextLevel = "NONE";textEdit = "";for (j = 0; j < 32; j += 1){ for (i = 0; i < 40; i += 1) { levelArray[i, j] = "0"; }}BLOCKS = 0;ENEMIES = 1;TRAPS = 2;ITEMS = 3;dropSelect = 0;if (global.tunnel1 == 0 and global.tunnel2 > 0) dropMax = 18;else if (global.tunnel1 > 0 and global.tunnel2 == 0) dropMax = 21;else if (global.tunnel1 == 0 and global.tunnel2 == 0) dropMax = 23;else dropMax = 10;// DEBUG// dropMax = 23;blockArray[0] = "@"; // EntranceblockArray[1] = "X"; // ExitblockArray[2] = "I"; // SignblockArray[3] = "1"; // MinesblockArray[4] = "L"; // LadderblockArray[5] = "P"; // Ladder PlatformblockArray[6] = "B"; // Push BlockblockArray[7] = "&"; // WebblockArray[8] = "r"; // RockblockArray[9] = "j"; // JarblockArray[10] = "k"; // BonesblockArray[11] = "2"; // JungleblockArray[12] = "w"; // WaterblockArray[13] = "v"; // VineblockArray[14] = "t"; // Vine TopblockArray[15] = "|"; // Tree TrunkblockArray[16] = "x"; // Tree TopblockArray[17] = ")"; // Tree LeavesblockArray[18] = "q"; // Tree BranchblockArray[19] = "3"; // DarkblockArray[20] = "d"; // Dark DropblockArray[21] = "i"; // IceblockArray[22] = "4"; // TempleblockArray[23] = "l"; // LavaenemyArray[0] = "b"; // BatenemyArray[1] = "n"; // SnakeenemyArray[2] = "s"; // SpiderenemyArray[3] = "S"; // Giant SpiderenemyArray[4] = "K"; // SkeletonenemyArray[5] = "h"; // CavemanenemyArray[6] = "!"; // ShopkeeperenemyArray[7] = "f"; // FrogenemyArray[8] = "F"; // Fire FrogenemyArray[9] = "z"; // ZombieenemyArray[10] = "A"; // VampireenemyArray[11] = "M"; // Man TrapenemyArray[12] = "m"; // MonkeyenemyArray[13] = "p"; // PiranhaenemyArray[14] = "{"; // Mega MouthenemyArray[15] = "a"; // AlienenemyArray[16] = "U"; // UFOenemyArray[17] = "E"; // Alien BossenemyArray[18] = "y"; // YetienemyArray[19] = "Y"; // Yeti KingenemyArray[20] = "H"; // HawkmanenemyArray[21] = "T"; // Tomb LordtrapArray[0] = "^"; // SpikestrapArray[1] = "<"; // Arrow Trap LefttrapArray[2] = ">"; // Arrow Trap RighttrapArray[3] = "]"; // Spear Trap ToptrapArray[4] = "["; // Spear Trap BottomtrapArray[5] = "_"; // Spring TraptrapArray[6] = "+"; // Smash TraplootArray[0] = "$"; // Gold BarlootArray[1] = "*"; // Gold BarslootArray[2] = "#"; // Gold IdollootArray[3] = "O"; // Crystal SkulllootArray[4] = "5"; // EmeraldlootArray[5] = "6"; // SapphirelootArray[6] = "7"; // RubylootArray[7] = "8"; // DiamondlootArray[8] = "c"; // ChestlootArray[9] = "C"; // CratelootArray[10] = "D"; // DamsellootArray[11] = "."; // Bomb BaglootArray[12] = ":"; // Bomb BoxlootArray[13] = "u"; // PastelootArray[14] = "R"; // Rope PilelootArray[15] = "`"; // ParachutelootArray[16] = "o"; // CompasslootArray[17] = "/"; // MachetelootArray[18] = "~"; // Spring ShoeslootArray[19] = "V"; // Spike ShoeslootArray[20] = "}"; // BowlootArray[21] = "-"; // PistollootArray[22] = "="; // ShotgunlootArray[23] = "W"; // Web CannonlootArray[24] = "%"; // SpectacleslootArray[25] = "G"; // GloveslootArray[26] = "g"; // MittlootArray[27] = "?"; // TeleporterlootArray[28] = "("; // MattocklootArray[29] = "\"; // CapelootArray[30] = "J"; // Jetpackif (global.testLevel != ""){ /* status = EDIT; levelName = global.testLevel; file = file_text_open_read("levels/" + string_lower(levelName)+".lvl"); if (file) { for (j = 0; j < 32; j += 1) { str = file_text_read_string(file); for (i = 0; i < 40; i += 1) { levelArray[i, j] = string_char_at(str, i+1); scrCreateTile(levelArray[i, j], 16+i*16, 16+j*16); } file_text_readln(file); } author = file_text_read_string(file); file_text_readln(file); music = file_text_read_string(file); file_text_readln(file); lifeStart = file_text_read_string(file); file_text_readln(file); bombStart = file_text_read_string(file); file_text_readln(file); ropeStart = file_text_read_string(file); file_text_readln(file); nextLevel = file_text_read_string(file); file_text_close(file); } */ status = EDIT; levelName = global.testLevel; file = file_text_open_read("levels/test.tmp"); // file = file_text_open_read("levels/" + string_lower(levelName)+".lvl"); if (file) { for (j = 0; j < 32; j += 1) { str = file_text_read_string(file); for (i = 0; i < 40; i += 1) { levelArray[i, j] = string_char_at(str, i+1); //scrCreateTile(levelArray[i, j], 16+i*16, 16+j*16); } file_text_readln(file); } author = file_text_read_string(file); file_text_readln(file); music = file_text_read_string(file); file_text_readln(file); lifeStart = file_text_read_string(file); file_text_readln(file); bombStart = file_text_read_string(file); file_text_readln(file); ropeStart = file_text_read_string(file); file_text_readln(file); nextLevel = file_text_read_string(file); exitNamesNum = 0; if (not file_text_eof(file)) { file_text_readln(file); exitNamesNum = real(file_text_read_string(file)); } if (exitNamesNum > 0) { file_text_readln(file); for (i = 0; i < exitNamesNum; i += 1) { exitNames[i] = file_text_read_string(file); if (i < exitNamesNum-1) file_text_readln(file); } } signNamesNum = 0; if (not file_text_eof(file)) { file_text_readln(file); signNamesNum = real(file_text_read_string(file)); } if (signNamesNum > 0) { file_text_readln(file); for (i = 0; i < signNamesNum; i += 1) { signNames[i] = file_text_read_string(file); if (i < signNamesNum-1) file_text_readln(file); } } file_text_close(file); // build level exitNamesID = 0; signNamesID = 0; for (j = 0; j < 32; j += 1) { for (i = 0; i < 40; i += 1) { scrCreateTile(levelArray[i, j], 16+i*16, 16+j*16); if (levelArray[i, j] == "X") { obj = instance_position(16+i*16, 16+j*16, oExit); if (obj) { if (exitNamesNum > 0) { obj.leadsTo = exitNames[exitNamesID]; exitNamesID += 1; } } } else if (levelArray[i, j] == "@") { obj = instance_position(16+i*16, 16+j*16, oEntrance); if (obj) { if (exitNamesNum > 0) { obj.leadsTo = exitNames[exitNamesID]; exitNamesID += 1; } } } else if (levelArray[i, j] == "I") { obj = instance_position(16+i*16, 16+j*16, oMsgSign); if (obj) { if (signNamesNum > 0) { obj.message = signNames[signNamesID]; signNamesID += 1; } } } } } } window_set_cursor(cr_default); oCursObj.visible = true; instance_create(x, y, oEditButton); instance_create(x+320-32, y, oNewButton); instance_create(x+320-32, y, oTestButton);}