# rgss-lib =begin ‚c‚pƒVƒXƒeƒ€ƒXƒNƒŠƒvƒg Train_Actor Author:: yf30 at users.sourceforge.jp (http://sourceforge.jp/users/yf30/) Date:: 2009/02/26 Copyright:: Copyright (C) 2004-2009 rgss-lib URL:: http://sourceforge.jp/projects/rgss-lib/ =end # dq # train_actor # Config.rb #============================================================================== # ก Train_Actor::Config #------------------------------------------------------------------------------ # ƒ}ƒbƒvใ‚ลƒAƒNƒ^[‚๐‘เ—๑ˆฺ“ฎ‚ณ‚น‚้ #============================================================================== module Train_Actor TRANSPARENT_SWITCH = false TRANSPARENT_SWITCHES_INDEX = 20 TRAIN_ACTOR_SIZE_MAX = 4 DEAD_CHARACTER_NAME = "Coffin" # ’่” DOWN_LEFT = 1 DOWN_RIGHT = 3 UP_LEFT = 7 UP_RIGHT = 9 JUMP = 5 STOP = 0 end # rgss # Game_Event_Module.rb # Game_Event_Module # ƒ}ƒbƒvใ‚ลƒAƒNƒ^[‚๐‘เ—๑ˆฺ“ฎ‚ณ‚น‚้ # Author:: fukuyama # Date:: 2006/03/05 # Copyright:: Copyright (C) 2005 fukuyama module Train_Actor module Game_Event_Module # ’สs‰ย”\”ป’่ # x:: X ภ•W # y:: Y ภ•W # d:: •๛Œ (0,2,4,6,8) ฆ 0 = ‘S•๛Œ’สs•s‰ย‚ฬ๊‡‚๐”ป’่ (ƒWƒƒƒ“ƒv—p) # return:: ’สs•s‰ย false ‰ย”\ true def passable?(x, y, d) result = super(x, y, d) return result if @through if result # V‚ต‚ขภ•W‚๐‹‚฿‚้ new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0) new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0) # ƒgƒŒƒCƒ“ƒAƒNƒ^[‚ฬƒ‹[ƒv for actor in $game_party.characters # •\Žฆ‚ณ‚๊‚ฤ‚ข‚้๊‡ if (not actor.character_name.empty?) and (not actor.transparent) # ƒAƒNƒ^[‚ฬภ•W‚ชˆฺ“ฎๆ‚ฦˆ๊’v‚ต‚ฝ๊‡ if actor.x == new_x and actor.y == new_y # Žฉ•ช‚ชƒCƒxƒ“ƒg‚ฬ๊‡ if self != $game_player # ’สs•s‰ย return false end end end end end return result end end end class Game_Event include Train_Actor::Game_Event_Module end # Game_Party_Module.rb # Train_Actor::Game_Party_Module # Game_Party—p‘เ—๑•เsƒ‚ƒWƒ…[ƒ‹ # Author:: fukuyama # Date:: 2007/12/31 # Copyright:: Copyright (C) 2005-2007 rgss-lib module Train_Actor module Game_Party_Module attr_reader :characters def dead_actor_include? for actor in actors if actor.dead? return true end end return false end def get_active_party_order if not dead_actor_include? return actors end alive_actors = [] dead_actors = [] for actor in actors if actor.dead? dead_actors.push actor else alive_actors.push actor end end return alive_actors + dead_actors end def setup_actor_character_sprites if @characters.nil? @characters = [] for i in 1 ... TRAIN_ACTOR_SIZE_MAX @characters.push(Game_Party_Actor.new(i - 1)) end end setup_actors = get_active_party_order for i in 1 .. @characters.size @characters[i - 1].setup(setup_actors[i]) end if $scene.class.method_defined?('setup_actor_character_sprites') $scene.setup_actor_character_sprites(@characters) end end def transparent_switch if TRANSPARENT_SWITCH unless $game_player.transparent return $game_switches[TRANSPARENT_SWITCHES_INDEX] end end return $game_player.transparent end def update_party_actors setup_actor_character_sprites transparent = transparent_switch for character in @characters character.transparent = transparent character.update end end def moveto_party_actors( x, y ) setup_actor_character_sprites for character in @characters character.moveto( x, y ) end @move_list = [] move_list_setup end def move_party_actors if @move_list == nil @move_list = [] move_list_setup end @move_list.each_index do |i| if not @characters[i].nil? @characters[i].add_move_list_element(@move_list[i]) end end end class Move_List_Element def initialize(type,args) @type = type @args = args end def type() return @type end def args() return @args end end def move_list_setup for i in 0 .. TRAIN_ACTOR_SIZE_MAX @move_list[i] = nil end end def add_move_list(type,*args) @move_list.unshift(Move_List_Element.new(type,args)).pop end def move_down_party_actors(turn_enabled = true) move_party_actors add_move_list(Input::DOWN,turn_enabled) end def move_left_party_actors(turn_enabled = true) move_party_actors add_move_list(Input::LEFT,turn_enabled) end def move_right_party_actors(turn_enabled = true) move_party_actors add_move_list(Input::RIGHT,turn_enabled) end def move_up_party_actors(turn_enabled = true) move_party_actors add_move_list(Input::UP,turn_enabled) end def move_lower_left_party_actors move_party_actors add_move_list(DOWN_LEFT) end def move_lower_right_party_actors move_party_actors add_move_list(DOWN_RIGHT) end def move_upper_left_party_actors move_party_actors add_move_list(UP_LEFT) end def move_upper_right_party_actors move_party_actors add_move_list(UP_RIGHT) end def jump_party_actors(x_plus, y_plus) move_party_actors add_move_list(JUMP,x_plus, y_plus) move_stop_party_actors end def move_stop_party_actors actors.each do |a| move_party_actors add_move_list(STOP) end end end end class Game_Party include Train_Actor::Game_Party_Module # ƒAƒNƒ^[‚๐‰ม‚ฆ‚้ # actor_id:: ƒAƒNƒ^[ ID def add_actor(actor_id) # ƒAƒNƒ^[‚๐Žๆ“พ actor = $game_actors[actor_id] # ƒp[ƒeƒBl”‚ช 4 l–ข–ž‚ลA‚ฑ‚ฬƒAƒNƒ^[‚ชƒp[ƒeƒB‚ษ‚ข‚ศ‚ข๊‡ if @actors.size < Train_Actor::TRAIN_ACTOR_SIZE_MAX and not @actors.include?(actor) # ƒAƒNƒ^[‚๐’ว‰ม @actors.push(actor) # ƒvƒŒƒCƒ„[‚๐ƒŠƒtƒŒƒbƒVƒ… $game_player.refresh end end end # Game_Player_Module.rb # Train_Actor::Game_Player_Module # Game_Player—p‘เ—๑•เsƒ‚ƒWƒ…[ƒ‹ # Author:: fukuyama # Date:: 2007/12/31 # Copyright:: Copyright (C) 2005-2007 rgss-lib module Train_Actor module Game_Player_Module attr_reader :move_speed attr_reader :step_anime attr_reader :direction_fix def update_party_actors if $game_party.actors.empty? return end $game_party.update_party_actors actor = $game_party.actors[0] if not actor.dead? if not @prev_dead.nil? @character_name = actor.character_name @character_hue = actor.character_hue @prev_dead = nil end return end @prev_dead = true $game_party.actors.each do |actor| if not actor.dead? @character_name = actor.character_name @character_hue = actor.character_hue break end end end def update update_party_actors super end def moveto( x, y ) $game_party.moveto_party_actors( x, y ) super( x, y ) end def move_down(turn_enabled = true) if passable?(@x, @y, Input::DOWN) $game_party.move_down_party_actors(turn_enabled) end super(turn_enabled) end def move_left(turn_enabled = true) if passable?(@x, @y, Input::LEFT) $game_party.move_left_party_actors(turn_enabled) end super(turn_enabled) end def move_right(turn_enabled = true) if passable?(@x, @y, Input::RIGHT) $game_party.move_right_party_actors(turn_enabled) end super(turn_enabled) end def move_up(turn_enabled = true) if passable?(@x, @y, Input::UP) $game_party.move_up_party_actors(turn_enabled) end super(turn_enabled) end def move_lower_left # ‰บจถAถจ‰บ ‚ฬ‚ว‚ฟ‚็‚ฉ‚ฬƒR[ƒX‚ช’สs‰ย”\‚ศ๊‡ if (passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::LEFT)) or (passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::DOWN)) $game_party.move_lower_left_party_actors end super end def move_lower_right # ‰บจ‰EA‰Eจ‰บ ‚ฬ‚ว‚ฟ‚็‚ฉ‚ฬƒR[ƒX‚ช’สs‰ย”\‚ศ๊‡ if (passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::RIGHT)) or (passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::DOWN)) $game_party.move_lower_right_party_actors end super end def move_upper_left # ใจถAถจใ ‚ฬ‚ว‚ฟ‚็‚ฉ‚ฬƒR[ƒX‚ช’สs‰ย”\‚ศ๊‡ if (passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::LEFT)) or (passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::UP)) $game_party.move_upper_left_party_actors end super end def move_upper_right # ใจ‰EA‰Eจใ ‚ฬ‚ว‚ฟ‚็‚ฉ‚ฬƒR[ƒX‚ช’สs‰ย”\‚ศ๊‡ if (passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::RIGHT)) or (passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::UP)) $game_party.move_upper_right_party_actors end super end def jump(x_plus, y_plus) # V‚ต‚ขภ•W‚๐ŒvŽZ new_x = @x + x_plus new_y = @y + y_plus # ‰มŽZ’l‚ช (0,0) ‚ฬ๊‡‚ฉAƒWƒƒƒ“ƒvๆ‚ช’สs‰ย”\‚ศ๊‡ if (x_plus == 0 and y_plus == 0) or passable?(new_x, new_y, 0) $game_party.jump_party_actors(x_plus, y_plus) end super(x_plus, y_plus) end end end class Game_Player include Train_Actor::Game_Player_Module end # Scene_Map_Module.rb # Train_Actor::Scene_Map_Module # Scene_Map—p‘เ—๑•เsƒ‚ƒWƒ…[ƒ‹ # Author:: fukuyama # Date:: 2007/12/31 # Copyright:: Copyright (C) 2005-2007 rgss-lib module Train_Actor module Scene_Map_Module def setup_actor_character_sprites(characters) @spriteset.setup_actor_character_sprites(characters) end end end class Scene_Map include Train_Actor::Scene_Map_Module end # Spriteset_Map_Module.rb # Train_Actor::Spriteset_Map_Module # Spriteset_Map—p‘เ—๑•เsƒ‚ƒWƒ…[ƒ‹ # Author:: fukuyama # Date:: 2007/12/31 # Copyright:: Copyright (C) 2005-2007 rgss-lib module Train_Actor module Spriteset_Map_Module def setup_actor_character_sprites? return @setup_actor_character_sprites_flag != nil end def setup_actor_character_sprites(characters) if not setup_actor_character_sprites? for character in characters.reverse @character_sprites.unshift(Sprite_Character.new(@viewport1, character)) end @setup_actor_character_sprites_flag = true end end end end class Spriteset_Map include Train_Actor::Spriteset_Map_Module end # Game_Party_Actor.rb # Train_Actor::Game_Party_Actor # ƒ}ƒbƒvใ‚ฬƒp[ƒeƒB—pƒLƒƒƒ‰ƒNƒ^[ # Author:: fukuyama # Date:: 2007/12/31 # Copyright:: Copyright (C) 2005-2007 rgss-lib module Train_Actor class Game_Party_Actor < Game_Character def initialize(character_index) super() @character_index = character_index @character_wait = 0 @through = true # •s“ง–พ“x‚ฦ‡ฌ•๛–@‚๐‰Š๚‰ป @opacity = 255 @blend_type = 0 @move_list = [] end def setup(actor) # ƒLƒƒƒ‰ƒNƒ^[‚ฬƒtƒ@ƒCƒ‹–ผ‚ฦF‘Š‚๐’่ if actor.nil? @character_name = "" @character_hue = 0 elsif not actor.dead? # Ž€‚๑‚ล‚้๊‡‚ฦ‚่‚ ‚ฆ‚ธAม‚ต‚ฦ‚ฑc @character_name = actor.character_name @character_hue = actor.character_hue else @character_name = DEAD_CHARACTER_NAME @character_hue = 0 end end def update @move_speed = $game_player.move_speed @step_anime = $game_player.step_anime @opacity = $game_player.opacity @blend_type = $game_player.blend_type @direction_fix = $game_player.direction_fix if @direction_fix @direction = $game_player.direction end update_move_list() super end def screen_z(height = 0) if $game_player.screen_z(height) == 999 return 998 end if $game_player.x == @x and $game_player.y == @y super(height) - 1 else super(height) end end def add_move_list_element(element) @move_list.push(element) if @move_list.size == 1 update_move_list() end end def move_list_size return @move_list.size end def update_move_list() return if moving? return if @move_list.empty? if @move_list[0].type == STOP if @character_index != 0 character = $game_party.characters[@character_index - 1] if character.x == @x and character.y == @y and character.direction == @direction @character_wait = 128 / (2 ** @move_speed) + 1 while character.move_list_size < @move_list.size and @move_list[0].type == STOP @move_list.shift end end end else @character_wait = 0 end if @character_wait > 0 @character_wait -= 1 return end element = @move_list.shift while element.type == STOP element = @move_list.shift end case element.type when Input::DOWN move_down(element.args[0]) when Input::LEFT move_left(element.args[0]) when Input::RIGHT move_right(element.args[0]) when Input::UP move_up(element.args[0]) when DOWN_LEFT move_lower_left when DOWN_RIGHT move_lower_right when UP_LEFT move_upper_left when UP_RIGHT move_upper_right when JUMP jump(element.args[0],element.args[1]) end end def moveto( x, y ) @move_list.clear super(x, y) end #-------------------------------------------------------------------------- # œ ‰บ‚ษˆฺ“ฎ # turn_enabled : ‚ป‚ฬ๊‚ล‚ฬŒ‚ซ•ฯX‚๐‹–‰ย‚ท‚้ƒtƒ‰ƒO #-------------------------------------------------------------------------- def move_down(turn_enabled = true) # ‰บ‚๐Œ‚ญ if turn_enabled turn_down end # ’สs‰ย”\‚ศ๊‡ if passable?(@x, @y, Input::DOWN) # ‰บ‚๐Œ‚ญ turn_down # ภ•W‚๐XV @y = (@y + 1 + $game_map.height) % ($game_map.height) @real_y = (@y - 1) * 128 end end #-------------------------------------------------------------------------- # œ ถ‚ษˆฺ“ฎ # turn_enabled : ‚ป‚ฬ๊‚ล‚ฬŒ‚ซ•ฯX‚๐‹–‰ย‚ท‚้ƒtƒ‰ƒO #-------------------------------------------------------------------------- def move_left(turn_enabled = true) # ถ‚๐Œ‚ญ if turn_enabled turn_left end # ’สs‰ย”\‚ศ๊‡ if passable?(@x, @y, Input::LEFT) # ถ‚๐Œ‚ญ turn_left # ภ•W‚๐XV @x = (@x - 1 + $game_map.width) % ($game_map.width) @real_x = (@x + 1) * 128 end end #-------------------------------------------------------------------------- # œ ‰E‚ษˆฺ“ฎ # turn_enabled : ‚ป‚ฬ๊‚ล‚ฬŒ‚ซ•ฯX‚๐‹–‰ย‚ท‚้ƒtƒ‰ƒO #-------------------------------------------------------------------------- def move_right(turn_enabled = true) # ‰E‚๐Œ‚ญ if turn_enabled turn_right end # ’สs‰ย”\‚ศ๊‡ if passable?(@x, @y, Input::RIGHT) # ‰E‚๐Œ‚ญ turn_right # ภ•W‚๐XV @x = (@x + 1 + $game_map.width) % ($game_map.width) @real_x = (@x - 1) * 128 end end #-------------------------------------------------------------------------- # œ ใ‚ษˆฺ“ฎ # turn_enabled : ‚ป‚ฬ๊‚ล‚ฬŒ‚ซ•ฯX‚๐‹–‰ย‚ท‚้ƒtƒ‰ƒO #-------------------------------------------------------------------------- def move_up(turn_enabled = true) # ใ‚๐Œ‚ญ if turn_enabled turn_up end # ’สs‰ย”\‚ศ๊‡ if passable?(@x, @y, Input::UP) # ใ‚๐Œ‚ญ turn_up # ภ•W‚๐XV @y = (@y - 1 + $game_map.height) % ($game_map.height) @real_y = (@y + 1) * 128 end end end end