Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #------------------------------------------------------------------------------#
- # Galv's Cam Control
- #------------------------------------------------------------------------------#
- # For: RPGMAKER VX ACE
- # Version 1.4
- # edited by LiTTleDRAgo
- #------------------------------------------------------------------------------#
- # 2013-03-18 - Version 1.4 - fixed a bug where it crashed if you didn't turn
- # - off following an event when transferring to a map
- # - without that event.
- # 2013-03-18 - Version 1.3 - fixed a bug with parallax motion stopping
- # 2013-03-04 - Version 1.2 - re-written script to scroll to targets
- # 2012-10-24 - Version 1.1 - updated alias naming for compatability
- # 2012-10-20 - Version 1.0 - release
- #------------------------------------------------------------------------------#
- # This script allows some control over where the camera is through use of
- # script calls. You can fix the camera to a location on the map or follow an
- # event's movements.
- #------------------------------------------------------------------------------#
- # SCRIPT CALLS:
- #------------------------------------------------------------------------------#
- #
- # cam_follow(event_id,speed) # Camera follows event instead of player
- # cam_center(speed) # Moves camera back to player
- # cam_set(x,y,speed) # Position the camera centered on x, y coordinates
- #
- # # NOTE: speed can be 1 to 6 or you can leave it out of the script call to
- # default to 6. If you want to instantly snap the camera without it
- # scrolling, make speed 0
- #
- #------------------------------------------------------------------------------#
- # EXAMPLES:
- # cam_set(10,5) # Moves camera to map co-ordinates x 10, y5 at speed 6
- # cam_set(10,5,2) # Moves camera to map co-ordinates x 10, y5 at speed 2
- # cam_follow(4) # Moves camera to event 4's location and follows it.
- # cam_follow(4,0) # SNAPS camera to event 4's location and follows it.
- # cam_center # Moves camera to player at speed 6
- # cam_center(0) # Snaps camera to player instantly
- #------------------------------------------------------------------------------#
- # NO OPTIONS FOR YOU TO EDIT. SORRY.
- #------------------------------------------------------------------------------#
- $imported = {} if $imported.nil?
- $imported["Camera_Control"] = true
- class Game_Map
- attr_accessor :cam_target
- alias_method :galv_cam_control_gm_setup, :setup
- def setup(*args)
- @cam_target = 0
- galv_cam_control_gm_setup(*args)
- @scroll_blocked = false
- end
- unless $imported[:drg_diagonal_scroll]
- @@scroll = method_defined?(:do_scroll) ? :do_scroll : :update
- alias_method :update_scrolling_straight, :"#{@@scroll}"
- define_method(:"#{@@scroll}") do |*args|
- update_scrolling_diagonal || 0 && update_scrolling_straight(*args)
- end
- def update_scrolling_diagonal
- if scrolling?
- distance = 2 ** @scroll_speed
- distance = scroll_distance if defined?(scroll_distance)
- case @scroll_direction
- when 1 then [scroll_down(distance), scroll_left(distance) ]
- when 3 then [scroll_down(distance), scroll_right(distance)]
- when 7 then [scroll_up(distance), scroll_left(distance) ]
- when 9 then [scroll_up(distance), scroll_right(distance)]
- end
- end
- end
- end
- def scroll_to_target(x,y,speed)
- x1, y1, dir = @display_x.to_i, @display_y.to_i, 0
- dir = 1 if dir == 0 && y1 < y && x1 > x && scroll_can_move?(2) && scroll_can_move?(4)
- dir = 7 if dir == 0 && y1 > y && x1 > x && scroll_can_move?(8) && scroll_can_move?(4)
- dir = 9 if dir == 0 && y1 > y && x1 < x && scroll_can_move?(8) && scroll_can_move?(6)
- dir = 3 if dir == 0 && y1 < y && x1 < x && scroll_can_move?(2) && scroll_can_move?(6)
- dir = 2 if dir == 0 && y1 < y && scroll_can_move?(2)
- dir = 8 if dir == 0 && y1 > y && scroll_can_move?(8)
- dir = 6 if dir == 0 && x1 < x && scroll_can_move?(6)
- dir = 4 if dir == 0 && x1 > x && scroll_can_move?(4)
- start_scroll(dir, 1, speed) if dir > 0
- @scroll_blocked = dir == 0
- Fiber.yield while scrolling?
- end
- def cannot_scroll?
- @scroll_blocked == true
- end
- def scroll_can_move?(dir)
- case dir
- when 2 then (@display_y % @map.height) < height - (Graphics.height / 32)
- when 4 then (@display_x % @map.width) > 0
- when 6 then (@display_x % @map.width) < width - (Graphics.width / 32)
- when 8 then (@display_y % @map.height) > 0
- end
- end
- def set_event_display_pos(x, y)
- x = [0, [x, width - screen_tile_x].min].max unless loop_horizontal?
- y = [0, [y, height - screen_tile_y].min].max unless loop_vertical?
- @display_x = (x + width) % width
- @display_y = (y + height) % height
- end
- end # Game_Map
- class Game_Player < Game_Character
- alias_method :galv_cam_control_gp_update, :update
- alias_method :galv_cam_control_gp_update_scroll, :update_scroll
- def update(*args)
- if (target = $game_map.cam_target).is_a?(Integer) && target > 0
- e = $game_map.interpreter.get_character(t)
- elsif target.is_a?(Game_Character)
- e = target
- end
- e && $game_map.set_event_display_pos(e.real_x-center_x, e.real_y-center_y)
- galv_cam_control_gp_update(*args)
- end
- def update_scroll(*args)
- return if ($game_map.cam_target ||= 0) != 0
- galv_cam_control_gp_update_scroll(*args)
- end
- end # Game_Player < Game_Character
- class Game_Interpreter
- def cam_center(speed = 6)
- cam_set($game_player.x, $game_player.y, speed)
- $game_map.cam_target = 0
- end
- def cam_set(x,y,speed = 6)
- $game_map.cam_target = -1
- _x = (x - $game_player.center_x).round
- _y = (y - $game_player.center_y).round
- speed > 0 && scroll_to_target(x,y,speed)
- $game_map.set_display_pos(_x, _y)
- end
- def scroll_to_target(x,y,speed)
- _x = (x - $game_player.center_x).round
- _y = (y - $game_player.center_y).round
- loop do
- $game_map.scroll_to_target(_x, _y, speed)
- finish = $game_map.display_x == _x && $game_map.display_y == _y
- break if finish || $game_map.cannot_scroll?
- end
- end
- def scroll_to_event(id,speed)
- char = id.is_a?(Game_Character) ? id : get_character(id)
- char && scroll_to_target(char.x,char.y,speed)
- end
- def cam_follow(event_id, speed = 6)
- $game_map.cam_target = -1
- char = event_id.is_a?(Game_Character) ? event_id : get_character(event_id)
- char && speed > 0 && scroll_to_event(char,speed)
- char && ($game_map.cam_target = char)
- end
- end # Game_Interpreter
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement