Skip to content

Commit

Permalink
feat: add screaming to shooter
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiPeterG committed Feb 4, 2024
1 parent 31f90cd commit 1f2f3a7
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ particles_anim_h_frames = 1
particles_anim_v_frames = 1
particles_anim_loop = false

[sub_resource type="Image" id="Image_l7xtp"]
[sub_resource type="Image" id="Image_bhegq"]
data = {
"data": PackedByteArray(249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0),
"format": "RGBA8",
Expand All @@ -44,7 +44,7 @@ data = {
}

[sub_resource type="ImageTexture" id="ImageTexture_c1vcs"]
image = SubResource("Image_l7xtp")
image = SubResource("Image_bhegq")

[sub_resource type="GDScript" id="GDScript_yljtb"]
script/source = "@tool
Expand Down Expand Up @@ -967,7 +967,7 @@ size = Vector2(15921.5, 26)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_drmbs"]
size = Vector2(831, 36)
[sub_resource type="Image" id="Image_6ppt8"]
[sub_resource type="Image" id="Image_t7ijv"]
data = {
"data": PackedByteArray(249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 255, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0, 249, 250, 251, 0),
"format": "RGBA8",
Expand All @@ -977,7 +977,7 @@ data = {
}
[sub_resource type="ImageTexture" id="ImageTexture_y0xxx"]
image = SubResource("Image_6ppt8")
image = SubResource("Image_t7ijv")
[node name="Node2D" type="Node2D"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ signal health_changed(health_value)

var health = 3

const SPEED = 10.0
@export var SPEED = 10.0
const JUMP_VELOCITY = 10.0

# Get the gravity from the project settings to be synced with RigidBody nodes.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
extends Label3D


# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass

func setText(Text: String):
self.text = Text
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=17 format=3 uid="uid://xcjrjq5cbn7y"]
[gd_scene load_steps=18 format=3 uid="uid://xcjrjq5cbn7y"]

[ext_resource type="Script" path="res://prototypes/game-burghardt-goergens-ragerumble-minigames/Shooter/Player.gd" id="1_2v3wm"]
[ext_resource type="PackedScene" uid="uid://cf1dcxwv6bvl3" path="res://prototypes/game-burghardt-goergens-ragerumble-minigames/Shooter/models/Pistol.glb" id="2_4esil"]
Expand Down Expand Up @@ -133,7 +133,9 @@ properties/2/path = NodePath("Camera3D:rotation")
properties/2/spawn = true
properties/2/replication_mode = 1

[node name="Player" type="CharacterBody3D"]
[sub_resource type="AudioStreamMicrophone" id="AudioStreamMicrophone_2wxd4"]

[node name="Player" type="CharacterBody3D" groups=["player"]]
collision_layer = 2
script = ExtResource("1_2v3wm")

Expand Down Expand Up @@ -175,4 +177,9 @@ playback_default_blend_time = 0.05
[node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."]
replication_config = SubResource("SceneReplicationConfig_hn37q")

[node name="AudioStreamRecord" type="AudioStreamPlayer" parent="."]
stream = SubResource("AudioStreamMicrophone_2wxd4")
autoplay = true
bus = &"Record"

[connection signal="animation_finished" from="AnimationPlayer" to="." method="_on_animation_player_animation_finished"]
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ extends Node
@onready var address_entry = $CanvasLayer/MainMenu/MarginContainer/VBoxContainer/AddressEntry
@onready var hud = $CanvasLayer/HUD
@onready var health_bar = $CanvasLayer/HUD/HealthBar

var stereo := true
var effect # See AudioEffect in docs
var recording # See AudioStreamSample in docs
var mix_rate := 44100 # This is the default mix rate on recordings
var format := 1 # This equals to the default format: 16 bits

const Player = preload("res://prototypes/game-burghardt-goergens-ragerumble-minigames/Shooter/player.tscn")
const PORT = 9999
Expand All @@ -24,15 +28,27 @@ func _on_host_button_pressed():
multiplayer.peer_disconnected.connect(remove_player)

add_player(multiplayer.get_unique_id())
var idx = AudioServer.get_bus_index("Record")
effect = AudioServer.get_bus_effect(idx, 0)

#upnp_setup()
while true:
_on_RecordButton_pressed()
await get_tree().create_timer(0.1).timeout
_on_RecordButton_pressed()
_on_PlayButton_pressed()

func _on_join_button_pressed():
main_menu.hide()
hud.show()

enet_peer.create_client(address_entry.text, PORT)
multiplayer.multiplayer_peer = enet_peer
while true:
_on_RecordButton_pressed()
await get_tree().create_timer(0.1).timeout
_on_RecordButton_pressed()
_on_PlayButton_pressed()

func add_player(peer_id):
var player = Player.instantiate()
Expand Down Expand Up @@ -68,3 +84,44 @@ func upnp_setup():
"UPNP Port Mapping Failed! Error %s" % map_result)

print("Success! Join Address: %s" % upnp.query_external_address())


func _on_RecordButton_pressed():
if effect.is_recording_active():
recording = effect.get_recording()
effect.set_recording_active(false)
recording.set_mix_rate(mix_rate)
recording.set_format(format)
recording.set_stereo(stereo)
else:
effect.set_recording_active(true)

func _on_PlayButton_pressed():
var max_amplitude = 0
var data = recording.get_data()
const threshold = 5000
# Iterate through each pair of bytes in the PackedByteArray
for i in range(0, data.size(), 2):
# Combine two bytes to create one 16-bit sample
var sample = data[i] | (data[i+1] << 8)

# Convert to signed 16-bit integer if necessary
if sample >= 32768:
sample -= 65536

# Calculate absolute value for amplitude
var amplitude = abs(sample)
amplitude = max(0, amplitude - threshold)
#if amplitude <= 200:
# amplitude = 0

# Update max_amplitude if this sample's amplitude is greater
if amplitude > max_amplitude:
max_amplitude = amplitude
var amplitude_percentage = roundi(100.0*max_amplitude/(32768 - threshold))
var playerlabel = $CanvasLayer/HUD/Recordinglabel
var playerchar = get_tree().get_nodes_in_group("player")[0]
#if playerlabel == null:
# return
playerlabel.setText("Amp: " + str(amplitude_percentage) +"%")
playerchar.SPEED = 10.0 + 10.0 * (max_amplitude / threshold)
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[gd_scene load_steps=9 format=3 uid="uid://c8oqxmm2w2wvv"]
[gd_scene load_steps=10 format=3 uid="uid://c8oqxmm2w2wvv"]

[ext_resource type="Script" path="res://prototypes/game-burghardt-goergens-ragerumble-minigames/Shooter/world.gd" id="1_6tkge"]
[ext_resource type="PackedScene" path="res://prototypes/game-burghardt-goergens-ragerumble-minigames/Shooter/environment.tscn" id="1_iktak"]
[ext_resource type="PackedScene" uid="uid://c1j7an8woikyd" path="res://prototypes/game-burghardt-goergens-ragerumble-minigames/Shooter/environment.tscn" id="1_iktak"]
[ext_resource type="Texture2D" uid="uid://8ka2ui7sq36p" path="res://prototypes/game-burghardt-goergens-ragerumble-minigames/Shooter/addons/kenney_particle_pack/circle_05.png" id="3_ehmxv"]
[ext_resource type="Script" path="res://prototypes/game-burghardt-goergens-ragerumble-minigames/Jumper/Recordinglabel.gd" id="4_6timr"]

[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_u5pdl"]
sky_horizon_color = Color(0.64625, 0.65575, 0.67075, 1)
Expand Down Expand Up @@ -117,6 +118,14 @@ max_value = 3.0
value = 3.0
show_percentage = false

[node name="Recordinglabel" type="Label" parent="CanvasLayer/HUD"]
offset_left = 542.0
offset_top = 37.0
offset_right = 596.0
offset_bottom = 60.0
text = "Amp: 0"
script = ExtResource("4_6timr")

[node name="MultiplayerSpawner" type="MultiplayerSpawner" parent="."]
_spawnable_scenes = PackedStringArray("res://prototypes/game-burghardt-goergens-ragerumble-minigames/Shooter/player.tscn")
spawn_path = NodePath("..")
Expand Down

0 comments on commit 1f2f3a7

Please sign in to comment.