Report abuse


			
class Edit
  def initialize map
    @screen = Map_screen.new
    @map = Map_render.new(map,@screen)
    @file = File.new
    @mouse = Mouse_input.new
    @map.image
    @map.render
    edit_mode
  end
  def change event
    #Compare x and y  until the value are greater and then map the last points.
    #Purpose is to determine the relative locations of the mouse in which squares
    #Start at negative 1 because @map['points'] contains array element and array start with 0
    max = 0
    square = -1
    while (1)
      #Deal with x position; square increase by 1
      if event.pos[0] >= max
        max +=50
        square += 1
      else
        #So the square will appear where the mouse is..relatively
        square -=16
        max = 0
        break
      end
    end
    while (1)
      #Deal with y position; square increase by 16
      if event.pos[1] >= max
        max +=50
        square += 16
      else
        break
      end
    end
    if @map.map['points'][square] == nil
      @map.map['points'][square] = 0
    else
      @map.map['points'][square] += 1
      if @map.map['points'][square] == 7
        @map.map['points'][square] = 0
      end
    end
    @map.render
  end
  def edit_mode
    q = Rubygame::Queue.instance()
    while 1
      q.get.each do |event|
        case event
          when Rubygame::MouseMotionEvent
            @mouse.pos(event)
          when Rubygame::MouseDownEvent
            case event.button
              when Rubygame::MOUSE_LEFT
                change(event)
            end
          when Rubygame::KeyDownEvent
            case event.key
              when Rubygame::K_ESCAPE
                save(@map , @name)
                exit
            end  
          when Rubygame::QuitEvent
            exit
        end
      end
      @mouse.undraw(@screen.screen,@screen.background)
      @mouse.update
      @mouse.draw(@screen.screen)
      @screen.screen.flip
    end
  end
end