Pages: [1]
  Print  
Author Topic: Doors, pExit and You (aka How Doors Work)  (Read 2844 times)
hyperme
Mosskid
*
Posts: 888



View Profile
« on: May 21, 2010, 11:01:45 AM »

On the title screen, there are doors.  In game, there are doors.  But how do there work?  I'll tell you.  Why?  Because it might help with infinite Spelunky.  While reading, open up your source copy and look.  It might help you understand.

All the code for deciding where a door takes you is in the oPlayer1 object.  That's right.  The doors do next to nothing.  Just sit and act as markers.  Now, on to how the doors work.

The first part is in oPlayer1's Create event.  It sets up all the varibles used in oPlayer1 (like in all objects).  Part of these are the x[name] varibles which are like states (each one is a different number) and pExit, which is part of setting whre you go.

The second part happens in the Step event, in the Actions code, from line 274 to 354.  The part between 274 and 335 deal with dumping 'heavy' items, making the player invincible and animating you.  Between 337 and 349, you have this:

Code:
pExit = xSTART;
    if (collision_point(x, y, oXScores, 0, 0)) pExit = xSCORES;
    else if (collision_point(x, y, oXTutorial, 0, 0)) pExit = xTUTORIAL;
    else if (collision_point(x, y, oXTitle, 0, 0)) pExit = xTITLE;
    else if (collision_point(x, y, oXEnd, 0, 0)) pExit = xEND;
    else if (collision_point(x, y, oXShortcut5, 0, 0)) pExit = xSHORTCUT5;
    else if (collision_point(x, y, oXShortcut9, 0, 0)) pExit = xSHORTCUT9;
    else if (collision_point(x, y, oXShortcut13, 0, 0)) pExit = xSHORTCUT13;
    else if (collision_point(x, y, oXSun, 0, 0)) pExit = xSUN;
    else if (collision_point(x, y, oXMoon, 0, 0)) pExit = xMOON;
    else if (collision_point(x, y, oXStars, 0, 0)) pExit = xSTARS;
    else if (collision_point(x, y, oXChange, 0, 0)) pExit = xCHANGE;
    else if (collision_point(x, y, oXChange2, 0, 0)) pExit = xCHANGE2;

This sets pExit based on which door is being touched.  As already said, pExit defines where a door leads.

Finally, there is the going to bit.  It's hiding it a way.  You'd wouldn't expect to be in the Animation End event would you?  Well that's where it is.  Basically, it whips you off to where ever after you've been doored.  First it checks if you have the exit sprite (or hanging or attacking).  Then it checks pExit.  Based on which of the x[name] varibles it is equal to, it performs an actio.  All of them include going to a different room, and  have other effects based on the door.  And that's how doors work.

Now, how to add your own?  There are some simple steps.  First, go to Objects/Other/Title, and duplicate one of the oX[name] objects.  Give it a name, and stick to the oX[name] format to be simple.  Our example will be oXExample.  Wow, I know.  After that, add this to oPlayer1's Creation event code, under all the x[name] varibles.
Code:
xEXAMPLE = 13;
Next under the action code, add this at line 350:
Code:
else if (collision_point(x, y, oXExample, 0, 0)) pExit = xEXAMPLE;

Finally, add this at line 219 in the Animation End event code:
Code:
else if (pExit == xEXAMPLE)
    {
        otherstuff
        room_goto([roomname]);
    }
Setting any varibles and such must happen before the room change, because other wise the code cuts off.

So, Ladies and Gentlemen, thats how doors work.  A handful of varibles and an animation.  If knew this already, meh, if not, I hope this helps with your mods.  Good Evening, everyone.
« Last Edit: May 21, 2010, 01:45:05 PM by hyperme » Logged
marsgreekgod
Big Bossy
Mossy
*
Posts: 9806


The will of the Galaxy.


View Profile WWW Email
« Reply #1 on: May 21, 2010, 11:38:14 AM »

Oh sweet, thanks. that helps a lot
Logged

Show your power, Gun Del Hell! Show them their fate! Yes! Yes! Yes! Yes! Yes! Here we go! Let's go, go, go, go, Django! Light and Dark! It comes down to this! Be afraid, Sun!
halibabica
Bossy
Mossy
*
Posts: 2176


old guard


View Profile Email
« Reply #2 on: May 21, 2010, 07:37:41 PM »

So THAT'S how hali added that door to the Custom Start Chamber!  Shocked
Logged

Sometimes I wonder if I like Spelunky too much.
ManTrap mod - Tastes Like Spelunky
Hand-drawn comic - Spelunkying
marsgreekgod
Big Bossy
Mossy
*
Posts: 9806


The will of the Galaxy.


View Profile WWW Email
« Reply #3 on: May 21, 2010, 07:49:34 PM »

So THAT'S how hali added that door to the Custom Start Chamber!  Shocked
I... would of thought you would have known seeing as you made a custom door...
Logged

Show your power, Gun Del Hell! Show them their fate! Yes! Yes! Yes! Yes! Yes! Here we go! Let's go, go, go, go, Django! Light and Dark! It comes down to this! Be afraid, Sun!
Pages: [1]
  Print  
 
Jump to: