How do I make doors?

Game Editor comments and discussion.

How do I make doors?

Postby He360 » Fri Oct 31, 2008 6:27 am

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
Sometimes you don't need a goal in life.
He360
 
Posts: 22
Joined: Sun Apr 06, 2008 2:21 pm
Score: 0 Give a positive score

Re: How do I make doors?

Postby Kalladdolf » Fri Oct 31, 2008 8:37 am

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.
User avatar
Kalladdolf
 
Posts: 2427
Joined: Sat Sep 08, 2007 8:22 am
Location: Germany
Score: 120 Give a positive score

Re: How do I make doors?

Postby Fuzzy » Sat Nov 01, 2008 4:10 am

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.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Re: How do I make doors?

Postby BlarghNRawr » Sun Nov 02, 2008 10:23 pm

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
Download Game Music
current projects:
Bold! ?% Started mechanics
Unnamed puzzle game 60% --i need a name!--
User avatar
BlarghNRawr
 
Posts: 767
Joined: Wed Jun 25, 2008 12:36 am
Location: Not using G-E anymore. Now using Source SDK.
Score: 27 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron