blob: 96edb574576210a0390d9fd5ddea842453ff0bd3 (
plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
|
# Hurry Curry! - a game about cooking
# Copyright 2024 metamuffin
# Copyright 2024 nokoe
# Copyright 2024 tpart
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, version 3 of the License only.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
class_name ProgressBar3D
extends MeshInstance3D
const PLAY_RANDOM_SCENE = preload("res://audio/play_random.tscn")
var beep_node: PlayRandom = PLAY_RANDOM_SCENE.instantiate()
var ding_node: PlayRandom = PLAY_RANDOM_SCENE.instantiate()
var speed := 0.
var position_ := 0.
var warn := false
func _ready():
add_child(beep_node)
add_child(ding_node)
beep_node.randomize_pitch = false
beep_node.volume_db = -12
beep_node.setup([load("res://map/tiles/sounds/beep.ogg")])
ding_node.randomize_pitch = false
ding_node.volume_db = -12
ding_node.setup([load("res://map/tiles/sounds/ding.ogg")])
func update(new_position: float, new_speed: float, new_warn: bool):
speed = new_speed
position_ = new_position
warn = new_warn
var mat: ShaderMaterial = get_active_material(0)
mat.set_shader_parameter("progress", position_)
mat.set_shader_parameter("bad", warn)
# Always play ding sound if item is making progress while warn
if warn and speed > 0.: ding_node.play_random()
func _process(delta: float):
position_ += delta * speed
var time_remaining = (1 - position_) / speed
if warn and speed > 0 and time_remaining < 5.: beep_node.start_autoplay()
else: beep_node.stop_autoplay()
var mat: ShaderMaterial = get_active_material(0)
mat.set_shader_parameter("progress", position_)
|