this post was submitted on 28 Mar 2024
611 points (98.1% liked)

Programmer Humor

32568 readers
153 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] cookie_sabotage 160 points 8 months ago (18 children)
public class GameManager : MonoBehaviour
{
    public bool EnableHighContrast;
    public bool PlayerWon;
    public float PlayerUnitsMoved;
    public int PlayerDeathCount;
    public float PlayerHealth;

    public void PlayerTakeDamage(float damage)
    {
        PlayerHealth -= damage;
        if (PlayerHealth < 0)
        {
            PlayerDieAndRespawn();
        }
    }

    public void PlayerDieAndRespawn()
    {
        return;
    }
}

I couldn't contain myself.

[–] [email protected] 57 points 8 months ago (10 children)

Should it be

PlayerHealth <= 0

?

Otherwise the player could have 0 health and not die? I’m sleep deprived so forgive me if I’m wrong

[–] Randomocity -4 points 8 months ago

This won't work if you can ever take more than 1 damage. If you were at 1 and received 2 damage you would become invincible. You'd want to do less than or equal to.

load more comments (9 replies)
load more comments (16 replies)