samples/99_genre_dev_tools/tile_editor_starting_point/app/main.rb
def add_grid

    # Outputs the grid's border.
    outputs.borders << state.grid_border
    temp = 0

    # Before looking at the code that outputs the vertical and horizontal lines in the
    # grid, take note of the fact that:
    # grid_border[1] refers to the border's bottom line (running horizontally),
    # grid_border[2] refers to the border's top line (running (horizontally),
    # grid_border[0] refers to the border's left line (running vertically),
    # and grid_border[3] refers to the border's right line (running vertically).

    #           [2]
    #       ----------
    #       |        |
    # [0]   |        | [3]
    #       |        |
    #       ----------
    #           [1]

    # Calculates the positions and outputs the x grid lines in the color gray.
    state.gridX.map do # perform an action on all elements of the gridX collection
      |x|
      temp += 1 # increment temp

      # if x's value is greater than (or equal to) the x value of the border's left side
      # and less than (or equal to) the x value of the border's right side
      if x >= state.centerX - (state.grid_border[2] / 2) && x <= state.centerX + (state.grid_border[2] / 2)
        delta = state.centerX - 640
        # vertical lines have the same starting and ending x positions
        # starting y and ending y positions lead from the bottom of the border to the top of the border
        outputs.lines << [x - delta, state.grid_border[1], x - delta, state.grid_border[1] + state.grid_border[2], 150, 150, 150] # sets definition of vertical line and outputs it
      end
    end
    temp = 0

    # Calculates the positions and outputs the y grid lines in the color gray.
    state.gridY.map do # perform an action on all elements of the gridY collection
      |y|
      temp += 1 # increment temp

      # if y's value is greater than (or equal to) the y value of the border's bottom side
      # and less than (or equal to) the y value of the border's top side
      if y >= state.centerY - (state.grid_border[3] / 2) && y <= state.centerY + (state.grid_border[3] / 2)
        delta = state.centerY - 393
        # horizontal lines have the same starting and ending y positions
        # starting x and ending x positions lead from the left side of the border to the right side of the border
        outputs.lines << [state.grid_border[0], y - delta, state.grid_border[0] + state.grid_border[3], y - delta, 150, 150, 150] # sets definition of horizontal line and outputs it
      end
    end

    # Sets values and outputs sprites for the filled_squares collection.
    state.filled_squares.map do # perform an action on every element of the filled_squares collection
      |x, y, w, h, sprite|
        # if x's value is greater than (or equal to) the x value of 17 pixels to the left of the border's left side
        # and less than (or equal to) the x value of the border's right side
        # and y's value is greater than (or equal to) the y value of the border's bottom side
        # and less than (or equal to) the y value of 25 pixels above the border's top side
        # NOTE: The allowance of 17 pixels and 25 pixels is due to the fact that a grid box may be slightly cut off or
        # not entirely visible in the grid's view (until it is moved using "W", "A", "S", "D")
        if x >= state.centerX - (state.grid_border[2] / 2) - 17 && x <= state.centerX + (state.grid_border[2] / 2) &&
           y >= state.centerY - (state.grid_border[3] / 2) && y <= state.centerY + (state.grid_border[3] / 2) + 25
          # calculations done to place sprites in grid spaces that are meant to filled in
          # mess around with the x and y values and see how the sprite placement changes
          outputs.sprites << [x - state.centerX + 630, y - state.centerY + 360, w, h, sprite]
        end
      end

      # outputs a white solid along the left side of the grid (change the color and you'll be able to see it against the white background)
      # state.increment subtracted in x parameter because solid's position is denoted by bottom left corner
      # state.increment subtracted in y parameter to avoid covering the title label
      outputs.primitives << [state.grid_border[0] - state.increment,
                             state.grid_border[1] - state.increment, state.increment, state.grid_border[3] + (state.increment * 2),
                             255, 255, 255].solid

      # outputs a white solid along the right side of the grid
      # state.increment subtracted from y parameter to avoid covering title label
      outputs.primitives << [state.grid_border[0] + state.grid_border[2],
                             state.grid_border[1] - state.increment, state.increment, state.grid_border[3] + (state.increment * 2),
                             255, 255, 255].solid

      # outputs a white solid along the bottom of the grid
      # state.increment subtracted from y parameter to avoid covering last row of grid boxes
      outputs.primitives << [state.grid_border[0] - state.increment, state.grid_border[1] - state.increment,
                             state.grid_border[2] + (2 * state.increment), state.increment, 255, 255, 255].solid

      # outputs a white solid along the top of the grid
      outputs.primitives << [state.grid_border[0] - state.increment, state.grid_border[1] + state.grid_border[3],
                             state.grid_border[2] + (2 * state.increment), state.increment, 255, 255, 255].solid

  end
