Skip to content

Commit

Permalink
wip2: the return
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiPeterG committed Feb 4, 2024
1 parent a56bf13 commit 5e5a68e
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 72 deletions.
2 changes: 1 addition & 1 deletion default_bus_layout.tres
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ resource_name = "Record"
[resource]
bus/1/name = &"Record"
bus/1/solo = false
bus/1/mute = true
bus/1/mute = false
bus/1/bypass_fx = false
bus/1/volume_db = 0.0
bus/1/send = &"Master"
Expand Down
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_f06nw"]
[sub_resource type="Image" id="Image_bik2w"]
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_f06nw")
image = SubResource("Image_bik2w")

[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_oki18"]
[sub_resource type="Image" id="Image_7iwkp"]
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_oki18")
image = SubResource("Image_7iwkp")
[node name="Node2D" type="Node2D"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ signal health_changed(health_value)
@onready var anim_player = $AnimationPlayer
@onready var muzzle_flash = $Camera3D/Pistol/MuzzleFlash
@onready var raycast = $Camera3D/RayCast3D

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
var health = 3

@export var SPEED = 10.0
Expand All @@ -23,6 +27,13 @@ func _ready():

Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
camera.current = true
var idx = AudioServer.get_bus_index("Record")
effect = AudioServer.get_bus_effect(idx, 0)
while true:
_on_RecordButton_pressed()
await get_tree().create_timer(0.1).timeout
_on_RecordButton_pressed()
_on_PlayButton_pressed()

func _unhandled_input(event):
if not is_multiplayer_authority(): return
Expand Down Expand Up @@ -88,3 +99,42 @@ func receive_damage():
func _on_animation_player_animation_finished(anim_name):
if anim_name == "shoot":
anim_player.play("idle")


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 amplitude_percentage = roundi(100.0*max_amplitude/(20000 - threshold))
var playerlabel = get_tree().get_nodes_in_group("label")[0]
playerlabel.setText("Amp: " + str(amplitude_percentage) +"%")
SPEED = 10.0 + 10.0 * (max_amplitude / threshold)
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ 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 @@ -28,29 +23,13 @@ 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)
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

var idx = AudioServer.get_bus_index("Record")
effect = AudioServer.get_bus_effect(idx, 0)
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 All @@ -71,46 +50,3 @@ func update_health_bar(health_value):
func _on_multiplayer_spawner_spawned(node):
if node.is_multiplayer_authority():
node.health_changed.connect(update_health_bar)

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 amplitude_percentage = roundi(100.0*max_amplitude/(20000 - threshold))
var playerlabel = $CanvasLayer/HUD/Recordinglabel
var playerchar = get_tree().get_nodes_in_group("player")
print(playerchar)
if playerlabel == null:
return
playerlabel.setText("Amp: " + str(amplitude_percentage) +"%")
for player in playerchar:
player.SPEED = 10.0 + 10.0 * (max_amplitude / threshold)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[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"]

Expand Down Expand Up @@ -118,7 +118,7 @@ max_value = 3.0
value = 3.0
show_percentage = false

[node name="Recordinglabel" type="Label" parent="CanvasLayer/HUD"]
[node name="Recordinglabel" type="Label" parent="CanvasLayer/HUD" groups=["label"]]
layout_mode = 0
offset_left = 542.0
offset_top = 37.0
Expand Down

0 comments on commit 5e5a68e

Please sign in to comment.