How to make an character die and return ?

Non-platform specific questions.

How to make an character die and return ?

Postby tris » Fri Jun 15, 2012 5:08 pm

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 ?
tris
 
Posts: 8
Joined: Thu Jun 14, 2012 2:10 pm
Score: 0 Give a positive score

Re: How to make an character die and return ?

Postby skydereign » Fri Jun 15, 2012 5:14 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: How to make an character die and return ?

Postby tris » Fri Jun 15, 2012 5:20 pm

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 ?
tris
 
Posts: 8
Joined: Thu Jun 14, 2012 2:10 pm
Score: 0 Give a positive score

Re: How to make an character die and return ?

Postby skydereign » Fri Jun 15, 2012 5:55 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: How to make an character die and return ?

Postby happyjustbecause » Fri Jun 15, 2012 6:06 pm

Here is a checkpoint tutorial that helped me, maybe it can help you:

viewtopic.php?f=27&t=8744
For small creatures such as we the vastness is bearable only through love.
-Carl Sagan

Night Knight Development Thread
User avatar
happyjustbecause
 
Posts: 267
Joined: Tue Jul 26, 2011 3:10 pm
Location: Frazier Park, Ca
Score: 15 Give a positive score

Re: How to make an character die and return ?

Postby tris » Sat Jun 16, 2012 10:22 am

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 ?
tris
 
Posts: 8
Joined: Thu Jun 14, 2012 2:10 pm
Score: 0 Give a positive score

Re: How to make an character die and return ?

Postby lcl » Sat Jun 16, 2012 11:25 am

Just create the timer to an actor that always exists, like view :)
And, of course move the timer event to view, too.
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: How to make an character die and return ?

Postby tris » Sat Jun 16, 2012 12:47 pm

omg, i move the timer event to view and when player die, it creates many players :shock: i don't know why :(
tris
 
Posts: 8
Joined: Thu Jun 14, 2012 2:10 pm
Score: 0 Give a positive score

Re: How to make an character die and return ?

Postby skydereign » Sat Jun 16, 2012 5:18 pm

That is probably because you set the timer to repeat. Disable that, and it should work.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: How to make an character die and return ?

Postby tris » Sat Jun 16, 2012 5:33 pm

arrrrrrrr what a small mistake that i didn't notice :lol: thank you so much
tris
 
Posts: 8
Joined: Thu Jun 14, 2012 2:10 pm
Score: 0 Give a positive score

Re: How to make an character die and return ?

Postby tris » Sun Jun 17, 2012 2:49 pm

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 ?
tris
 
Posts: 8
Joined: Thu Jun 14, 2012 2:10 pm
Score: 0 Give a positive score

Re: How to make an character die and return ?

Postby skydereign » Sun Jun 17, 2012 5:34 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: How to make an character die and return ?

Postby tris » Mon Jun 18, 2012 12:37 pm

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.
tris
 
Posts: 8
Joined: Thu Jun 14, 2012 2:10 pm
Score: 0 Give a positive score

Re: How to make an character die and return ?

Postby skydereign » Mon Jun 18, 2012 5:05 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: How to make an character die and return ?

Postby tris » Wed Aug 29, 2012 1:15 pm

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 ?
tris
 
Posts: 8
Joined: Thu Jun 14, 2012 2:10 pm
Score: 0 Give a positive score

Next

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron