# 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 . # 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_)