57 lines
1.1 KiB
GDScript
57 lines
1.1 KiB
GDScript
extends Node
|
|
|
|
|
|
var _level: float setget _set_level, get_level
|
|
var _min: float = 1.0
|
|
var _max: float = 7.0
|
|
var _decrease_per_second: float = 0.2
|
|
var _pill_add_amount: float = 2.0
|
|
|
|
enum LEVELS {
|
|
SOBRE = 0,
|
|
VERY_LOW = 1,
|
|
LOW = 2,
|
|
MEDIUM = 3,
|
|
HIGH = 4,
|
|
VERY_HIGH = 5,
|
|
FULL = 6
|
|
}
|
|
|
|
|
|
# Returns the max level
|
|
func get_max() -> float:
|
|
return _max
|
|
|
|
|
|
# Returns the exact current level as a floating point number between min and max
|
|
func get_level() -> float:
|
|
return _level
|
|
|
|
|
|
# Returns the currenct level as a floating point number between 0 and 1
|
|
func get_normalized_level() -> float:
|
|
return _level / _max
|
|
|
|
|
|
# Returns the rounded level, e.g. for behavior which changes stepwise (X at level 6, Y at level 5, ...)
|
|
func get_round_level():
|
|
return ceil(get_level())
|
|
|
|
|
|
func _set_level(new_level: float):
|
|
# Make sure the level stays between min and max
|
|
_level = clamp(new_level, _min, _max)
|
|
|
|
|
|
func _ready() -> void:
|
|
# Start with the maximum druggedness
|
|
_set_level(_max)
|
|
|
|
|
|
func _process(delta: float) -> void:
|
|
# Gradually decrease the level by the decrease per second
|
|
_set_level(_level - _decrease_per_second * delta)
|
|
|
|
|
|
func take_pill():
|
|
_set_level(_level + _pill_add_amount) |