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.

[VX/RGSS2] Need moar help with 8dir

Hey guys. This is a method which is called for each tile in a grid of my own construction, and needs to find the value of the tile that is closer to the center. I get the left, right, up, and down checks, and it works wonderfully although it can't draw angles. I would love it to draw angles, but to do that, I need the other four directions.

The code functions as it should in the its current form here. I already set up handlers for the other four directions, but the little brackets there are only testing four directions.

Halp please! I even tried sleeping this time and that didn't fix it either!
kthxbai


Code:
  def closer(x, y)

    # checks which tile in the grid is closer to the center and return its value

    # first, determine which of the 8 directions to check by offset from center

    sx = 0 - (@center - x)

    sy = 0 - (@center - y)

    return 0 if (sx < 2) & (sy < 2) & (sx > -2) & (sy > -2)

    if sy.abs > sx.abs

      sy > 0 ? dir = 'up' : dir = 'down'

    else

      sx > 0 ? dir = 'left' : dir = 'right'

    end

    case dir 

      when 'up' then return @tile[x][y - 1] rescue 1

      when 'up-right' then return @tile[x + 1][y - 1] rescue 1

      when 'right' then return @tile[x + 1][y]  rescue 1

      when 'down-right' then return @tile[x + 1][y + 1]  rescue 1

      when 'down' then return @tile[x][y + 1]  rescue 1

      when 'down-left' then return @tile[x - 1][y + 1] rescue 1

      when 'left' then return @tile[x - 1][y]  rescue 1

      when 'top-left' then return @tile[x - 1][y - 1] rescue 1

    end

  end
 
Theory, I know you understand the script perfectly, but not everyone here would. Comments are a way to make it so that anybody who might be able to help has a much better chance of helping. Not to mention the fact that they probably need the whole script, and not just the method you're stuck on. (And don't worry about theft. All that happens in that case is you pointing out this thread, and the admins will usually deal with it, no matter what the forum)

As for the script itself, I'll probably be able to help next time you come online.
 
Actually just this:
# if sy.abs > sx.abs
# sy > 0 ? dir = 'up' : dir = 'down'
# else
# sx > 0 ? dir = 'left' : dir = 'right'
# end

should be enough for what I am asking. All I was asking is how to take an x and y offset and determine the 8 directions from it. I don't see how they need the whole script for that. If someone asked, I would share it. I'm not worried about theft. I simply would like it to be stable and, well, pretty when I first show it to the world rather than the blocky mess it is now.

Again, though, thanks for the offer, I'll see you on AIM.
 

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