| MCS' Coding Tips "Success!" |
![]() |
Adding a teleporter Written by MCS Tested by BrotherTank |
| Main Page News Wolfenstein 3D Texture Library MCS' Coding Tips - "Success"! Utilities Spear Resurrection Wolfendoom Wolf Collection Original Wolf 3D Doom/Duke maps Other Stuff Links Questions? Email us! |
| Not very realistic in a WWII game setting, I know. But if you don't care about this (or you're creating some addon based on a "futuristic" theme like Blake Stone), you can add an extra dimension to your game. This method will let you "warp" within the same level. Note: this tutorial describes how to make teleporters that are "East" or "West" oriented like the elevators in the original Wolf. It's easy to expand things to North and South as well, once you'll get the hang of it. 1. Adding definitions to WL_DEF.H We'll use particular tile values for the teleporter, as ID did for the elevators. Open WL_DEF.H and do a search for: #define ALTELEVATORTILE 107 add the following lines below: #define WARPEASTTILE 100 #define WARPWESTTILE 102 We also have to declare the warp coordinates. Do a search for extern unsigned plux,pluy; and add this line below: extern int warpwx,warpwy,warpex,warpey; 2. Adding the teleporter code. The actual code for the teleporter will be added to WL_AGENT.C Open WL_AGENT.C and locate this line: void T_Attack (objtype *ob); enter this line below: void WarpPlayer (int facedir); Next, paste this block at the very end of the file: void WarpPlayer (int facedir) { objtype *check; int x,y; buttonstate[bt_attack] = false; buttonheld[bt_attack] = false; gamestate.attackframe = 0; gamestate.weaponframe = 0; DrawPlayerWeapon(); ThreeDRefresh(); switch (facedir) { case EAST: check = actorat[warpex][warpey]; if (check > objlist && (check->flags & FL_SHOOTABLE)) KillActor(check); SpawnPlayer(warpex,warpey,facedir); break; case WEST: check = actorat[warpwx][warpwy]; if (check > objlist && (check->flags & FL_SHOOTABLE)) KillActor(check); SpawnPlayer(warpwx,warpwy,facedir); break; } SD_PlaySound (BOSSACTIVESND); if (DigiMode != sds_Off) { long lasttimecount = TimeCount; while(TimeCount < lasttimecount+35) //adjust warp duration here SD_Poll(); } else VW_WaitVBL(1*50); buttonstate[bt_attack] = false; buttonheld[bt_attack] = false; gamestate.attackframe = 0; gamestate.weaponframe = 0; DrawPlayerWeapon(); ThreeDRefresh(); } 3. Calling the teleporter code Also in WL_AGENT.C, locate this block: if (*(mapsegs[1] + offset) == EXITTILE) VictoryTile (); and add these lines below: if (*(mapsegs[1] + offset) == WARPEASTTILE) WarpPlayer(EAST); if (*(mapsegs[1] + offset) == WARPWESTTILE) WarpPlayer(WEST); 4. Adding the teleport locations to MapEdit definition files. In order to use the teleport facility in your levels, you need to add entries for them in your MapEdit definition files. Open OBJDATA.WL6 and add the following lines: 0064 5e50 Teleport Artefact 1 0065 e2f0 Teleport to here 1 0066 5b50 Teleport Artefact 2 0067 b6f0 Teleport to here 2 |
| 5. Spawning the teleport locations at startup. In order to spawn the added teleport entries, we need to insert entries for them into the engine. To add the coordinate declaration, open WL_GAME.C and locate boolean spearflag; and enter this line below: int warpwx,warpwy,warpex,warpey; Also in WL_GAME.C, locate this block: case 22: SpawnPlayer(x,y,NORTH+tile-19); break; add these lines below: case 100: // Warp in East SpawnStatic(x,y,0); break; case 101: // Warp out East warpex = x; warpey = y; break; case 102: // Warp in West SpawnStatic(x,y,0); break; case 103: // Warp out West warpwx = x; warpwy = y; break; Note: look at the line SpawnStatic(x,y,0); The "0" means that a water puddle will be displayed at the "warp in" locations. Of course you want to use your own "Teleporter sprite". That's OK, any sprite will do, as long as it's a non-blocking one. Adjust things by replacing the "0" with the proper value of your sprite (see WL_ACT1.C) Using this example, you can have just one EAST and one WEST teleporter per level (well you can have more, but they'll all point to the same TO EAST or TO WEST locations). If you really need more of them, you'll have to define additional WARPX and WARPY coordinates for each one of them, and you'll also have to insert additional definitions in WL_DEF.H, WL_GAME.C and OBJDATA.WL6. Also make sure that enemies won't block the warp destinations. In this example, they will be killed when you're warping as a last resort (like in Heretic), but there's still a minor chance that you will get stuck. So keep this in mind when making level designs. Success! MCS. |