# Creates a grid by outputting vertical and horizontal grid lines onto the screen.
# Outputs sprites for the filled_squares collection onto the screen.
Creates a grid by outputting vertical and horizontal grid lines onto the screen.
Outputs sprites for the filled_squares collection onto the screen.
Creates a grid by outputting vertical and horizontal grid lines onto the screen . Outputs sprites for the filled_squares collection onto the screen .
def add_grid
    outputs.borders << state.grid_border
    temp = 0
    state.gridX.map do 
      |x|
      temp += 1 
      if x >= state.centerX - (state.grid_border[2] / 2) && x <= state.centerX + (state.grid_border[2] / 2)
        delta = state.centerX - 640
        outputs.lines << [x - delta, state.grid_border[1], x - delta, state.grid_border[1] + state.grid_border[2], 150, 150, 150] 
      end
    end
    temp = 0
    state.gridY.map do 
      |y|
      temp += 1 
      if y >= state.centerY - (state.grid_border[3] / 2) && y <= state.centerY + (state.grid_border[3] / 2)
        delta = state.centerY - 393
        outputs.lines << [state.grid_border[0], y - delta, state.grid_border[0] + state.grid_border[3], y - delta, 150, 150, 150] 
      end
    end
    state.filled_squares.map do 
      |x, y, w, h, sprite|
        if x >= state.centerX - (state.grid_border[2] / 2) - 17 && x <= state.centerX + (state.grid_border[2] / 2) &&
           y >= state.centerY - (state.grid_border[3] / 2) && y <= state.centerY + (state.grid_border[3] / 2) + 25
          outputs.sprites << [x - state.centerX + 630, y - state.centerY + 360, w, h, sprite]
        end
      end
      outputs.primitives << [state.grid_border[0] - state.increment,
                             state.grid_border[1] - state.increment, state.increment, state.grid_border[3] + (state.increment * 2),
                             255, 255, 255].solid
      outputs.primitives << [state.grid_border[0] + state.grid_border[2],
                             state.grid_border[1] - state.increment, state.increment, state.grid_border[3] + (state.increment * 2),
                             255, 255, 255].solid
      outputs.primitives << [state.grid_border[0] - state.increment, state.grid_border[1] - state.increment,
                             state.grid_border[2] + (2 * state.increment), state.increment, 255, 255, 255].solid
      outputs.primitives << [state.grid_border[0] - state.increment, state.grid_border[1] + state.grid_border[3],
                             state.grid_border[2] + (2 * state.increment), state.increment, 255, 255, 255].solid
  end
