Page 1 of 2

Tutorial: Make doors!

PostPosted: Tue Jan 18, 2011 3:31 pm
by lcl
Hello!

Here's very simple tutorial of making doors to your game.
Create actor that is the door and give it animation of door.

You will need this code to global code:
Code: Select all
//That code is for playing with clones easily
char actor[30];

Actor * GetClone(char Name[30], int num)
{
    sprintf(actor, "%s.%i", Name, num);
    return getclone(actor);
}


Create integer variable called canMove.

And then to door - collision any side of player, repeat: yes - script editor:
(The code might seem unclear because of all comments)
Code: Select all
int doornum = 1 - 2 * fmod(cloneindex, 2); //This line checks is the cloneindex of current door even or uneven and makes doornum equal to - 1 or 1 according to what fmod(); returns
Actor * next = GetClone("door", cloneindex + doornum); //Set the next door
char * key = GetKeyState(); //Get keyboard state and store it to char * key

if (key[KEY_UP] == 1 && x < player.x + 10 && x > player.x - 10 && canMove == 0) //If at doors position, KEY_UP pressed and canMove 0
{
    player.x = next->x; //Move player to next doors x
    player.y = (next->y + next->height / 2) - player.height / 2; //Move player to next doors y
    canMove = 1; //Set canMove to 1
}

if (key[KEY_UP] == 0) //If KEY_UP isn't pressed
{
    canMove = 0; //Set canMove to 0
}


In this method door 0 leads to door 1 and conversely,
door 2 to door 3 and conversely,
and etc. So, every two doors are a "pair".

Test it and see how well it works! :D

Re: Tutorial: Make doors!

PostPosted: Fri Jan 21, 2011 1:15 pm
by lcl
* UPDATED! *
Now with clearer, shorter code! :)

Re: Tutorial: Make doors!

PostPosted: Sat Jan 22, 2011 12:29 pm
by Camper1995
Great! :) Exactly what I needed :D

btw: have you finished the AI? I'm waiting for it so I can animate the bad bunny :P

Re: Tutorial: Make doors!

PostPosted: Sun Jan 23, 2011 12:23 pm
by lcl
Great you like it. :D

Oh that AI, I'm sorry, I haven't been working on it.
But now, because you mentioned it, I will keep making it. :wink:

Re: Tutorial: Make doors!

PostPosted: Sun Jan 23, 2011 7:00 pm
by Camper1995
Awesome. I started new project for iPhone because you was not online long time, but it's ok. I don't have much time now, but from 4.2. to 13.2. I have holidays so I can start doing serious thing on our Bunny project ;) And of course on my iPhone game that I want to put on the App store :P

Re: Tutorial: Make doors!

PostPosted: Sun Jan 23, 2011 9:59 pm
by lcl
:D
I have also a reason for that I weren't working on the bunny project..
My computer went "crazy" :lol: and I've been also very busy.

EDIT:
This is going too off-topic.. :P

Re: Tutorial: Make doors!

PostPosted: Sun Feb 20, 2011 7:43 am
by lcl
*UPDATED!*

- Now with demo!

Re: Tutorial: Make doors!

PostPosted: Sun Feb 20, 2011 11:59 pm
by CobraSFX
Great job lcl, this helped me a lot :D

Now im at a crossroads - i have 20 levels and 57 doors - do i make them all in the same GED file or make seperate GED's (which sound more complex as a door in one would have to open a door in another GED file), you recommend i make all 20 levels in 1 file?

Re: Tutorial: Make doors!

PostPosted: Mon Feb 21, 2011 6:09 am
by schnellboot
make all levels in seperate files and use lcl's door for each level and use a specific door that brings up the next level

Re: Tutorial: Make doors!

PostPosted: Wed Feb 23, 2011 12:35 am
by CobraSFX
Its quite a complex setup but ill go along with making them seperate, so i assume if level 1 has 3 doors they would be labelled as 1 3 and 5 (as 2, 4 and 6 would be in different GEDS etc) and GE would load them fine?

Re: Tutorial: Make doors!

PostPosted: Wed Feb 23, 2011 7:22 am
by lcl
CobraSFX wrote:Its quite a complex setup but ill go along with making them seperate, so i assume if level 1 has 3 doors they would be labelled as 1 3 and 5 (as 2, 4 and 6 would be in different GEDS etc) and GE would load them fine?

No, that won't work.
You see that door pairs are 0 and 1, 2 and 3, 4 and 5, etc.
And cloneindexes change in different geds. You should use activation regions instead of separate game files. :D

Re: Tutorial: Make doors!

PostPosted: Wed Feb 23, 2011 7:54 am
by CobraSFX
Yah i was thinking all in one due to the nature of how the doors work, activation regions ill read up on now :D

Re: Tutorial: Make doors!

PostPosted: Wed Feb 23, 2011 9:36 am
by lcl
CobraSFX wrote:Yah i was thinking all in one due to the nature of how the doors work, activation regions ill read up on now :D

When you use activation regions, you have to do this: (I learnt all this by mistakes xD)

1. You have to split your large tile actors (ground, scenery) into clones, one for each region.
It is easier to do if you always clone one more than you need and this one contains always only one tile. Then you don't have to remove tiles from new clone for new region.

2. If your game is continuous (one big world), you have to place the regions so that they are one on top of another at their sides.

I wish you understood what I meant, it's pretty hard to explain. I can send pics of what I mean if it clears this for you. :D

Re: Tutorial: Make doors!

PostPosted: Wed Feb 23, 2011 10:54 am
by Game A Gogo
Just create another kind of door that could teleport you in another ged by saving a variable, which could the from what level and from what door the player came from, then you just check those conditions and have it teleport to the door that corresponds (note: a switch() will be usefull here)

Re: Tutorial: Make doors!

PostPosted: Wed Feb 23, 2011 2:27 pm
by CobraSFX
Thanks for the help and advice guys - it is one continuous world where the player can go to any room regardless of it having been completed as they will need to use certain doors to get to certain areas, it might help if i show a pic of what im re-creating .....

Introducing Booty, an old 8 bit platform game ...

ftp://ftp.worldofspectrum.org/pub/sincl ... /Booty.jpg

And a screenie of my WIP ...

http://www.mods-r-us.net/datas/users/2/booty_2.jpg

So now you know where im coming from you will have a better idea how it should be made :D

Please advise.