còn đây là scipr của nó! phải lưu vào chứ
- Spoiler:
- module Caterpillar
#--------------------------------------------------------------------------
# * Maximum Size of Party
#--------------------------------------------------------------------------
MAX_SIZE = 4
#--------------------------------------------------------------------------
# * Switch to Enable Party Followers
# syntax: nil for none (always active) or switch_id
#--------------------------------------------------------------------------
INVISIBLE = nil
#--------------------------------------------------------------------------
# * Switch to Enable Movement
# syntax: nil for none (always active) or switch_id
# note: this does not disable $game_player.moveto(x, y)
#--------------------------------------------------------------------------
ENABLE_MOVEMENT = nil
#--------------------------------------------------------------------------
# * Switch for followers to activate events
# syntax: nil for none (always active) or switch_id
#--------------------------------------------------------------------------
FOLLOWER_EVENTS = nil
#--------------------------------------------------------------------------
# * Do Not Touch
#--------------------------------------------------------------------------
def self.active?(symbol)
value = const_get(symbol)
return value == nil || $game_switches[value]
end
end
- Spoiler:
- class Game_Follower < Game_Character
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :actor
attr_accessor :move_speed
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(actor)
super()
@through = true
@actor = actor
end
#--------------------------------------------------------------------------
# * Set Actor
#--------------------------------------------------------------------------
def actor=(actor)
if actor != @actor
@actor = actor
refresh
end
end
#--------------------------------------------------------------------------
# * Setup
#--------------------------------------------------------------------------
def refresh
if @actor != nil
@character_name = actor.character_name
@character_hue = actor.character_hue
else
@character_name = ''
@character_hue = 0
end
@opacity = 255
@blend_type = 0
end
#--------------------------------------------------------------------------
# * Screen Z
#--------------------------------------------------------------------------
def screen_z(height = 0)
if $game_player.x == @x and $game_player.y == @y
return $game_player.screen_z(height) - 1
end
super(height)
end
#--------------------------------------------------------------------------
# * Same Position Starting Determinant
#--------------------------------------------------------------------------
def check_event_trigger_here(triggers)
result = false
if !Caterpillar.active?(:FOLLOWER_EVENTS)
# If event is running
if $game_system.map_interpreter.running?
return result
end
# All event loops
for event in $game_map.events.values
# If event coordinates and triggers are consistent
if event.x == @x and event.y == @y and triggers.include?(event.trigger)
# If starting determinant is same position event (other than jumping)
if not event.jumping? and event.over_trigger?
event.start
result = true
end
end
end
end
return result
end
#--------------------------------------------------------------------------
# * Front Envent Starting Determinant
#--------------------------------------------------------------------------
def check_event_trigger_there(triggers)
result = false
if !Caterpillar.active?(:FOLLOWER_EVENTS)
# If event is running
if $game_system.map_interpreter.running?
return result
end
# Calculate front event coordinates
new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
# All event loops
for event in $game_map.events.values
# If event coordinates and triggers are consistent
if event.x == new_x and event.y == new_y and
triggers.include?(event.trigger)
# If starting determinant is front event (other than jumping)
if not event.jumping? and not event.over_trigger?
event.start
result = true
end
end
end
# If fitting event is not found
if result == false
# If front tile is a counter
if $game_map.counter?(new_x, new_y)
# Calculate 1 tile inside coordinates
new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
# All event loops
for event in $game_map.events.values
# If event coordinates and triggers are consistent
if event.x == new_x and event.y == new_y and
triggers.include?(event.trigger)
# If starting determinant is front event (other than jumping)
if not event.jumping? and not event.over_trigger?
event.start
result = true
end
end
end
end
end
end
return result
end
#--------------------------------------------------------------------------
# * Touch Event Starting Determinant
#--------------------------------------------------------------------------
def check_event_trigger_touch(x, y)
result = false
if !Caterpillar.active?(:FOLLOWER_EVENTS)
# If event is running
if $game_system.map_interpreter.running?
return result
end
# All event loops
for event in $game_map.events.values
# If event coordinates and triggers are consistent
if event.x == x and event.y == y and [1,2].include?(event.trigger)
# If starting determinant is front event (other than jumping)
if not event.jumping? and not event.over_trigger?
event.start
result = true
end
end
end
end
return result
end
end
- Spoiler:
- class Spriteset_Map
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
# Make viewports
@viewport1 = Viewport.new(0, 0, 640, 480)
@viewport2 = Viewport.new(0, 0, 640, 480)
@viewport3 = Viewport.new(0, 0, 640, 480)
@viewport2.z = 200
@viewport3.z = 5000
# Make tilemap
@tilemap = Tilemap.new(@viewport1)
@tilemap.tileset = RPG::Cache.tileset($game_map.tileset_name)
for i in 0..6
autotile_name = $game_map.autotile_names[i]
@tilemap.autotiles[i] = RPG::Cache.autotile(autotile_name)
end
@tilemap.map_data = $game_map.data
@tilemap.priorities = $game_map.priorities
# Make panorama plane
@panorama = Plane.new(@viewport1)
@panorama.z = -1000
# Make fog plane
@fog = Plane.new(@viewport1)
@fog.z = 3000
# Make character sprites
@character_sprites = []
for i in $game_map.events.keys.sort
sprite = Sprite_Character.new(@viewport1, $game_map.events[i])
@character_sprites.push(sprite)
end
@character_sprites.push(Sprite_Character.new(@viewport1, $game_player))
$game_party.followers.each do |char|
@character_sprites << Sprite_Character.new(@viewport1, char)
end
# Make weather
@weather = RPG::Weather.new(@viewport1)
# Make picture sprites
@picture_sprites = []
for i in 1..50
@picture_sprites.push(Sprite_Picture.new(@viewport2,
$game_screen.pictures[i]))
end
# Make timer sprite
@timer_sprite = Sprite_Timer.new
# Frame update
update
end
end
- Spoiler:
- class Game_Party
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :followers
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
alias_method :trick_caterpillar_party_initialize, :initialize
def initialize
trick_caterpillar_party_initialize
@followers = Array.new(Caterpillar::MAX_SIZE - 1) {Game_Follower.new(nil)}
@move_list = Array.new(Caterpillar::MAX_SIZE - 1) {nil}
end
#--------------------------------------------------------------------------
# * Update Followers
#--------------------------------------------------------------------------
def update_followers
transparent = !(Caterpillar.active?(:INVISIBLE) ? true :
$game_player.transparent)
@followers.each_with_index do |char, i|
char.actor = @actors[i + 1]
char.transparent = transparent
char.move_speed = $game_player.move_speed
char.update
end
end
#--------------------------------------------------------------------------
# * Move To Party
#--------------------------------------------------------------------------
def moveto_party(x, y)
@followers.each {|char| char.moveto(x, y)}
@move_list.fill(nil)
end
#--------------------------------------------------------------------------
# * Move Party
#--------------------------------------------------------------------------
def move_party
@move_list.each_index do |i|
case @move_list[i].type
when 2
@followers[i].move_down(*@move_list[i].args)
when 4
@followers[i].move_left(*@move_list[i].args)
when 6
@followers[i].move_right(*@move_list[i].args)
when 8
@followers[i].move_up(*@move_list[i].args)
when 1
@followers[i].move_lower_left
when 3
@followers[i].move_lower_right
when 7
@followers[i].move_upper_left
when 9
@followers[i].move_upper_right
when 5
@followers[i].jump(*@move_list[i].args)
end
end
end
#--------------------------------------------------------------------------
# * Add Move List
#--------------------------------------------------------------------------
def update_move(type, *args)
if Caterpillar.active?(:ENABLE_MOVEMENT)
move_party
@move_list.unshift(Game_MoveListElement.new(type, args))
@move_list.pop
end
end
end
Game_MoveListElement = Struct.new(:type, :args)
- Spoiler:
- class Game_Player
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :move_speed
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------
alias_method :trick_caterpillar_player_update, :update
def update
$game_party.update_followers
trick_caterpillar_player_update
end
#--------------------------------------------------------------------------
# * Moveto
#--------------------------------------------------------------------------
alias_method :trick_caterpillar_player_moveto, :moveto
def moveto(x, y)
$game_party.moveto_party(x, y)
trick_caterpillar_player_moveto(x, y)
end
#--------------------------------------------------------------------------
# * Move Down
#--------------------------------------------------------------------------
alias_method :trick_caterpillar_player_move_down, :move_down
def move_down(turn_enabled = true)
if passable?(@x, @y, 2)
$game_party.update_move(2, turn_enabled)
end
trick_caterpillar_player_move_down(turn_enabled)
end
#--------------------------------------------------------------------------
# * Move Left
#--------------------------------------------------------------------------
alias_method :trick_caterpillar_player_move_left, :move_left
def move_left(turn_enabled = true)
if passable?(@x, @y, 4)
$game_party.update_move(4, turn_enabled)
end
trick_caterpillar_player_move_left(turn_enabled)
end
#--------------------------------------------------------------------------
# * Move Right
#--------------------------------------------------------------------------
alias_method :trick_caterpillar_player_move_right, :move_right
def move_right(turn_enabled = true)
if passable?(@x, @y, 6)
$game_party.update_move(6, turn_enabled)
end
trick_caterpillar_player_move_right(turn_enabled)
end
#--------------------------------------------------------------------------
# * Move Up
#--------------------------------------------------------------------------
alias_method :trick_caterpillar_player_move_up, :move_up
def move_up(turn_enabled = true)
if passable?(@x, @y,
$game_party.update_move(8, turn_enabled)
end
trick_caterpillar_player_move_up(turn_enabled)
end
#--------------------------------------------------------------------------
# * Move Lower Left
#--------------------------------------------------------------------------
alias_method :trick_caterpillar_player_move_lower_left, :move_lower_left
def move_lower_left
if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) or
(passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
$game_party.update_move(1)
end
trick_caterpillar_player_move_lower_left
end
#--------------------------------------------------------------------------
# * Move Lower Right
#--------------------------------------------------------------------------
alias_method :trick_caterpillar_player_move_lower_right, :move_lower_right
def move_lower_right
if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) or
(passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
$game_party.update_move(3)
end
trick_caterpillar_player_move_lower_right
end
#--------------------------------------------------------------------------
# * Move Upper Left
#--------------------------------------------------------------------------
alias_method :trick_caterpillar_player_move_upper_left, :move_upper_left
def move_upper_left
if (passable?(@x, @y, and passable?(@x, @y - 1, 4)) or
(passable?(@x, @y, 4) and passable?(@x - 1, @y, )
$game_party.update_move(7)
end
trick_caterpillar_player_move_upper_left
end
#--------------------------------------------------------------------------
# * Move Upper Right
#--------------------------------------------------------------------------
alias_method :trick_caterpillar_player_move_upper_right, :move_upper_right
def move_upper_right
if (passable?(@x, @y, and passable?(@x, @y - 1, 6)) or
(passable?(@x, @y, 6) and passable?(@x + 1, @y, )
$game_party.update_move(9)
end
trick_caterpillar_player_move_upper_right
end
#--------------------------------------------------------------------------
# * Move Upper Right
#--------------------------------------------------------------------------
alias_method :trick_caterpillar_player_jump, :jump
def jump(x_plus, y_plus)
new_x = @x + x_plus
new_y = @y + y_plus
if (x_plus == 0 and y_plus == 0) or passable?(new_x, new_y, 0)
$game_party.update_move(5, x_plus, y_plus)
end
trick_caterpillar_player_jump(x_plus, y_plus)
end
end