def add_grid outputs . borders << state . grid_border temp = 0 state . gridX . map do | x | temp += 1 if x >= state . centerX - ( state . grid_border [ 2 ] / 2 ) && x <= state . centerX + ( state . grid_border [ 2 ] / 2 ) delta = state . centerX - 640 outputs . lines << [ x - delta , state . grid_border [ 1 ] , x - delta , state . grid_border [ 1 ] + state . grid_border [ 2 ] , 150 , 150 , 150 ] end end temp = 0 state . gridY . map do | y | temp += 1 if y >= state . centerY - ( state . grid_border [ 3 ] / 2 ) && y <= state . centerY + ( state . grid_border [ 3 ] / 2 ) delta = state . centerY - 393 outputs . lines << [ state . grid_border [ 0 ] , y - delta , state . grid_border [ 0 ] + state . grid_border [ 3 ] , y - delta , 150 , 150 , 150 ] end end state . filled_squares . map do | x , y , w , h , sprite | if x >= state . centerX - ( state . grid_border [ 2 ] / 2 ) - 17 && x <= state . centerX + ( state . grid_border [ 2 ] / 2 ) && y >= state . centerY - ( state . grid_border [ 3 ] / 2 ) && y <= state . centerY + ( state . grid_border [ 3 ] / 2 ) + 25 outputs . sprites << [ x - state . centerX + 630 , y - state . centerY + 360 , w , h , sprite ] end end outputs . primitives << [ state . grid_border [ 0 ] - state . increment , state . grid_border [ 1 ] - state . increment , state . increment , state . grid_border [ 3 ] + ( state . increment * 2 ) , 255 , 255 , 255 ] . solid outputs . primitives << [ state . grid_border [ 0 ] + state . grid_border [ 2 ] , state . grid_border [ 1 ] - state . increment , state . increment , state . grid_border [ 3 ] + ( state . increment * 2 ) , 255 , 255 , 255 ] . solid outputs . primitives << [ state . grid_border [ 0 ] - state . increment , state . grid_border [ 1 ] - state . increment , state . grid_border [ 2 ] + ( 2 * state . increment ) , state . increment , 255 , 255 , 255 ] . solid outputs . primitives << [ state . grid_border [ 0 ] - state . increment , state . grid_border [ 1 ] + state . grid_border [ 3 ] , state . grid_border [ 2 ] + ( 2 * state . increment ) , state . increment , 255 , 255 , 255 ] . solid end
Creates a grid by outputting vertical and horizontal grid lines onto the screen.
Creates a grid by outputting vertical and horizontal grid lines onto the screen .
# Outputs the grid's border. # Before looking at the code that outputs the vertical and horizontal lines in the # grid, take note of the fact that: # grid_border[1] refers to the border's bottom line (running horizontally), # grid_border[2] refers to the border's top line (running (horizontally), # grid_border[0] refers to the border's left line (running vertically), # and grid_border[3] refers to the border's right line (running vertically). #           [2] #       ---------- #       |        | # [0]   |        | [3] #       |        | #       ---------- #           [1] # Calculates the positions and outputs the x grid lines in the color gray. # perform an action on all elements of the gridX collection # increment temp # if x's value is greater than (or equal to) the x value of the border's left side # and less than (or equal to) the x value of the border's right side # vertical lines have the same starting and ending x positions # starting y and ending y positions lead from the bottom of the border to the top of the border # sets definition of vertical line and outputs it # Calculates the positions and outputs the y grid lines in the color gray. # perform an action on all elements of the gridY collection # increment temp # if y's value is greater than (or equal to) the y value of the border's bottom side # and less than (or equal to) the y value of the border's top side # horizontal lines have the same starting and ending y positions # starting x and ending x positions lead from the left side of the border to the right side of the border # sets definition of horizontal line and outputs it # Sets values and outputs sprites for the filled_squares collection. # perform an action on every element of the filled_squares collection # if x's value is greater than (or equal to) the x value of 17 pixels to the left of the border's left side # and less than (or equal to) the x value of the border's right side # and y's value is greater than (or equal to) the y value of the border's bottom side # and less than (or equal to) the y value of 25 pixels above the border's top side # NOTE: The allowance of 17 pixels and 25 pixels is due to the fact that a grid box may be slightly cut off or # not entirely visible in the grid's view (until it is moved using "W", "A", "S", "D") # calculations done to place sprites in grid spaces that are meant to filled in # mess around with the x and y values and see how the sprite placement changes # outputs a white solid along the left side of the grid (change the color and you'll be able to see it against the white background) # state.increment subtracted in x parameter because solid's position is denoted by bottom left corner # state.increment subtracted in y parameter to avoid covering the title label # outputs a white solid along the right side of the grid # state.increment subtracted from y parameter to avoid covering title label # outputs a white solid along the bottom of the grid # state.increment subtracted from y parameter to avoid covering last row of grid boxes # outputs a white solid along the top of the grid