samples/99_genre_dev_tools/tile_editor_starting_point/app/main.rb
# Checks if the mouse is being clicked or dragged
Checks if the mouse is being clicked or dragged
Checks if the mouse is being clicked or dragged
def check_click
    if inputs.keyboard.key_down.r 
      $dragon.reset
    end
    if inputs.mouse.down 
      state.mouse_held = true
      if inputs.mouse.position.x < state.grid_border[0] 
        state.tileCords.map do 
          |x, y, order|
          if inputs.mouse.position.x >= x && inputs.mouse.position.x <= x + state.tileSize &&
             inputs.mouse.position.y >= y && inputs.mouse.position.y <= y + state.tileSize
            state.tileSelected = order 
          end
        end
      end
    elsif inputs.mouse.up 
      state.mouse_held = false 
      state.mouse_dragging = false
    end
    if state.mouse_held &&    
       !inputs.mouse.click &&     
       ((inputs.mouse.previous_click.point.x - inputs.mouse.position.x).abs > 15 ||
        (inputs.mouse.previous_click.point.y - inputs.mouse.position.y).abs > 15) 
      state.mouse_dragging = true
    end
    if ((inputs.mouse.click) && (inputs.mouse.click.point.inside_rect? state.grid_border))
      search_lines(inputs.mouse.click.point, :click)
    elsif ((state.mouse_dragging) && (inputs.mouse.position.inside_rect? state.grid_border))
      search_lines(inputs.mouse.position, :drag)
    end
    state.centerX += state.speed if inputs.keyboard.key_held.d &&
                                    (state.centerX + state.speed) < state.originalCenter[0] + (state.gridSize / 2) - (state.grid_border[2] / 2)
    state.centerX -= state.speed if inputs.keyboard.key_held.a &&
                                    (state.centerX - state.speed) > state.originalCenter[0] - (state.gridSize / 2) + (state.grid_border[2] / 2)
    state.centerY += state.speed if inputs.keyboard.key_held.w &&
                                    (state.centerY + state.speed) < state.originalCenter[1] + (state.gridSize / 2) - (state.grid_border[3] / 2)
    state.centerY -= state.speed if inputs.keyboard.key_held.s &&
                                    (state.centerY - state.speed) > state.originalCenter[1] - (state.gridSize / 2) + (state.grid_border[3] / 2)
  end
def check_click if inputs . keyboard . key_down . r $dragon . reset end if inputs . mouse . down state . mouse_held = true if inputs . mouse . position . x < state . grid_border [ 0 ] state . tileCords . map do | x , y , order | if inputs . mouse . position . x >= x && inputs . mouse . position . x <= x + state . tileSize && inputs . mouse . position . y >= y && inputs . mouse . position . y <= y + state . tileSize state . tileSelected = order end end end elsif inputs . mouse . up state . mouse_held = false state . mouse_dragging = false end if state . mouse_held && ! inputs . mouse . click && ( ( inputs . mouse . previous_click . point . x - inputs . mouse . position . x ) . abs > 15 || ( inputs . mouse . previous_click . point . y - inputs . mouse . position . y ) . abs > 15 ) state . mouse_dragging = true end if ( ( inputs . mouse . click ) && ( inputs . mouse . click . point . inside_rect? state . grid_border ) ) search_lines ( inputs . mouse . click . point , :click ) elsif ( ( state . mouse_dragging ) && ( inputs . mouse . position . inside_rect? state . grid_border ) ) search_lines ( inputs . mouse . position , :drag ) end state . centerX += state . speed if inputs . keyboard . key_held . d && ( state . centerX + state . speed ) < state . originalCenter [ 0 ] + ( state . gridSize / 2 ) - ( state . grid_border [ 2 ] / 2 ) state . centerX -= state . speed if inputs . keyboard . key_held . a && ( state . centerX - state . speed ) > state . originalCenter [ 0 ] - ( state . gridSize / 2 ) + ( state . grid_border [ 2 ] / 2 ) state . centerY += state . speed if inputs . keyboard . key_held . w && ( state . centerY + state . speed ) < state . originalCenter [ 1 ] + ( state . gridSize / 2 ) - ( state . grid_border [ 3 ] / 2 ) state . centerY -= state . speed if inputs . keyboard . key_held . s && ( state . centerY - state . speed ) > state . originalCenter [ 1 ] - ( state . gridSize / 2 ) + ( state . grid_border [ 3 ] / 2 ) end
Checks if the mouse is being clicked or dragged
Checks if the mouse is being clicked or dragged
# if the "r" key is pressed down #is mouse up or down? # if mouse's x position is inside the grid's borders # perform action on all elements of tileCords collection # if mouse's x position is greater than (or equal to) the starting x position of a tile # and the mouse's x position is also less than (or equal to) the ending x position of that tile, # and the mouse's y position is greater than (or equal to) the starting y position of that tile, # and the mouse's y position is also less than (or equal to) the ending y position of that tile, # (BASICALLY, IF THE MOUSE'S POSITION IS WITHIN THE STARTING AND ENDING POSITIONS OF A TILE) # that tile is selected # otherwise, if the mouse is in the "up" state # mouse is not held down or dragged # mouse needs to be down # must not be first click # Need to move 15 pixels before "drag" # if mouse is clicked inside grid's border, search_lines method is called with click input type # if mouse is dragged inside grid's border, search_lines method is called with drag input type # Changes grid's position on screen by moving it up, down, left, or right. # centerX is incremented by speed if the "d" key is pressed and if that sum is less than # the original left side of the center plus half the grid, minus half the top border of grid. # MOVES GRID RIGHT (increasing x) # centerX is decremented by speed if the "a" key is pressed and if that difference is greater than # the original left side of the center minus half the grid, plus half the top border of grid. # MOVES GRID LEFT (decreasing x) # centerY is incremented by speed if the "w" key is pressed and if that sum is less than # the original bottom of the center plus half the grid, minus half the right border of grid. # MOVES GRID UP (increasing y) # centerY is decremented by speed if the "s" key is pressed and if the difference is greater than # the original bottom of the center minus half the grid, plus half the right border of grid. # MOVES GRID DOWN (decreasing y)