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.

Dimond Formula

Hello,

I'm trying to create a tile based(32*32) diamond shape on the map but I'm having a hard time. At first I wanted an ellipse but then figured out that it didn't work/look so well, except for movement(in a TBS).

Here is the ellipse:
http://www.unknowncoders.com/rmxp/screenshots/ellipse.PNG[/img]

Here is what I want:
http://www.unknowncoders.com/rmxp/scree ... elpdim.PNG[/img]

Here is the ellipse code/formula:
Code:
  #-----------------------------------------------------------------------------
  # * Calculate Tiles - Ellipse
  #-----------------------------------------------------------------------------   
  def calculate_tiles(h_r, v_r, center,c_pass=true)
    @current_tiles = {}
    if v_r >= h_r
      for current_v in 1..v_r
        for current_h in 1..h_r
          calculate_tile(current_h,current_v, center,c_pass)
        end
      end
    else
      for current_h in 1..h_r
        for current_v in 1..v_r
          calculate_tile(current_h,current_v, center,c_pass)
        end
      end
    end
  end
  #-----------------------------------------------------------------------------
  # * Calculate Tile Pos
  #----------------------------------------------------------------------------- 
  def calculate_tile(h_r, v_r, center,c_pass)
    for angle in 0...360
      x = Math.cos(angle)*h_r + center.x
      y = Math.sin(angle)*v_r + center.y
      # Check if passible
      next unless center.tbs_passable?(x.round,y.round,0,c_pass)
      @current_tiles.push([x.round, y.round])
    end
  end
 
Code:
  #-----------------------------------------------------------------------------
  # * Calculate Tiles - Diamond
  #-----------------------------------------------------------------------------   
  def calculate_tiles(range)
    index = range
    array = [ ]
    height = index * 2 + 1
    for i in 0..(height-1)/2
      width = i * 2 + 1
      x = (height - width / 2 - 1) - 1
      array.push([x, i, width])
    end
    b = array.size
    for i in 0...b-1
      array.push(array[width - b - i - 1])
    end
    c = [ ]
    for y in 0...array.size
      x = array[y][0]
      b = array[y][2]
      for i in 0...b
        c << [x+i, y]
      end
    end
    c.each { |tile| @tiles << tile }
  end
it's a big mess but it works ;)
 

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