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.

Range of a specific tile from the player...

Well I've been trying to make a script that plays a certain Background Sound when the player is within range of a tile that has a certain terrain tag. Can someone help me out with this ranged business? I have managed to do it one way, but isn't that great and the sound will start all over again when you walk away and then come back. I want it to just constantly play then when you get near it again it'll be louder.

Wow, I just realized what I had typed and just realized how I could do that, but I'd still like to do it a better way for the range. Currently I'm doing it this way.

Code:
x1 = $game_player.x - 10
    x2 = $game_player.x + 10
    y1 = $game_player.y - 10
    y2 = $game_player.y + 10
    for x in x1...x2
      for y in y1...y2
        if $game_map.terrain_tag(x, y) == 1
          terrain = 0
          range_bgs = true
        elsif $game_map.terrain_tag(x, y) == 2
          terrain = 1
          range_bgs = true
        else
          range_bgs = false
        end
      end
    end
Now I know there is a better way of doing this, but that's what I need help with getting.

Oh also when I have it this way, the volume was only set at one number, I'd like to make it vary based on your location, thus the need for the in_range? type method.
 

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