Dynamic music system? Ideas on how I could do this?

Started by Subsonic_Noise, February 13, 2010, 03:02:29 pm

Previous topic - Next topic

Subsonic_Noise

So, I just came up with a system for my game that would totally make it much more intense.

Dynamic music.

So, the music of my game mainly consists of a mixture of ambient, industrial and breakbeat. On maps, the player mainly will hear ambient music, fitting the general mood of the game.
But here is the awesome part: when an enemy nears, the fitting breakbeat drums will become louder and louder and stop again when the player killed the enemy.
I think this would be really awesome and intense if realized in the right way, and that's where you come in: HOW THE FUCK WOULD I DO THIS?
I was thinking of making the ambient stuff the BGM and the drums the BGS, both starting at the same time, but the BGS volume being 0. Would this work and if it would, how could I link this to the distance between the player and the enemy? Would this need a script?
And, last but not least, would you even like this?

Ryex

I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Subsonic_Noise

February 13, 2010, 03:11:05 pm #2 Last Edit: February 13, 2010, 03:17:42 pm by Subsonic_Noise
Quote from: Ryexander on February 13, 2010, 03:08:57 pm
I made the DEE for a reason ya know  :P

OOOOOOHH!!! I thought about your system, but I never came up with using it for this! THANKS!
I'll try it as soon as possible and then demo random people.
EDIT: What kind of mods would I have to do? Or could I just use it as it is?

Ryex

February 13, 2010, 03:25:34 pm #3 Last Edit: February 13, 2010, 03:27:25 pm by Ryexander
it would have to be modified to have the sources follow the events and then to go away when the monster was killed. and I would suggest using point sources, much less lag.
you would be better off using the dynamic sounds script as a code reference for a new script that uses the DEE.

but the DEE should definitely be used, I put a LOT of time in to making it work and nearly lagless.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Subsonic_Noise

Quote from: Ryexander on February 13, 2010, 03:25:34 pm
it would have to be modified to have the sources follow the events and then to go away when the monster was killed. and I would suggest using point sources, much less lag.
you would be better off using the dynamic sounds script as a code reference for a new script that uses the DEE.

but the DEE should definitely be used, I put a LOT of time in to making it work and nearly lagless.

I have no clue what you where talking about in the first part, so I guess I'll just have to try, lol.

Ryex

hold on, hold on.

I went back at the code in the DEE an I realized that I never made a Dynamic source. If I did then I could create this script for you in no time flat.
I'll get back to you on this
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Subsonic_Noise

Quote from: Ryexander on February 13, 2010, 03:42:59 pm
hold on, hold on.

I went back at the code in the DEE an I realized that I never made a Dynamic source. If I did then I could create this script for you in no time flat.
I'll get back to you on this


Thanks! ^^
You just got another level up and an coupon for one free musics.

Ryex

February 13, 2010, 04:11:16 pm #7 Last Edit: February 13, 2010, 05:39:19 pm by Ryexander
ok I got this almost done I just need to figure out how to tell if a BABS enemy is dead so I can mute the source piece.


Spoiler: ShowHide

#=============================================================================
#
# ** Ryex's Dynamic BABS Monster Sounds
#
#-----------------------------------------------------------------------------
#
# By Ryex
# V 1.0
#
#-----------------------------------------------------------------------------
#
# Features
#
# * Creates Dynamic BGS Sound effects useing BABAS Monsters as sources
# * Under 200 lines of code (comments not included)
#
#-----------------------------------------------------------------------------
#
# Instructions
#
# Place in a new script above main
#
# the instructions for setting up this script are too complex to list here
# please visit
# <url>
# to get the instructions
#==============================================================================
if !$BlizzABS || BlizzABS::VERSION < 2.7
  raise 'ERROR: Ryex\'s Dynamic BABS Monster Sounds requires Blizz-ABS v2.7 or higher.'
elsif DEE::DEE_VERSION < 1.2
  raise 'ERROR: Ryex\'s Dynamic BABS Monster Sounds requires DEE v1.2 or higher.'
end

module RyexCFG
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# START basic Configuration
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  # this is the number of frames that are skiped before the BGS  gets update
  # higher value can cause more lag
  # unless you notice chopy changes in volume you don't need to change this
  Dynamic_Monster_Sound_Update = 10
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# END Configuration
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
end


class Dynamic_Source_Piece < DEE::Source_Piece
   
  attr_accessor :id, :radius
 
  def initialize (radius, id, power)
    @id = id
    @radius
    update_location
    super(@x, @y, 1, 1, power)
  end
 
  def update_location
    client = $game_map.events[@id]
    @x = client.x * DEE::Pixel_Offset_x
    @y = client.y * DEE::Pixel_Offset_y
    @id = client.id
  end
 
