Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================#
- # ASR Map Picture Collision v0.8.1
- # Require : Vicky pixel movement
- #-------------------------------------------------------------------------------
- # How to use :
- #-------------------------------------------------------------------------------
- # > Siapin gambar buat collisionnya
- # > Warna buat collision harus sama kek di config bawah ↓
- # > Masukin gambar ke parallax
- # > Masukin tag <cm=nama_gambarnya> di note map
- #-------------------------------------------------------------------------------
- # Extra note :
- # Potentially buggy ~ =w=a
- #==============================================================================#
- module ASR
- #-----------------------------------------------------------------------------
- # Jangan diutak-atik
- #-----------------------------------------------------------------------------
- def self.color(hex, alpha=255)
- r = hex[0, 2].to_i(16)
- g = hex[2, 2].to_i(16)
- b = hex[4, 2].to_i(16)
- return Color.new(r, g, b, alpha)
- end
- COLLISION = ASR.color("ff0000") # Hexacode warnanya
- SHOW_PIC_COLLISION = true # Tampilin gambar?
- end
- #==============================================================================#
- # End of safe zone
- #==============================================================================#
- class Game_CharacterBase
- def passable?(x, y, d)
- x = fix_position(x)
- y = fix_position(y)
- passable1 = passable_tile?(x, y, d)
- passable2 = character_collision?(x, y, d)
- fix_movement(x, y, d) if player? && !passable1 && passable2
- fix_collision(x, y, d) if player? && !passable2 #&& passable1
- passable1 && passable2
- end
- def out_of_screen?
- rx = (@x * 32).floor
- rx2 = rx + bw * 32
- ry = (@y * 32).floor
- ry2 = ry + bh * 32
- end
- alias asr_pixel_collide_passable_tile? passable_tile?
- def passable_tile?(x, y, d)
- return asr_pixel_collide_passable_tile?(x, y, d) unless
- $game_map.use_pic_collision?
- case d
- when 2
- y += distance_per_frame + 0.1
- when 4
- x -= distance_per_frame + 0.1
- when 6
- x += distance_per_frame + 0.1
- when 8
- y -= distance_per_frame + 0.1
- end
- rx = (x * 32).floor
- rx2 = rx + bw * 32
- ry = (y * 32).floor
- ry2 = ry + bh * 32
- if debug_through?
- return !(rx < 0 || rx2 > Graphics.width || ry < 0 ||
- ry2 > Graphics.height)
- end
- top_left = Coordinate.new(rx,ry)
- top_right = Coordinate.new(rx2,ry)
- bottom_left = Coordinate.new(rx,ry2)
- bottom_right = Coordinate.new(rx2,ry2)
- dircheck = {}
- dircheck[2] = [bottom_left, bottom_right]
- dircheck[4] = [top_left, bottom_left]
- dircheck[6] = [top_right, bottom_right]
- dircheck[8] = [top_left, top_right]
- to_check = dircheck[d]
- result = to_check.any? do |point|
- $game_temp.pic_collision.get_pixel(point.x, point.y) == ASR::COLLISION
- end
- return !result
- end
- end
- class Game_Map
- alias asr_setup_map setup
- def setup(map_id)
- asr_setup_map(map_id)
- setup_pic_collision
- end
- def use_pic_collision?
- @pic_collision
- end
- def setup_pic_collision
- @pic_collision = nil
- if @map.note[/<cm:\s*(.+)>/i]
- @pic_collision = $1.to_s
- end
- $game_temp.pic_collision = Cache.parallax(@pic_collision) if @pic_collision
- end
- end
- class Game_Temp
- attr_accessor :pic_collision
- end
- class Scene_Map
- alias addon_start start
- def start
- addon_start
- setup_pic_collision
- end
- def setup_pic_collision
- @collision.dispose if @collision
- return unless ASR::SHOW_PIC_COLLISION
- @collision = Sprite.new
- @collision.bitmap = $game_temp.pic_collision
- @collision.opacity = 128
- end
- alias asr_pic_collision_update update
- def update
- asr_pic_collision_update
- setup_pic_collision if $game_map.need_refresh
- end
- alias asr_pic_collision_terminate terminate
- def terminate
- asr_pic_collision_terminate
- @collision.dispose if @collision
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment