NoiseSystem PseudoCode

mail@pastecode.io avatar
unknown
csharp
a month ago
893 B
5
Indexable
Never
// In Weapon.cs
private void Shoot(){
    // codice per sparare effettivamente
    
    NoiseManager.MakeNoise(here, volume, Enemies)
}

// In NoiseManager.cs
public void MakeNoise(Position where, float volume, Team targetTeam){
    float maxDistance = CalculateMaxDistance(volume);
    
    foreach(listener){
        if(listener.team != targetTeam)
            continue; // skip
            
        if(listener.distance > maxDistance)
            continue; // skip
        
        float apparentVolume = CalculateApparentVolume(volume, listener.distance);
        
        listener.HearNoise(listener.direction.normalized, apparentVolume);
    }
}

// In Enemy.cs
public void HearNoise(Direction noiseDirection, float volume){
    float approximateDistance = CalculateApproximateDistance(volume);
    Position approximateNoisePosition = myPosition + noiseDirection * approximateDistance;
}
Leave a Comment