Tutorial: Make doors!

Learn how to make certain types of games and use gameEditor.

Tutorial: Make doors!

Postby lcl » Tue Jan 18, 2011 3:31 pm

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
Attachments
Door demo.zip
Demo of using the code!
(22.14 KiB) Downloaded 1019 times
door.png
door.png (7.43 KiB) Viewed 18092 times
Last edited by lcl on Sun Feb 20, 2011 7:42 am, edited 4 times in total.
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Tutorial: Make doors!

Postby lcl » Fri Jan 21, 2011 1:15 pm

* UPDATED! *
Now with clearer, shorter code! :)
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Tutorial: Make doors!

Postby Camper1995 » Sat Jan 22, 2011 12:29 pm

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
Say hello to my little friend.
User avatar
Camper1995
 
Posts: 707
Joined: Tue Dec 30, 2008 7:20 pm
Location: Lost in the past.
Score: 44 Give a positive score

Re: Tutorial: Make doors!

Postby lcl » Sun Jan 23, 2011 12:23 pm

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:
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Tutorial: Make doors!

Postby Camper1995 » Sun Jan 23, 2011 7:00 pm

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
Say hello to my little friend.
User avatar
Camper1995
 
Posts: 707
Joined: Tue Dec 30, 2008 7:20 pm
Location: Lost in the past.
Score: 44 Give a positive score

Re: Tutorial: Make doors!

Postby lcl » Sun Jan 23, 2011 9:59 pm

: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
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Tutorial: Make doors!

Postby lcl » Sun Feb 20, 2011 7:43 am

*UPDATED!*

- Now with demo!
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Tutorial: Make doors!

Postby CobraSFX » Sun Feb 20, 2011 11:59 pm

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?
CobraSFX
 
Posts: 13
Joined: Sat Feb 12, 2011 2:50 am
Location: UK
Score: 0 Give a positive score

Re: Tutorial: Make doors!

Postby schnellboot » Mon Feb 21, 2011 6:09 am

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
schnellboot
 
Posts: 819
Joined: Sat Mar 31, 2007 1:35 pm
Location: Germany
Score: 102 Give a positive score

Re: Tutorial: Make doors!

Postby CobraSFX » Wed Feb 23, 2011 12:35 am

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?
CobraSFX
 
Posts: 13
Joined: Sat Feb 12, 2011 2:50 am
Location: UK
Score: 0 Give a positive score

Re: Tutorial: Make doors!

Postby lcl » Wed Feb 23, 2011 7:22 am

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
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Tutorial: Make doors!

Postby CobraSFX » Wed Feb 23, 2011 7:54 am

Yah i was thinking all in one due to the nature of how the doors work, activation regions ill read up on now :D
CobraSFX
 
Posts: 13
Joined: Sat Feb 12, 2011 2:50 am
Location: UK
Score: 0 Give a positive score

Re: Tutorial: Make doors!

Postby lcl » Wed Feb 23, 2011 9:36 am

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
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Tutorial: Make doors!

Postby Game A Gogo » Wed Feb 23, 2011 10:54 am

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)
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: Tutorial: Make doors!

Postby CobraSFX » Wed Feb 23, 2011 2:27 pm

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.
CobraSFX
 
Posts: 13
Joined: Sat Feb 12, 2011 2:50 am
Location: UK
Score: 0 Give a positive score

Next

Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest

cron