Tutorial: Make doors!
Posted: 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:
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)
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!
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!