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
Post a Comment