java - Regenerating system in my game not working as intended -


i programming simple 3d java game in free time, , implementing health system, 5 hearts, , when, instance, swim in lava lose 1 heart every 0.4 seconds, when out of lava should regenerate 1 heart every 2 seconds, not working intended. losing of health works, step out of lava stay @ amount of hearts have left , won't regenerate any.

here relevant piece of code problem:

public void updatehealthbar(player player, screen screen) {     if(player.isswimminginlava) {         player.isgettingdamage = true;         if(system.currenttimemillis() >= lasttime) {             lasttime = system.currenttimemillis() + 400;             this.playerhealth--;         } else {             player.isgettingdamage = false;         }     }     if(!(player.isswimminginlava) && !(this.playerhealth < 5) && system.currenttimemillis() >= lasttime) {         lasttime = system.currenttimemillis() + 2000;         this.playerhealth++;     } } 

i think part !(this.playerhealth < 5) of last if condition should not negated.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -