[Script] [ACE] [RMVXA] Camera Target

MeoDenLuoiMeoDenLuoi Posts: 1,425Registered
[size=xx-large][align=center]Camera Target[/align][/size]
[chapter]Giới thiệu[/chapter]
Script này giúp cài đặt cho bạn hệ thống Camera để theo dõi 1 character trong map đó, bằng cách sử dụng script calls lên event. Trong lúc bình thường, Camera theo dõi người chơi.
[chapter]Hình ảnh[/chapter]
RxAlh5U.gif
[chapter]Script[/chapter]
[php]=begin
#===============================================================================
Title: Camera Target
Author: Tsukihime
Date: Apr 16, 2013
** Change log
Apr 16, 2013
- initial release
** Terms of Use
* Free to use in commercial/non-commercial projects
* No real support. The script is provided as-is
* Will do bug fixes, but no compatibility patches
* Features may be requested but no guarantees, especially if it is non-trivial
* Credits to Tsukihime in your project
* Preserve this header
** Description

This script allows you to set the camera to follow a particular character
on the map using script calls. By default, the camera follows the player.

** Installation

Place this script below Materials and above Main

** Usage

To set the camera's target, make a script call in the event or move route

set_camera_target(char_id)

If char_id = -1, then it is the player
If char_id = 0, then it is the current event
if char_id > 0, then it is the specified event
#===============================================================================
=end
$imported = {} if $imported.nil?
$imported["TH_CameraTarget"] = true
#===============================================================================
# ** Configuration
#===============================================================================
module TH
module Camera_Target
end
end
#===============================================================================
# ** Rest of script
#===============================================================================
module DataManager
class << self
alias :th_camera_target_create_game_objects :create_game_objects
end
def self.create_game_objects
th_camera_target_create_game_objects
$game_system.camera_target = $game_player
end
end

#
# For convenient script call
#
class Game_Interpreter

#
# Set the camera target. Update mode is how the camera will update its target
# Not implemented yet
#
def set_camera_target(event_id, update_mode=0)
$game_system.camera_target = get_character(event_id)
$game_map.refresh_camera_target(update_mode)
end
end

#
# Camera target stored with the system
#
class Game_System
attr_reader :camera_target

alias :th_camera_target_initialize :initialize
def initialize
th_camera_target_initialize
@camera_target = nil
end

def camera_target=(target)
@camera_target = target
end
end

#
# When the camera target changes, decide whether to update the camera position
# to the current target, and how it should be done
#
class Game_Map
def refresh_camera_target(update_mode)
char = $game_system.camera_target
$game_system.camera_target.center(char.x, char.y)
end
end

#
# Add scrolling logic to all characters
#
class Game_Character < Game_CharacterBase

#
# X Coordinate of Screen Center
#
def center_x
(Graphics.width / 32 - 1) / 2.0
end
#
# Y Coordinate of Screen Center
#
def center_y
(Graphics.height / 32 - 1) / 2.0
end
#
# Set Map Display Position to Center of Screen
#
def center(x, y)
$game_map.set_display_pos(x - center_x, y - center_y)
end

#
# Scroll map depending on character location
#
def update_scroll(last_real_x, last_real_y)
return unless $game_system.camera_target == self
ax1 = $game_map.adjust_x(last_real_x)
ay1 = $game_map.adjust_y(last_real_y)
ax2 = $game_map.adjust_x(@real_x)
ay2 = $game_map.adjust_y(@real_y)
$game_map.scroll_down (ay2 - ay1) if ay2 > ay1 && ay2 > center_y
$game_map.scroll_left (ax1 - ax2) if ax2 < ax1 && ax2 < center_x
$game_map.scroll_right(ax2 - ax1) if ax2 > ax1 && ax2 > center_x
$game_map.scroll_up (ay1 - ay2) if ay2 < ay1 && ay2 < center_y
end
end

#
# Only update scroll if player is the camera target
#
class Game_Player < Game_Character

alias :th_camera_target_update_scroll :update_scroll
def update_scroll(last_real_x, last_real_y)
return unless $game_system.camera_target == self
th_camera_target_update_scroll(last_real_x, last_real_y)
end
end

#
#
#
class Game_Event < Game_Character

#
# Return the specified character by ID
#
def get_character(param)
if $game_party.in_battle
nil
elsif param < 0
$game_player
else
$game_map.events[param > 0 ? param : @id]
end
end

#
# Set the camera target. Used in move route interpreter
#
def set_camera_target(event_id, update_mode=0)
$game_system.camera_target = get_character(event_id)
$game_map.refresh_camera_target(update_mode)
end

alias :th_camera_target_update :update
def update
last_real_x = @real_x
last_real_y = @real_y
th_camera_target_update
update_scroll(last_real_x, last_real_y)
end

alias :th_camera_target_moveto :moveto
def moveto(x, y)
th_camera_target_moveto(x, y)
center(x, y)
end
end[/php]
[chapter]Hướng dẫn[/chapter]
Tạo ra một script call trong event hoặc move route:
set_camera_target(char_id)
Đặc biệt: char_id = -1: Người chơi
char_id = 0: Event hiện tại
char_id > 0, Event được xác định
[chapter]Điều khoản sử dụng[/chapter]
Xài thoải mái, nhưng phải Credit tên tác giả.
[chapter]Credit[/chapter]
Tsukihime

Comments

Sign In or Register to comment.