Randomfraff Posted April 8, 2014 Share Posted April 8, 2014 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 . Any guidance would be appreciated. Quote Link to comment Share on other sites More sharing options...
DudeAwesome Posted April 8, 2014 Share Posted April 8, 2014 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 Quote It doesn´t work... why? mhmmm It works... why? Link to comment Share on other sites More sharing options...
cassius Posted April 8, 2014 Share Posted April 8, 2014 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 Quote 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 More sharing options...
Haydenmango Posted April 8, 2014 Share Posted April 8, 2014 (edited) 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 April 8, 2014 by Haydenmango Quote Check out my game Rogue Snowboarding- https://haydenmango.itch.io/roguesnowboarding Link to comment Share on other sites More sharing options...
Randomfraff Posted April 9, 2014 Author Share Posted April 9, 2014 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 . 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 . Quote Link to comment Share on other sites More sharing options...
cassius Posted April 9, 2014 Share Posted April 9, 2014 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... Quote 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 More sharing options...
beo6 Posted April 10, 2014 Share Posted April 10, 2014 Or you reload the map file after you died if you don't care about loading times. Might be easier at the start and you don't need to keep track of every entity in the map. Quote Link to comment Share on other sites More sharing options...
Randomfraff Posted April 11, 2014 Author Share Posted April 11, 2014 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 . Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.