Diagonal Map Scrolling
#1
This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.


Directions are in the comments. As usual, put it just before "Main".

Code:
#----------------------------------------------------------------------------
#Diagonal scrolling tool by Khatharr.
#To use, simply invoke $game_map.start_diag(x, y, speed).
#X and Y are in map tiles.
#Note that speed can be any integer number.
#A speed of 1 is very slow and a speed of 6 is pretty fast,
#so you may wish to tinker with it if you like.  Integers only, though.
#http://www.dubealex.com
#----------------------------------------------------------------------------
class Game_Map
  #----------------------------------------------------------------------------
  alias k_dscroller_init initialize
  alias k_dscroller_upd update
  #----------------------------------------------------------------------------
  def initialize
    k_dscroller_init
    @diag_rest = 0
  end
  #----------------------------------------------------------------------------
  def update
    if @diag_rest > 0
      @diag_rest -= 1
      ary = @line[@diag_rest]
      @display_x = ary[0]
      @display_y = ary[1]
      k_dscroller_upd
    end
  end
  #----------------------------------------------------------------------------
  def start_diag(x, y, speed)
    speed *= 2
    x = (x - 9.5) * 128
    y = (y - 7) * 128
    xlen = @display_x - x
    ylen = @display_y - y
    len = Math.hypot(xlen, ylen)
    @line = []
    @line.push([@display_x, @display_y])
    for i in 1..len
      @line.push([(@display_x - ((xlen / len) * i)).to_i, (@display_y - ((ylen / len) * i)).to_i])
    end
    for i in 1..speed
      for a in 0...@line.size
        if a % 2 == 0
          @line.delete_at(a)
        end
      end
    end
    @line.push([x, y])
    @diag_rest = @line.size
    @line.reverse!
  end
  #----------------------------------------------------------------------------
  def scrolling?
    return true if @scroll_rest > 0
    return true if @diag_rest > 0
    return false
  end
  #----------------------------------------------------------------------------
end
#---------------------------End of script---------------------------
}


Possibly Related Threads…
Thread Author Replies Views Last Post
  Equipment Scrolling System Legacy 0 2,499 05-12-2006, 01:00 PM
Last Post: Legacy
  Scrolling Selectable Menu Ultrapokemaniac 0 2,565 01-08-2006, 01:00 PM
Last Post: Ultrapokemaniac



Users browsing this thread: 1 Guest(s)