Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================#
- # ISS - Position Register
- #==============================================================================#
- # Date Created : 04/28/2011
- # Date Modified : 04/29/2011
- # Created By : IceDragon
- # For Game : S.A.R.A
- # ID : 003
- # Version : 1.0
- #==============================================================================#
- $imported = {} if $imported == nil
- $imported["ISS-PositionRegister"] = true
- #==============================================================================#
- # ISS
- #==============================================================================#
- module ISS
- #==============================================================================#
- # Pos
- #==============================================================================#
- class Pos
- attr_accessor :x # // X
- attr_accessor :y # // Y
- attr_accessor :z # // Z
- def initialize(x, y, z=0) ; @x = x ; @y = y ; @z = z end
- def ==(otherpos)
- return (@x == otherpos.x && @y == otherpos.y && @z == otherpos.z)
- end
- end
- #==============================================================================#
- # PositionRegister
- #==============================================================================#
- class PositionRegister
- attr_accessor :setup_ready
- #--------------------------------------------------------------------------#
- # * method :initialize
- #--------------------------------------------------------------------------#
- def initialize( sizex = 1, sizey = 1, sizez = 1)
- @setup_ready = false
- resize( sizex, sizey, sizez )
- end
- #--------------------------------------------------------------------------#
- # * method :setup
- #--------------------------------------------------------------------------#
- def setup( gm ) # // gm is a Game_Map class used for reference
- resize(gm.width+1, gm.height+1, 2)
- end
- #--------------------------------------------------------------------------#
- # * method :resize
- #--------------------------------------------------------------------------#
- def resize( sizex, sizey, sizez )
- @data = Array.new(sizex).map! { # // X
- Array.new( sizey ).map! { # // Y
- Array.new( sizez ).map! { # // Z
- Array.new(1) } } } # // Characters
- end
- #--------------------------------------------------------------------------#
- # * method :get_at
- #--------------------------------------------------------------------------#
- def get_at( pos ) ; return @data[pos.x][pos.y][pos.z] end
- #--------------------------------------------------------------------------#
- # * method :set_at
- #--------------------------------------------------------------------------#
- def set_at( pos, obj ) ; @data[pos.x][pos.y][pos.z] << obj end
- #--------------------------------------------------------------------------#
- # * method :delete_at
- #--------------------------------------------------------------------------#
- def delete_at( pos, obj )
- @data[pos.x][pos.y][pos.z].delete( obj )
- @data[pos.x][pos.y][pos.z].compact!
- end
- end
- end
- #==============================================================================#
- # Game_Map
- #==============================================================================#
- class Game_Map
- attr_accessor :posRegister
- #--------------------------------------------------------------------------#
- # * alias method :initialize
- #--------------------------------------------------------------------------#
- alias iss003_gm_initialize initialize unless $@
- def initialize
- iss003_gm_initialize
- @posRegister = ::ISS::PositionRegister.new(1, 1, 1)
- end
- #--------------------------------------------------------------------------#
- # * alias method :setup
- #--------------------------------------------------------------------------#
- alias iss003_gmp_setup setup unless $@
- def setup(map_id)
- @posRegister.setup_ready = false
- iss003_gmp_setup(map_id)
- setup_iss003_map( 0 )
- @posRegister.setup_ready = true
- setup_iss003_map( 1 )
- end
- #--------------------------------------------------------------------------#
- # * new method :setup_iss003_map
- #--------------------------------------------------------------------------#
- def setup_iss003_map( part )
- case part
- when 0
- @posRegister.setup( self )
- when 1
- @events.values.each { |e| e.update_pos( :bypass ) }
- end
- end
- #--------------------------------------------------------------------------
- # * Get array of event at designated coordinates
- # x : x-coordinate
- # y : y-coordinate
- #--------------------------------------------------------------------------
- def events_xy(x, y)
- return (@posRegister.get_at(::ISS::Pos.new(x, y)) - [$game_player]).uniq.compact
- end
- end
- #==============================================================================#
- # Game_Character
- #==============================================================================#
- class Game_Character
- attr_accessor :lastpos
- #--------------------------------------------------------------------------#
- # * alias method :initialize
- #--------------------------------------------------------------------------#
- alias iss003_gc_initialize initialize unless $@
- def initialize
- iss003_gc_initialize()
- @lastpos = ::ISS::Pos.new(self.x, self.y, 0)
- @screenrect = Rect.new(0, 0, 544, 416)
- end
- #--------------------------------------------------------------------------#
- # * alias method :moveto
- #--------------------------------------------------------------------------#
- alias iss003_gc_moveto moveto unless $@
- def moveto(x, y)
- iss003_gc_moveto(x, y)
- update_pos( :bypass )
- end
- #--------------------------------------------------------------------------#
- # * alias method :update
- #--------------------------------------------------------------------------#
- alias iss003_gc_update update unless $@
- def update
- iss003_gc_update()
- update_pos( :normal )
- end
- #--------------------------------------------------------------------------#
- # * new method :update_pos
- #--------------------------------------------------------------------------#
- def update_pos( type=:normal )
- return unless $game_map.posRegister.setup_ready
- con = false # // Continue?
- case type
- when :normal ; con = !(@lastpos.x == self.x && @lastpos.y == self.y)
- when :bypass ; con = true
- when :clear ; con = true
- end
- if con
- $game_map.posRegister.delete_at( @lastpos, self )
- return if type == :clear
- @lastpos.x = self.x ; @lastpos.y = self.y
- $game_map.posRegister.set_at(@lastpos, self)
- end
- end
- #--------------------------------------------------------------------------#
- # * new method :onScreen?
- #--------------------------------------------------------------------------#
- def onScreen?
- r = @screenrect
- return ( screen_x >= r.x && screen_x < r.width &&
- screen_y >= r.y && screen_y < r.height )
- end
- end
- #=*==========================================================================*=#
- # ** END OF FILE
- #=*==========================================================================*=#
Advertisement
Add Comment
Please, Sign In to add comment