Add Pill singleton with basic behavior
A pill can be taken (key 'E', currently in Player.gd for testing) to increase the level up to the max level (currently 6). The drugged level gradually decreases down to the min level (currently 0).
This commit is contained in:
parent
603e21b6fe
commit
ff1d85a325
@ -58,6 +58,13 @@ func process_input():
|
|||||||
# sprinting
|
# sprinting
|
||||||
_is_sprinting = Input.is_action_pressed("move_sprint")
|
_is_sprinting = Input.is_action_pressed("move_sprint")
|
||||||
|
|
||||||
|
# Taking a pill
|
||||||
|
# TODO: Should be moved to a different component which only handles pills - this script should only do movement
|
||||||
|
# Only here for testing purposes!
|
||||||
|
if Input.is_action_just_pressed("take_pill"):
|
||||||
|
Pills.take_pill()
|
||||||
|
Logger.info("Player took a pill; new level: %s" % [Pills.get_round_level()])
|
||||||
|
|
||||||
|
|
||||||
func process_movement(delta):
|
func process_movement(delta):
|
||||||
_vel.y += delta * GRAVITY
|
_vel.y += delta * GRAVITY
|
||||||
|
37
Global/Pills.gd
Normal file
37
Global/Pills.gd
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
extends Node
|
||||||
|
|
||||||
|
|
||||||
|
var _level: float setget _set_level, get_level
|
||||||
|
var _min: float = 0.0
|
||||||
|
var _max: float = 6.0
|
||||||
|
var _decrease_per_second: float = 0.2
|
||||||
|
var _pill_add_amount: float = 2.0
|
||||||
|
|
||||||
|
|
||||||
|
# Returns the exact current level as a floating point number between min and max
|
||||||
|
func get_level():
|
||||||
|
return _level
|
||||||
|
|
||||||
|
|
||||||
|
# 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)
|
@ -69,6 +69,7 @@ config/icon="res://icon.png"
|
|||||||
[autoload]
|
[autoload]
|
||||||
|
|
||||||
Logger="*res://Util/gs-logger-3.1-R3/gs_logger/logger.gd"
|
Logger="*res://Util/gs-logger-3.1-R3/gs_logger/logger.gd"
|
||||||
|
Pills="*res://Global/Pills.gd"
|
||||||
|
|
||||||
[input]
|
[input]
|
||||||
|
|
||||||
@ -106,6 +107,11 @@ move_sprint={
|
|||||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777237,"unicode":0,"echo":false,"script":null)
|
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777237,"unicode":0,"echo":false,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
take_pill={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":69,"unicode":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
[layer_names]
|
[layer_names]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user