hp

package
v0.0.0-...-5198b88 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2023 License: MPL-2.0 Imports: 2 Imported by: 0

Documentation

Overview

hp is a package that provides a health point system with a maximum and current value.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compute

func Compute(level, base, constitution int) int

Compute returns the computed Max value based on the given level and base value. 8 + 4 by level + bonus point for every 3 constitution point above 10 every level.

Types

type HP

type HP struct {
	Max      *pts.Point
	Current  *pts.Point
	Previous *pts.Point
}

HP represents a health point system with a maximum and current value.

func New

func New(max int) *HP

New returns a new HP struct with the given max and current values.

func (*HP) BeetwenPercent

func (hp *HP) BeetwenPercent(percent float64) bool

BeetwenPercent returns true if the current HP and previous HP are between the given percentages.

func (*HP) Compute

func (hp *HP) Compute(level, base, constitution int)

Compute returns the computed Max value based on the given level and base value.

func (*HP) Copy

func (hp *HP) Copy() HP

Copy creates a new HP with copies of Max, Current, and Previous points.

func (*HP) Damage

func (hp *HP) Damage(amount int)

Damage subtracts the given amount from the current HP and caps it at 0.

func (*HP) Heal

func (hp *HP) Heal(amount int)

Heal adds the given amount to the current HP and caps it at the maximum HP.

func (*HP) IsAlive

func (hp *HP) IsAlive() bool

IsAlive returns true if the current HP is greater than 0.

func (*HP) IsDead

func (hp *HP) IsDead() bool

IsDead returns true if the current HP is less than or equal to 0.

func (*HP) Percent

func (hp *HP) Percent() float64

Percent returns the current HP as a percentage of the maximum HP.

func (*HP) PercentString

func (hp *HP) PercentString() string

PercentString returns the current HP as a percentage string.

func (*HP) Reset

func (hp *HP) Reset()

Reset sets the current HP to the maximum HP.

func (*HP) Set

func (hp *HP) Set(amount int)

Set sets the maximum and current HP to the given amount.

func (*HP) String

func (hp *HP) String() string

String returns the current and maximum HP as a string.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL