Page 1 of 2

How to make an character die and return ?

PostPosted: Fri Jun 15, 2012 5:08 pm
by tris
As the title, i wonder how to do it, i suppose to creat an variable for player's life, if it > 0, player can return to save point, if it = 0 then game over, but dont know how to make it, can anyone show me clearly ?

Re: How to make an character die and return ?

PostPosted: Fri Jun 15, 2012 5:14 pm
by skydereign
As you said, you use a variable to hold the number of lives the player has. When the player dies, you reduce life by 1, then if life is zero, game over, else return the player to the starting point. If you know how to use variables (if statements and changing their value) you should be able to turn the italicized statement into code. If you don't though, just ask and I can explain it.

Re: How to make an character die and return ?

PostPosted: Fri Jun 15, 2012 5:20 pm
by tris
i can understand the idea, but still dont know to turn it into code :( create a variable and reduce it by 1 when player die is ok, i can do it, my problem is to return the player to the nearest save point, can u explain it ?

Re: How to make an character die and return ?

PostPosted: Fri Jun 15, 2012 5:55 pm
by skydereign
If by nearest save point you mean last touched checkpoint, then you would need to store the coordinates of the checkpoint (two variables, I would call them check_x and check_y). When the player collides with a checkpoint actor you set check_x and check_y equal to the checkpoint actor's x and y. That way, you can create the player at the last checkpoint (inside the player's destroy actor event). The CreateActor function has two parameters to specify where you want to create the actor, so pass it check_x and check_y and it should respawn the player in the right place. Two things to note, make sure the CreateActor is not set to create it relative to the event actor (the end of the CreateActor function should say true) and you'll probably need to move the view to be around the player again.
Code: Select all
view.x=player.x-view.width/2;
view.y=player.y-view.height/2;

You may run into one or two problems depending on how you are doing view movement.

Re: How to make an character die and return ?

PostPosted: Fri Jun 15, 2012 6:06 pm
by happyjustbecause
Here is a checkpoint tutorial that helped me, maybe it can help you:

viewtopic.php?f=27&t=8744

Re: How to make an character die and return ?

PostPosted: Sat Jun 16, 2012 10:22 am
by tris
Hello guys, after reading the tutorial and your explaination, i still have 1 problem (doing follow the tutorial is OK) because i want the player return after his death 3 seconds, i do like that :
Player -> Collision -> Anyside of Checkpoint -> Script Editor :
Code: Select all
checkx=x;
checky=y;


Player -> Collision -> Left or Right side of Monster -> Destroy actor -> Event actor

Player -> Destroy actor -> Script Editor :
Code: Select all
CreateTimer("Event Actor", "return", 3000);


Player -> Timer -> "return" -> Scrip Editor:
Code: Select all
CreateActor("player", "r_stand", "(none)", "(none)", checkx, checky, true);


It doesn't work, i think because the "return" timer exist if the player exist, when the player is destroyed, "return" doesn't exsit anymore, is it right ?
Can you help me to fix it ?

Re: How to make an character die and return ?

PostPosted: Sat Jun 16, 2012 11:25 am
by lcl
Just create the timer to an actor that always exists, like view :)
And, of course move the timer event to view, too.

Re: How to make an character die and return ?

PostPosted: Sat Jun 16, 2012 12:47 pm
by tris
omg, i move the timer event to view and when player die, it creates many players :shock: i don't know why :(

Re: How to make an character die and return ?

PostPosted: Sat Jun 16, 2012 5:18 pm
by skydereign
That is probably because you set the timer to repeat. Disable that, and it should work.

Re: How to make an character die and return ?

PostPosted: Sat Jun 16, 2012 5:33 pm
by tris
arrrrrrrr what a small mistake that i didn't notice :lol: thank you so much

Re: How to make an character die and return ?

PostPosted: Sun Jun 17, 2012 2:49 pm
by tris
Hello guys, im having some troubles about making health and exp bar, i just know to make it as numbers, like 250/1000 .... Can you show me the idea so that i can put it into code ?

Re: How to make an character die and return ?

PostPosted: Sun Jun 17, 2012 5:34 pm
by skydereign
This isn't the best resource but it gets the general idea of how hp bars work.
http://game-editor.com/HP_Bar
If you search the forums, plenty of users have asked this question before. The major thing to note is the hp bar is an animated actor. There is a variable called nframes that holds the total number of frames in the current animation. Multiplying that by the percent of hp you have (hp/maxhp) will set the animation to the right frame. Make sure to change the animation direction to stopped.

Re: How to make an character die and return ?

PostPosted: Mon Jun 18, 2012 12:37 pm
by tris
I learned in some demo games from forum, they use some ways to create hp bar which is easier than the explaination in the tutorial :D now i can do it :D
Btw, can you show me the differences between "forward", "backward", "no_change" and "stopped" in the animation direction ? Because i tried in state method, it doesn't affect player's movement when i change these directions.

Re: How to make an character die and return ?

PostPosted: Mon Jun 18, 2012 5:05 pm
by skydereign
tris wrote:I learned in some demo games from forum, they use some ways to create hp bar which is easier than the explaination in the tutorial

This is why you should search the forums when you have problems. Almost all simple questions have been answered somewhere on the forums.

tris wrote:Btw, can you show me the differences between "forward", "backward", "no_change" and "stopped" in the animation direction ?

These are not the player movement. They are the animation movement. FORWARD means the animation will move forward, BACKWARD means it plays in reverse. NO_CHANGE means it will keep the same state as the previous animation had, and STOPPED means the animation won't play. Movement is controlled by changing the player's xy variables or the velocity variables.

Re: How to make an character die and return ?

PostPosted: Wed Aug 29, 2012 1:15 pm
by tris
Hello, i need some help about 1 problem, that is when i add keydown event for player to do something, i must hold the button until the animation finish, unless it will stop the animation immediately, how can i fix this ?