Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Hear Steps Help

Star

Sponsor

I was reading this thread here

http://www.rmxp.org/forums/index.php?topic=12980

And I thought it would be pretty cool to script different sounds for different terrain tags.  But so far I haven't gotten any luck of how to do this right.

Here's the edit I've made so far.  But no matter what I do.  It either makes the same sound play for every terrain, or it doesn't play a sound at all

#==============================================================================
# ** Hear_Steps
#------------------------------------------------------------------------------
#  by arevulopapo
#  9.11.2006
#==============================================================================

class Game_Character
  #--------------------------------------------------------------------------
  attr_accessor :hear_steps
  attr_accessor :step_sound
  attr_accessor :water_sound
  #--------------------------------------------------------------------------
  alias hs_init initialize
  def initialize
    hs_init
    @hear_steps = false
    @step_sound = "Audio/SE/Walk"
    @water_sound = "Audio/SE/splash"
  end
  alias hs_update update
  def update
    if self.moving? and self.hear_steps == true and (Graphics.frame_count + 2 * self.id) % (18 - @move_speed) == 0
      if self.screen_x > 0 and self.screen_x < 640 and self.screen_y > 0 and self.screen_y < 480
        if terrain_tag = 1
          volume = 100 - 5 * Math.sqrt((self.x - $game_player.x)**2 + (self.y - $game_player.y)**2)
          Audio.se_play(@step_sound, volume, 100)
        end
        if terrain_tag = 2
          volume = 100 - 5 * Math.sqrt((self.x - $game_player.x)**2 + (self.y - $game_player.y)**2)
          Audio.se_play(@water_sound, volume, 100)
          end
      end
    end
    hs_update
  end
end
Any pointers?
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top