Update 61 - Sound Regulation, Loot Magnet


Bugfix

  • Fixed: Player could lose a Space-MooMoo while passing by the Pacman-Planet (MooMoo would stay there until player comes back).

Loot Magnet

Collecting one of those magnet will suck in ALL xp or chocolate from the whole level.
Video (with sound): https://imgur.com/vtyvp4T

Sound Regulation

I've prevented the game now from playing the same sound at the same time multiple times. Now it does not get too loud all the time.

Video Demo (with sound): https://imgur.com/gKxBfvm

My solution in code: I'm storing the resource path (e.g. ".../mysound.wav") into an array when I want to play it. Before playing it, I search the same array, if this resource-path is already in there. After a defined time, I remove the resource path from the array. In my case, the entries stay for 0.03s in there and then get removed. Meaning: Every frame (when we think of 30 FPS) you can play one sound of the same type.

Sound Manager (Autoload)

extends Node
 
class sound_info:
    var timer
    var resource_path
 
var recently_played_sounds = []
 
func _process(delta):
    for i in range(recently_played_sounds.size()-1, -1, -1):
        recently_played_sounds[i].timer -= delta
        if recently_played_sounds[i].timer <= 0.0:
            recently_played_sounds.remove_at(i)
 
func register_sound(_stream, _timer = 0.03):
    var new_sound_info = sound_info.new()
    new_sound_info.resource_path = _stream.resource_path
    new_sound_info.timer = _timer
    recently_played_sounds.append(new_sound_info)
 
func sound_was_recently_played(_stream):
    for my_sound_info in recently_played_sounds:
        if _stream.resource_path == my_sound_info.resource_path:
            return true
     
    return false

Usage in Code (Script added to AudioStreamPlayer):

func play_sound_stream():
    if not SoundManager.sound_was_recently_played(stream):
        SoundManager.register_sound(stream)
        play()

Files

cozy-space-survivors-windows.zip 104 MB
Version 77 Nov 12, 2023
cozy_space_survivors-mac.zip 248 MB
Version 77 Nov 12, 2023

Get Cozy Space Survivors

Leave a comment

Log in with itch.io to leave a comment.