-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpheromone_bar.gd
50 lines (39 loc) · 1.5 KB
/
pheromone_bar.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
extends Control
@export var pheromone_available: float = 100.0
@export var depletion_speed: float = 3.0
@export var regeneration_speed: float = 3.0
@onready var progress_bar = $ProgressBar
@onready var game = get_node("/root/Game")
func _ready() -> void:
scale = Vector2.ZERO
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
if get_tree().paused:
return
var t = progress_bar.value / progress_bar.max_value
var color = lerp(Color.GRAY, Color.GREEN, t)
progress_bar.modulate = color
progress_bar.value = pheromone_available
pheromone_available = min(100.0, pheromone_available + delta * regeneration_speed)
# if not game.is_drawing:
# hide()
func deplete(amount: float) -> void:
# We want to allow negative values here because we don't check the amount before
# allowing a depletion, so if we clamp it, we're giving the user free pheromones.
pheromone_available -= amount * depletion_speed
func add(amount: float) -> void:
pheromone_available = min(100.0, pheromone_available + amount)
func _input(event: InputEvent) -> void:
if event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_LEFT:
var tween = create_tween().set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_CUBIC)
if event.pressed:
tween.tween_property(self, "scale", Vector2.ONE, 0.1)
else:
tween.tween_property(self, "scale", Vector2.ZERO, 0.1)
if game.is_drawing:
# show()
if event is InputEventMouseMotion:
position = event.position
else:
pass