Jump to content

Player lives and restarting game


Randomfraff
 Share

Recommended Posts

Hi,

I was wondering how you implemented lives into a game and have the game restart upon player death. I've tried having a look on the forums and the guide docs but can't seem to find anything, also tried tinkering with the FPSPlayer script but with no luck :P. Any guidance would be appreciated.

Link to comment
Share on other sites

hi its not that hard but you need some coding skills to implement that.

 

you ask how so i think you mean the logic:

 

 

 

the player object needs

 

vars: healthpoints and lifes (Integer)

 

functions: hit($input)

 

hit($input) decreases the player HP

 

e.g.

currentHP = 100

 

 

hit(80) -> return currentHP - 80

 

 

 

check also if your HP is <= 0 if yes you need a

 

dead() function. the deadfunction just decrement your life integer var.

 

 

if life = 0 -> do some gameover stuff

 

 

 

 

 

BTW:

 

forget about that player script. create a new game and do everything by yourself and read the documentation. if you have mainly problems with programming read some c++/lua tuts or see the tutorial thread (from Rick).

 

 

you also dont will find some functions in guides or in the code reference for doing such trivial stuff. take a look into the command reference and also the script reference for your script stuff.

 

also take a look into the object script guide

It doesn´t work... why? mhmmm It works... why?

Link to comment
Share on other sites

In c++ the main character death and end of game is easy to do.

before man loop you can declare

bool player_alive = true.

 

Then at top of main loop

 

while (player_alive)

 

or

if(player_alive)

 

Then when you want to kill player

 

player_alive = false

amd quad core 4 ghz / geforce 660 ti 2gb / win 10

Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++

Link to comment
Share on other sites

As for lives you could store the number of lives as an integer

ex: player.lives=5

and everytime your player dies you can subtract a life.

if player.alive~=true then

player.lives=player.lives-1

if player.lives<1 then

game over

else

player.alive=true

end

Edited by Haydenmango

Check out my game Rogue Snowboarding- 

https://haydenmango.itch.io/roguesnowboarding

Link to comment
Share on other sites

Thanks for all the suggestions and advice! I'm very new to coding and think I'll take your advice and try and do it all from scratch. I'm sure I'll learn a lot that way, although I'm also pretty sure that'll result in a fair few silly questions posted by yours truly on the forums tongue.png. I'll have a look at the lua tuts as I have the indie version so the lua stuff will probably be the most relevant for me right now.

 

All the code examples are really useful! Thanks for taking the time to write these out, they really help show how to phrase concepts as code and the type of logic used. I was wondering though how I'd restart a function? So for example, when the player is dead instead of the game ending I'd want the game to restart from the beginning again with the player back at the start.

 

Thanks again for all the help biggrin.png.

Link to comment
Share on other sites

Resarting the game after the player dies would involve re-setting all the values to their original state. Any dead enemies would have to come back to life etc...

amd quad core 4 ghz / geforce 660 ti 2gb / win 10

Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++

Link to comment
Share on other sites

Ah! Thanks! So that's how I would do it, I think for now reloading the map will be fine (as the game is very simple at this point I don't think loading times will be too bad). But its good to know how I could go about it in future when map loads will be taking longer as the game is getting bigger.

 

Thanks again all of you for all the help! I'm sure I'll be back soon enough to pester you guys with more questions tongue.png.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...