Page 1 of 1

How do I make doors?

PostPosted: Fri Oct 31, 2008 6:27 am
by He360
My game is going to be something like Super Mario Bros 2. I was wondering how do I make doors in my game to get to different places?

Thanks

Re: How do I make doors?

PostPosted: Fri Oct 31, 2008 8:37 am
by Kalladdolf
when your actor touches the door, make him change the x and y coordinates.
That's the most simple way.
You can do that by putting the script editor on the collision event.
Code: Select all
x = 344;
y = -321;  // these coordinates are just random, enter the exact x and y position, just right where you want your actor to go. Make sure the view stays with it.

Re: How do I make doors?

PostPosted: Sat Nov 01, 2008 4:10 am
by Fuzzy
In global code type the following

Code: Select all
// I make the assumption that 12 doors will be lots
double DoorX[12];
double DoorY[12];
// this will store the location of each door clone, up to number 12. It makes 2 arrays


Next, in create actor for the door, do the following

Code: Select all
DoorX[cloneindex]=x;
DoorY[cloneindex]=y;


Now each door will update its location each time you move it. You dont need to calculate or measure. You dont need to remember what numbers mean.

But this only sets its location: not where the door leads. We need an elegant way to do that too.

Go back to global code and add another line. Several actually. Put it under the other two.

Code: Select all
int DoorDest[12] = {6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 13};
// we are assuming that door zero leads to door six, door 1 leads to door 7 and that those doors lead back. Note the mysterious 13th door. It doesnt lead anywhere
// but arrays actually start counting at zero, so we should have used 11 in the arrays, But this shows the fact visually and that you can hide stuff in your game. Maybe
// door 13 is for the creator only!


Now to use the doors(again without if statements and over thinking the problem) in collision make the view parent to the player, then move the view(and it drags the player) to the door pointed to by the first doors cloneindex. I know thats complicated sounding, but its rather easy as you shall see.

Code: Select all
// in door script during collision with player.
ChangeParent("Player", "view");
view.x = DoorX[DoorDest[cloneindex]];
view.y = DoorY[DoorDest[cloneindex]];
ChangeParent("Player", "(none)"); // or whatever it was before.


of course when you move to the new door you will have a collision there and get moved again, but I will leave that up to you to solve. If you cannot fix something by yourself you have no hope! Hint: The easiest way would be to have two types of doors.

Re: How do I make doors?

PostPosted: Sun Nov 02, 2008 10:23 pm
by BlarghNRawr
make a variable called door, on keydown: up
Code: Select all
door=1;
on keyup: up
Code: Select all
door=0


then on collision with door
Code: Select all
if (door=1) moveTo (wherever the other door is)


i assume this is right if its a platform/side scroller like mario 2 is :D