Skip to content

Commit

Permalink
feat: crying
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiPeterG committed Feb 5, 2024
1 parent 280405c commit 15c0f4a
Show file tree
Hide file tree
Showing 13 changed files with 536 additions and 1,294 deletions.
9 changes: 9 additions & 0 deletions addons/pronto/behaviors/PlatformerControllerBehavior.gd
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,12 @@ var key_map = [{
}]

func _enter_tree():
if not is_multiplayer_authority(): return
if not get_parent() is CharacterBody2D:
push_error("PlatformerController must be a child of a CharacterBody2D")

func _update_jump():
if not is_multiplayer_authority(): return
var now = Time.get_ticks_msec()

if _parent.is_on_floor():
Expand All @@ -88,16 +90,19 @@ func _update_jump():
_last_jump_input = now

func _can_jump():
if not is_multiplayer_authority(): return
var now = Time.get_ticks_msec()
var input = _last_jump_input > now - 1000 * jump_buffer
var floored = _last_on_floor > now - 1000 * coyote_time
return input and floored

func _reset_jump():
if not is_multiplayer_authority(): return
_last_jump_input = -10000
_last_on_floor = -10000

func _draw():
if not is_multiplayer_authority(): return
super._draw()
if !show_trail:
return
Expand All @@ -117,6 +122,7 @@ func _is_key_pressed(direction):
func _physics_process(delta):
if Engine.is_editor_hint():
return
if not is_multiplayer_authority(): return

# region for lerping the horizontal_velocity
var delta_time = delta
Expand Down Expand Up @@ -165,10 +171,13 @@ func _physics_process(delta):
queue_redraw()

func lines():
if not is_multiplayer_authority(): return
return super.lines() + [Lines.DashedLine.new(self, get_parent(), func (f): return "controls", "controls")]

func update_horizontal_velocity(value: float):
if not is_multiplayer_authority(): return
goal_horizontal_velocity = value

func set_movement_enabled(boolean: bool):
if not is_multiplayer_authority(): return
movement_enabled = boolean
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func _physics_process(delta):
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
player = get_parent().get_parent().get_node("Player")
player = get_tree().get_nodes_in_group("player")[0]
if player == null:
return
playerpos = player.global_position.x
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
extends CharacterBody2D

signal health_changed(health_value)
signal amp_changes(amp)
var health = 3
@onready var camera = $CameraPlayer
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
@export var SPEED = 250.0
const JUMP_VELOCITY = 400.0

# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = 800.0

func _enter_tree():
set_multiplayer_authority(str(name).to_int())
print("here3")

func _ready():
if not is_multiplayer_authority():
print("lol")
return

Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
camera.make_current()
print("here")
var idx = AudioServer.get_bus_index("Record")
AudioServer.add_bus_effect(idx, AudioEffectRecord.new(), 0)
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()

@rpc("any_peer")
func receive_damage():
health -= 1
if health <= 0:
health = 3
reset_player()
health_changed.emit(health)

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 data = recording.get_data()
const max_amplitude = 12000.0
var amplitude = 0.0
# 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
amplitude = abs(sample)
if amplitude <= 200.0:
amplitude = 0.0
#var amplitude_percentage = roundi(100.0*max_amplitude/(32768 - threshold))
var amplitude_percentage = roundi(100.0* (amplitude / max_amplitude))
amp_changes.emit("Amp: " + str(amplitude_percentage) +"%")
SPEED = 250.0 + 250.0 * (amplitude / max_amplitude)

func reset_player():
position = Vector2(128.0, 512.0)

func _physics_process(delta):
if not is_multiplayer_authority(): return

# Add the gravity.
if not is_on_floor():
velocity.y += gravity * delta

# Handle Jump.
if Input.is_action_just_pressed("up") and is_on_floor():
velocity.y = -JUMP_VELOCITY

if Input.is_action_just_pressed("ui_accept") and is_on_floor():
reset_player()


# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var input_dir = Input.get_vector("left", "right", "up", "down")
var direction = (transform.origin * Vector2(input_dir.x, 0)).normalized()
if direction:
velocity.x = direction.x * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)

move_and_slide()
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
extends Node2D

@onready var main_menu = $CanvasLayer/MainMenu
@onready var address_entry = $CanvasLayer/MainMenu/MarginContainer/VBoxContainer/AddressEntry
@onready var hud = $CanvasLayer/HUD
@onready var health_bar = $CanvasLayer/HUD/HealthBar

const Player = preload("res://prototypes/game-burghardt-goergens-ragerumble-minigames/Jumper/player.tscn")
const PORT = 9999
var enet_peer = ENetMultiplayerPeer.new()

func _unhandled_input(event):
if Input.is_action_just_pressed("quit"):
enet_peer.close()
get_tree().change_scene_to_file("res://prototypes/game-burghardt-goergens-ragerumble-minigames/game-burghardt-goergens-ragerumble-minigames.tscn")
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE

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

enet_peer.create_server(PORT)
multiplayer.multiplayer_peer = enet_peer
multiplayer.peer_connected.connect(add_player)
multiplayer.peer_disconnected.connect(remove_player)

add_player(multiplayer.get_unique_id())

func _on_join_button_pressed():
main_menu.hide()
hud.show()
print("here2")
var address
if address_entry.text == "":
address = "localhost"

enet_peer.create_client(address, PORT)
multiplayer.multiplayer_peer = enet_peer

func set_amp_label(amp):
$CanvasLayer/HUD/Recordinglabel.set_text(amp)

func add_player(peer_id):
var player = Player.instantiate()
player.name = str(peer_id)

add_child(player)
if player.is_multiplayer_authority():
player.health_changed.connect(update_health_bar)
player.amp_changes.connect(set_amp_label)

func remove_player(peer_id):
var player = get_node_or_null(str(peer_id))
if player:
player.queue_free()

func update_health_bar(health_value):
health_bar.value = health_value

func _on_multiplayer_spawner_spawned(node):
if node.is_multiplayer_authority():
node.health_changed.connect(update_health_bar)
node.amp_changes.connect(set_amp_label)
Loading

0 comments on commit 15c0f4a

Please sign in to comment.