add sound effects and make clicks time based
This commit is contained in:
parent
7518e6873c
commit
01596be02c
3
assets/sound/click.wav
Normal file
3
assets/sound/click.wav
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:373cde6b402bd106fea9260b833a429e496caaf500d3b7186bed2fd36b0c6b01
|
||||||
|
size 17452
|
24
assets/sound/click.wav.import
Normal file
24
assets/sound/click.wav.import
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="wav"
|
||||||
|
type="AudioStreamWAV"
|
||||||
|
uid="uid://k1xeit7qyqlq"
|
||||||
|
path="res://.godot/imported/click.wav-e8a30ec71317fecc836e787d9d63b4a3.sample"
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/sound/click.wav"
|
||||||
|
dest_files=["res://.godot/imported/click.wav-e8a30ec71317fecc836e787d9d63b4a3.sample"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
force/8_bit=false
|
||||||
|
force/mono=false
|
||||||
|
force/max_rate=false
|
||||||
|
force/max_rate_hz=44100
|
||||||
|
edit/trim=false
|
||||||
|
edit/normalize=false
|
||||||
|
edit/loop_mode=0
|
||||||
|
edit/loop_begin=0
|
||||||
|
edit/loop_end=-1
|
||||||
|
compress/mode=0
|
3
assets/sound/spawn.wav
Normal file
3
assets/sound/spawn.wav
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:4dbe8aa4dcfb16741a9439283d0ceeeb83b7153c26f8cab421d381676b8e51b5
|
||||||
|
size 38780
|
24
assets/sound/spawn.wav.import
Normal file
24
assets/sound/spawn.wav.import
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="wav"
|
||||||
|
type="AudioStreamWAV"
|
||||||
|
uid="uid://ducbejs36cuim"
|
||||||
|
path="res://.godot/imported/spawn.wav-144efb9acab2ae0dd785e23bcaa07433.sample"
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/sound/spawn.wav"
|
||||||
|
dest_files=["res://.godot/imported/spawn.wav-144efb9acab2ae0dd785e23bcaa07433.sample"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
force/8_bit=false
|
||||||
|
force/mono=false
|
||||||
|
force/max_rate=false
|
||||||
|
force/max_rate_hz=44100
|
||||||
|
edit/trim=false
|
||||||
|
edit/normalize=false
|
||||||
|
edit/loop_mode=0
|
||||||
|
edit/loop_begin=0
|
||||||
|
edit/loop_end=-1
|
||||||
|
compress/mode=0
|
|
@ -2,6 +2,7 @@ extends Node3D
|
||||||
|
|
||||||
@onready var _controller := XRHelpers.get_xr_controller(self)
|
@onready var _controller := XRHelpers.get_xr_controller(self)
|
||||||
@export var ray: RayCast3D
|
@export var ray: RayCast3D
|
||||||
|
@export var timespan_click = 200.0
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready():
|
func _ready():
|
||||||
|
@ -11,6 +12,7 @@ func _ready():
|
||||||
var _last_collided: Object = null
|
var _last_collided: Object = null
|
||||||
var _is_pressed := false
|
var _is_pressed := false
|
||||||
var _is_grabbed := false
|
var _is_grabbed := false
|
||||||
|
var _time_pressed := 0.0
|
||||||
var _moved := false
|
var _moved := false
|
||||||
var _click_point := Vector3.ZERO
|
var _click_point := Vector3.ZERO
|
||||||
|
|
||||||
|
@ -19,18 +21,17 @@ func _physics_process(delta):
|
||||||
_handle_move()
|
_handle_move()
|
||||||
|
|
||||||
func _handle_move():
|
func _handle_move():
|
||||||
if _is_pressed == false && _is_grabbed == false:
|
var time_passed = Time.get_ticks_msec() - _time_pressed
|
||||||
|
if time_passed <= timespan_click || (_is_pressed == false && _is_grabbed == false):
|
||||||
return
|
return
|
||||||
|
|
||||||
var distance = ray.get_collision_point().distance_to(_click_point)
|
_moved = true
|
||||||
|
|
||||||
if _moved || distance > 0.02:
|
|
||||||
if _is_pressed:
|
if _is_pressed:
|
||||||
_call_fn(_last_collided, "_on_press_move")
|
_call_fn(_last_collided, "_on_press_move")
|
||||||
_moved = true
|
|
||||||
if _is_grabbed:
|
if _is_grabbed:
|
||||||
_call_fn(_last_collided, "_on_grab_move")
|
_call_fn(_last_collided, "_on_grab_move")
|
||||||
_moved = true
|
|
||||||
|
|
||||||
func _handle_enter_leave():
|
func _handle_enter_leave():
|
||||||
var collider = ray.get_collider()
|
var collider = ray.get_collider()
|
||||||
|
@ -52,6 +53,7 @@ func _on_button_pressed(button):
|
||||||
match button:
|
match button:
|
||||||
"trigger_click":
|
"trigger_click":
|
||||||
_is_pressed = true
|
_is_pressed = true
|
||||||
|
_time_pressed = Time.get_ticks_msec()
|
||||||
_click_point = ray.get_collision_point()
|
_click_point = ray.get_collision_point()
|
||||||
_call_fn(collider, "_on_press_down")
|
_call_fn(collider, "_on_press_down")
|
||||||
"grip_click":
|
"grip_click":
|
||||||
|
|
|
@ -21,6 +21,7 @@ var active: bool = false :
|
||||||
return active
|
return active
|
||||||
|
|
||||||
@onready var animation_player: AnimationPlayer = $AnimationPlayer
|
@onready var animation_player: AnimationPlayer = $AnimationPlayer
|
||||||
|
@onready var click_sound: AudioStreamPlayer = $ClickSound
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
if initial_active:
|
if initial_active:
|
||||||
|
@ -34,6 +35,7 @@ func _on_click(_event):
|
||||||
return
|
return
|
||||||
|
|
||||||
active = !active
|
active = !active
|
||||||
|
AudioPlayer.play_effect("click")
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"active": active
|
"active": active
|
||||||
|
@ -46,6 +48,7 @@ func _on_press_down(_event):
|
||||||
if toggleable:
|
if toggleable:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
AudioPlayer.play_effect("click")
|
||||||
animation_player.play("down")
|
animation_player.play("down")
|
||||||
|
|
||||||
func _on_press_up(_event):
|
func _on_press_up(_event):
|
||||||
|
|
|
@ -121,11 +121,13 @@ func _on_entity_click(entity_name):
|
||||||
if entity_name == "#back":
|
if entity_name == "#back":
|
||||||
selected_device = null
|
selected_device = null
|
||||||
page = last_device_page
|
page = last_device_page
|
||||||
|
AudioPlayer.play_effect("click")
|
||||||
render()
|
render()
|
||||||
return
|
return
|
||||||
|
|
||||||
var type = entity_name.split(".")[0]
|
var type = entity_name.split(".")[0]
|
||||||
print(type)
|
print(type)
|
||||||
|
AudioPlayer.play_effect("spawn")
|
||||||
|
|
||||||
if type == "switch":
|
if type == "switch":
|
||||||
var switch = Switch.instantiate()
|
var switch = Switch.instantiate()
|
||||||
|
|
|
@ -39,12 +39,17 @@ func _ready():
|
||||||
)
|
)
|
||||||
|
|
||||||
func generate_mesh():
|
func generate_mesh():
|
||||||
|
var corner_count = wall_corners.get_child_count()
|
||||||
|
|
||||||
|
if corner_count < 3:
|
||||||
|
return
|
||||||
|
|
||||||
var st = SurfaceTool.new()
|
var st = SurfaceTool.new()
|
||||||
var wall_up = Vector3.UP * 3
|
var wall_up = Vector3.UP * 3
|
||||||
|
|
||||||
st.begin(Mesh.PRIMITIVE_TRIANGLE_STRIP)
|
st.begin(Mesh.PRIMITIVE_TRIANGLE_STRIP)
|
||||||
|
|
||||||
for i in range(wall_corners.get_child_count()):
|
for i in range(corner_count):
|
||||||
var corner = get_corner(i)
|
var corner = get_corner(i)
|
||||||
|
|
||||||
print(corner.position, " ", corner.position + wall_up)
|
print(corner.position, " ", corner.position + wall_up)
|
||||||
|
|
15
lib/globals/audio_player.gd
Normal file
15
lib/globals/audio_player.gd
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
extends AudioStreamPlayer
|
||||||
|
|
||||||
|
var click_sound = preload("res://assets/sound/click.wav")
|
||||||
|
var spawn_sound = preload("res://assets/sound/spawn.wav")
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
volume_db = -18
|
||||||
|
|
||||||
|
func play_effect(sound):
|
||||||
|
if sound == "click":
|
||||||
|
stream = click_sound
|
||||||
|
elif sound == "spawn":
|
||||||
|
stream = spawn_sound
|
||||||
|
|
||||||
|
play()
|
|
@ -20,6 +20,7 @@ config/icon="res://assets/logo.png"
|
||||||
XRToolsUserSettings="*res://addons/godot-xr-tools/user_settings/user_settings.gd"
|
XRToolsUserSettings="*res://addons/godot-xr-tools/user_settings/user_settings.gd"
|
||||||
Request="*res://lib/globals/request.gd"
|
Request="*res://lib/globals/request.gd"
|
||||||
HomeAdapters="*res://lib/globals/home_adapters.gd"
|
HomeAdapters="*res://lib/globals/home_adapters.gd"
|
||||||
|
AudioPlayer="*res://lib/globals/audio_player.gd"
|
||||||
|
|
||||||
[editor_plugins]
|
[editor_plugins]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user