end
 
 
class Dynamic_Source < DEE::Source
   
  def initialize (id, radius, power)
    @pieces = []
    @pieces.push(DEE::Dynamic_Source_Piece.new(id, radius, power))
  end
 
  def update_location
    @pieces.each { |piece|
      piece.update_location
      piece.mute = $BlizzABS.get_enemy(piece.id).battler.dead?
    }
  end
 
  def effective_power (client)
    update_location
    powers = []
    if client.is_a?(DEE::Client)
      @pieces.each { |piece_index|
        unless @pieces[piece_index].mute
          squared_distance = (client.x - @pieces[piece_index].x) ** 2 + (client.y - @pieces[piece_index].y) ** 2
          if @pieces[piece_index].radius ** 2 >= squared_distance
            powers.push([piece_index, @pieces[piece_index].power])
          elsif squared_distance <= (@pieces[piece_index].power + @pieces[piece_index].radius - 1) ** 2
            distence = Math.sqrt(squared_distance) - @pieces[piece_index].radius
            powers.push([piece_index, @pieces[piece_index].power - distence])
          end
        end
      }
      unless powers.empty?
        max = powers[0]
        if max.size > 1
          (1 ... powers.size).each {|i| max = powers[i] if powers[i][1] > max[1]}
        end
        return [max[1], @pieces[max[0]].power]
      else
        return [0, 0]
      end
    else
      return [0, 0]
    end
  end
 
  def in_range? (client)
    update_location
    if client.is_a?(DEE::Client)
      @pieces.each { |piece|
        unless piece.mute
          squared_distance = (client.x - piece.x) ** 2 + (client.y - piece.y) ** 2
          if squared_distance <= (piece.power + piece.radius - 1) ** 2
            return true
          end
        end
      {
      return false
    else
      return false
    end
  end
 
end

class Sound_Source_Type < DEE::Source_Type
 
  attr_reader :bgs, :bgs_volume
 
 
  def initialize
    super('sound')
    @bgs = ''
    @bgs_volume = 100
  end
 
  def update
    if Graphics.frame_count % RyexCFG::Dynamic_Sound_Update == 0
      super
      sound_power = @clients[0].highest_effective_power
      unless sound_power[0][0] == 0
        bgsfile = $game_map.map.bgs
        @bgs = @sources[sound_power[1]].bgs
        @bgs_volume = (sound_power[0][0].to_f / sound_power[0][1]) * 100
        bgsfile = RPG::AudioFile.new(@bgs, @bgs_volume)
        unless bgsfile == nil
          unless $game_system.playing_bgs == nil
            unless $game_system.playing_bgs.name == bgsfile.name &&
              $game_system.playing_bgs.volume == bgsfile.volume
              unless @bgs_volume < 20
                $game_system.bgs_play(bgsfile)
              end
            end
          else
            $game_system.bgs_play(bgsfile)
          end
        end
      end
    end
  end
 
end

class Dynamic_Sound_Source < Dynamic_Source
 
  attr_accessor :bgs
 
  def initialize(id, radius, power, file)
    super(id, radius, power)
    @bgs = file
  end
 
end


try this you will need the DEE

you configure it like this


module DEE
 
  def self.cfg_load
#=================================
# START CFG
#=================================
    #create an array for the sources on map 1
    source_array = []
    #create an array for the clients on map 1
    client_array = []
    #add the player to the client's array
    client_array[0] = DEE::Client.new($game_player)
#----------------
# Do not edit the above
#----------------

    #add three sources to the sources array
# source_array[index] = Dynamic_Sound_Source.new(event_id, radius, 'file', power)
#event_id = id of map event monster no leading 0's
#radius = distance in pixels that the the bgs is at full power (32 is one map square)
#'file' = name of sound file in the bgs folder no exstention needed
#power = distance beyond the radius to fade the bgs (32 is one map square)
    source_array[0] = Dynamic_Sound_Source.new(1, 200, '003-Wind03', 400)
    #add new pieces to the third source (extra monsters with the same sound)
#source_array[index].pieces.push(Dynamic_Source_Piece.new(radius, event_id, power))
#radius = same as above
#event_id = same as above but for a different monster
#power = same as above
    source_array[0].pieces.push(Dynamic_Source_Piece.new(200, 4, 500))
    source_array[0].pieces.push(Dynamic_Source_Piece.new(200, 5, 500))
    source_array[0].pieces.push(Dynamic_Source_Piece.new(200, 13, 500))
    #create a hash
    map_sources = {}
    #add a sound source type under tha name 'sound'
    map_sources['sound'] = Sound_Source_Type.new
    #give our source type our sources array
    map_sources['sound'].sources = source_array
    #give our source type our client array
    map_sources['sound'].clients = client_array
    #load our hash into the DEE configuration under the map id 1
# DEE::MapSources[map_id] = hash of sources
    DEE::MapSources[1] = map_sources
    #tell the DEE that the CFG has been loaded

#repeate the above for every map (tedious I know) using DEE::MapSources[map_id]
    $dee_cfg_loaded = true
  end
 
end


hopefully you can figure that out.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Ryex

did this work for you? I'm curently making a system that would setup the sources through event comments to make it easier.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Subsonic_Noise

Quote from: Ryexander on February 15, 2010, 06:20:50 pm
did this work for you? I'm curently making a system that would setup the sources through event comments to make it easier.

wow, that's awesome!
Couldn't test this so far, I was VERY busy the last week, lol.
I'll do as soon as possible though.

Ryex

well I just finished the event set up system soo... I'll be posting an official script look for it.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Subsonic_Noise

Sorry to bump this, but did you ever post the finshed version? I couldn't find it, and this one gives me a syntax error in line 123, which is "return false". :(