#============================================================================== # 本脚本来自www.66RPG.com,使用和转载请保留此信息 #============================================================================== #============================================================================== # * Animated_Sprite Scripted by: SiR_VaIlHoR # Edited by: 柳柳 #------------------------------------------------------------------------------ # A class for animated sprites. #============================================================================== #66RPG,超级横版战斗脚本简要说明: #默认情况下,把一张战斗图截成4列,>8行,如果感觉4列4帧的动画还不能满足要求,看 #def pose(number,frame = 4),更改=4,以及相关部分。 #战斗图从上到下:前进图,等待图,防御图,挨打图,普通攻击图(默认的武器),施展魔法, #倒地不行了,胜利姿势,自定义武器1,自定义武器2…… #这个脚本的模型是老外编写的,其中参考了XMXS的一个方法,我添加了一些功能,去掉素材限制。 #不同职业拥有的图片数可以不一样,参考工程和录像教学 #============================================================================== # □ RPG::Class #============================================================================== module RPG class Class def name name = @name.split(/,/)[0] return name != nil ? name : '' end def name2 name = @name.split(/,/)[1] return name != nil ? name : '' end end class Weapon def name name = @name.split(/,/)[0] return name != nil ? name : '' end def name2 name = @name.split(/,/)[1] return name != nil ? name : '' end end end class Game_Actor #-------------------------------------------------------------------------- # ● 更改名称 # name : 新的名称 #-------------------------------------------------------------------------- def picturephase name = $data_classes[class_id].name2 return name != nil ? name : "66RPG" end end class Game_Enemy #-------------------------------------------------------------------------- # ● 获取名称 #-------------------------------------------------------------------------- def name name = $data_enemies[@enemy_id].name.split(/,/)[0] return name != nil ? name : '' end def picturephase name = $data_enemies[@enemy_id].name.split(/,/)[1] return name != nil ? name : "66RPG" end end class Animated_Sprite < RPG::Sprite #-------------------------------------------------------------------------- # - Accessible instance variables. #-------------------------------------------------------------------------- attr_accessor :frames # Number of animation frames attr_accessor :delay # Delay time between frames (speed) attr_accessor :frame_width # Width of each frame attr_accessor :frame_height # Height of each frame attr_accessor :offset_x # X coordinate of the 1st frame attr_accessor :offset_y # Y coordinate of all frames attr_accessor :current_frame # Current animation frame attr_accessor :moving # Is the sprite moving? #-------------------------------------------------------------------------- # - Initialize an animated sprite # viewport : Sprite viewport #-------------------------------------------------------------------------- def initialize(viewport = nil) super(viewport) @frame_width, @frame_height = 0, 0 change # A basic change to set initial variables @old = Graphics.frame_count # For the delay method @goingup = true # Increasing animation? (if @rm2k_mode is true) @once = false # Is the animation only played once? @animated = true # Used to stop animation when @once is true end #-------------------------------------------------------------------------- # Comment by RPG # - Change the source rect (change the animation) # frames : Number of animation frames # delay : Frame delay, controls animation speed # offx : X coordinate of the 1st frame # offy : Y coordinate of all frames # startf : Starting frame for animation # once : Is the animation only played once? # rm2k_mode : Animation pattern: 1-2-3-2 if true, 1-2-3-1 if false # # Comment by cybersam # # the rm2k_mode isnt pressent anymore... # if you want that feature then use rm2k or use RPG's scrîpt... #-------------------------------------------------------------------------- def change(frames = 0, delay = 0, offx = 0, offy = 0, startf = 0, once = false) @frames = frames @delay = delay @offset_x, @offset_y = offx, offy @current_frame = startf @once = once x = @current_frame * @frame_width + @offset_x self.src_rect = Rect.new(x, @offset_y, @frame_width, @frame_height) @goingup = true @animated = true end #-------------------------------------------------------------------------- # - Update animation and movement #-------------------------------------------------------------------------- def update super if self.bitmap != nil and delay(@delay) and @animated x = @current_frame * @frame_width + @offset_x self.src_rect = Rect.new(x, @offset_y, @frame_width, @frame_height) @current_frame = (@current_frame + 1) unless @frames == 0 @animated = false if @current_frame == @frames and @once @current_frame %= @frames end end #-------------------------------------------------------------------------- # - Move the sprite # x : X coordinate of the destination point # y : Y coordinate of the destination point # speed : Speed of movement (0 = delayed, 1+ = faster) # delay : Movement delay if speed is at 0 #-------------------------------------------------------------------------- def move(x, y, speed = 1, delay = 0) @destx = x @desty = y @move_speed = speed @move_delay = delay @move_old = Graphics.frame_count @moving = true end #-------------------------------------------------------------------------- # - Move sprite to destx and desty #-------------------------------------------------------------------------- def update_move return unless @moving movinc = @move_speed == 0 ? 1 : @move_speed if Graphics.frame_count - @move_old > @move_delay or @move_speed != 0 self.x += movinc if self.x < @destx self.x -= movinc if self.x > @destx self.y += movinc if self.y < @desty self.y -= movinc if self.y > @desty @move_old = Graphics.frame_count end if @move_speed > 1 # Check if sprite can't reach that point self.x = @destx if (@destx - self.x).abs % @move_speed != 0 and (@destx - self.x).abs <= @move_speed self.y = @desty if (@desty - self.y).abs % @move_speed != 0 and (@desty - self.y).abs <= @move_speed end if self.x == @destx and self.y == @desty @moving = false end end #-------------------------------------------------------------------------- # - Pause animation, but still updates movement # frames : Number of frames #-------------------------------------------------------------------------- def delay(frames) update_move if (Graphics.frame_count - @old >= frames) @old = Graphics.frame_count return true end return false end end #============================================================================= # # here we go... # this makes the scrîpt very easy to implement # just add a new scrîpt above the "Main" scrîpt # and insert this whole thing in there # # as you can see the sprite changing code is from the japanese scrîpt # so the credits for the sprite changin goes to them.... # i edit it a little so it can show more sprites and sprite animations # and added some other stuff... the next things are player movement... # # # # i got the battler changing scrîpt in this scrîpt... # the credits for this goes to the guy who made this... # # ▼▲▼ XRXS11. 戦闘・バトラーモーション ver.0 ▼▲▼ # # since this isnt used anymore... it isnt need for credit anymore... # but i'll let it here since it helped me a lot... # # # as for the ideas... missy provided me with really good ideas # that helped me alot when i didnt find a way to some of these features... # # here one more Credit to place... # its RPG's scrîpt... # not the whole thing here... # but some snipplet you'll know witch one when read the comments # # # if you want some more explaines about this scrîpt... # the most stuff are commented... but if you still have questions or # sugestions then you can contact me # # how or where you can contact me... # at the http://www.rmxp.net forum via pm, email: [email protected] # or via AIM: cych4n or ICQ: 73130840 # # remember this is still in testing phase... # and i'm trying to work on some other additions... like character movements... # but that wont be added now... couse i need to figure it out first... # # # # oh hehe.... before i forget... # sorry for the bad english... ^-^'''' # # #============================================================================== # # here i'm going to tell you what names you need to give for your chara # battle sprites.... # # ok... here... since i'm using RPG's movement scrîpt... # there are a lot of changes... # # when you look at the scrîpt you'll find line with "pose(n)" or "enemy_pose(n)" # since i want my sprites have different sprites... i added one more option # to these... # so now if you add a number after the n (the n stands for witch sprite is used) # fo example 8... ("pose(4, 8)") this will tell the scrîpt that the 4th animation # have 8 frames... # pose is used for the player... and enemy_pose for the enemy... # there is nothing more to this... # i used my old sprite numbers... (this time in only one sprite...) # # explains about the animation sprites... (the digits) # # # 0 = move (during battle) # 1 = standby # 2 = defend # 3 = hit (being attacked) # 4 = attack # 5 = skill use # 6 = dead # 7 = winning pose... this idea is from RPG.... # # # of course this is just the begining of the code... # so more animations can be implemented... # but for now this should be enough... # # alot has changed here... and now it looks like it is done... # of course the fine edit needs to be done so it looks and works great with your # game too... # # # # 1st character movement... done # 2nd character movement during attack... done # 3rd character apears at the enemy while attacking... done # # 4th enemies movement... done # 5th enemy movement during attack... done # 6th enemy apears at the enemy while attacking... done # # 7th each weapon has its own animation... done # 8th each skill has its own animation... done # # # # for the ones interisted... my nex project is an Movie player # (that actualy plays avi, mpgs and such... # but dont think this will be done soon... ^-^'' # # but i'll may be try something else before i begin to code that one... #============================================================================== class Game_Actor < Game_Battler # you dont have to change your game actor to let the characters schows # from the side... # this will do it for you... ^-^ def screen_x if self.index != nil return self.index * 30 + 430 else return 0 end end def screen_y return self.index * 30 + 250 end def screen_z if self.index != nil return self.index else return 0 end end end # RPG's snipplet... class Spriteset_Battle attr_accessor :actor_sprites attr_accessor :enemy_sprites alias original_initialize initialize def initialize #@start_party_number = $game_party.actors.size # ビューポートを作成 @viewport0 = Viewport.new(0, 0, 640, 480) @viewport1 = Viewport.new(0, 0, 640, 320) @viewport2 = Viewport.new(0, 0, 640, 480) @viewport3 = Viewport.new(0, 0, 640, 480) @viewport4 = Viewport.new(0, 0, 640, 480) @viewport1.z = 50 @viewport2.z = 50 @viewport3.z = 200 @viewport4.z = 5000 @battleback_sprite = Sprite.new(@viewport0) @enemy_sprites = [] for enemy in $game_troop.enemies #.reverse @enemy_sprites.push(Sprite_Battler.new(@viewport1, enemy)) end @actor_sprites = [] @actor_sprites.push(Sprite_Battler.new(@viewport2,$game_party.actors[0])) @actor_sprites.push(Sprite_Battler.new(@viewport2,$game_party.actors[1])) @actor_sprites.push(Sprite_Battler.new(@viewport2,$game_party.actors[2])) @actor_sprites.push(Sprite_Battler.new(@viewport2,$game_party.actors[3])) @weather = RPG::Weather.new(@viewport1) @picture_sprites = [] for i in 51..100 @picture_sprites.push(Sprite_Picture.new(@viewport3, $game_screen.pictures[i])) end @timer_sprite = Sprite_Timer.new update end alias original_update update def update @viewport1.z = 50 and @viewport2.z = 51 if $actor_on_top == true @viewport1.z = 51 and @viewport2.z = 50 if $actor_on_top == false # 刷新角色的活动块 (对应角色的替换) @actor_sprites[0].battler = $game_party.actors[0] @actor_sprites[1].battler = $game_party.actors[1] @actor_sprites[2].battler = $game_party.actors[2] @actor_sprites[3].battler = $game_party.actors[3] # 战斗背景的文件名与现在情况有差异的情况下 if @battleback_name != $game_temp.battleback_name @battleback_name = $game_temp.battleback_name if @battleback_sprite.bitmap != nil @battleback_sprite.bitmap.dispose end @battleback_sprite.bitmap = RPG::Cache.battleback(@battleback_name) @battleback_sprite.src_rect.set(0, 0, 640, 480) end # 刷新战斗者的活动块 for sprite in @enemy_sprites + @actor_sprites sprite.update end # 刷新天气图形 @weather.type = $game_screen.weather_type @weather.max = $game_screen.weather_max @weather.update # 刷新图片活动块 for sprite in @picture_sprites sprite.update end # 刷新计时器活动块 @timer_sprite.update # 设置画面的色调与震动位置 @viewport1.tone = $game_screen.tone @viewport1.ox = $game_screen.shake # 设置画面的闪烁色 @viewport4.color = $game_screen.flash_color # 刷新显示端口 @viewport1.update @viewport2.update @viewport4.update end end # end #============================================================================== # Sprite Battler for the Costum Battle System #============================================================================== # here we are making some animations and stuff... # i know its not the best way... # but this is the first working way that i found.... # this needs propper understanding how the animation works... # if you want to change some stuff... # in this i'll not explain much couse its realy easy if you know what you do # otherwise it will take you time to understand it, but i think the one who # is trying to edit this will know what he/she do... ^-^ # # # # here i'll completely replace the "Sprite_Battler" class... # so if you've changed something in there you need to change it here as well # (i think... i didnt tested it... so its up to you) # i'll mark the stuff i added just with --> # # something that need to be explained have a comment... # but its not all commented... # so if you dont know what it means or you just want to know why it is there and # what it does then you need to contact me or anyone who understand this... ^-^ # how you can contact me see above... at the top of this scrîpt... class Sprite_Battler < Animated_Sprite attr_accessor :battler attr_reader :index attr_accessor :target_index attr_accessor :frame_width def initialize(viewport, battler = nil) super(viewport) @battler = battler @pattern_b = 0 # @counter_b = 0 # @index = 0 # if @battler != nil tempbitmap = RPG::Cache.battler(@battler.battler_name, @battler.battler_hue) @frame_width = tempbitmap.width/4 picturephase = @battler.picturephase if picturephase == "66RPG" @frame_height = tempbitmap.height/8 else @frame_height = tempbitmap.height/picturephase.to_i end else @frame_width, @frame_height = 1,1 end # start sprite @battler.is_a?(Game_Enemy) ? enemy_pose(1) : pose(1) @battler_visible = false if $target_index == nil $target_index = 0 end end def index=(index) # @index = index # update # end # def dispose if self.bitmap != nil self.bitmap.dispose end super end def enemy # $target_index += $game_troop.enemies.size $target_index %= $game_troop.enemies.size return $game_troop.enemies[$target_index] # end # def actor # $target_index += $game_party.actors.size $target_index %= $game_party.actors.size return $game_party.actors[$target_index] # end #============================================================================== # here is a snipplet from RPG's scrîpt... # i changed only to lines from this... # # here you can add more sprite poses... if you have more... ^-^ #============================================================================== def pose(number, frames = 4) case number when 0 # run change(frames, 5, 0, 0, 0) when 1 # standby change(frames, 5, 0, @frame_height) when 2 # defend change(frames, 5, 0, @frame_height * 2) when 3 # Hurt, loops change(frames, 5, 0, @frame_height * 3) when 4 # attack no loop change(frames, 5, 0, @frame_height * 4, 0, true) when 5 # skill change(frames, 5, 0, @frame_height * 5) when 6 # death change(frames, 5, 0, @frame_height * 6) when 7 # winning pose change(frames, 5, 0, @frame_height * 7) when 8 # no sprite change(frames, 5, 0, @frame_height * 8) when 9 # no sprite change(frames, 5, 0, @frame_height * 9) when 10 # no sprite change(frames, 5, 0, @frame_height * 10) when 11 # no sprite change(frames, 5, 0, @frame_height * 11) when 12 # no sprite change(frames, 5, 0, @frame_height * 12) when 13 # no sprite change(frames, 5, 0, @frame_height * 13) when 14 # no sprite change(frames, 5, 0, @frame_height * 14) when 15 # no sprite change(frames, 5, 0, @frame_height * 15) when 16 # no sprite change(frames, 5, 0, @frame_height * 16) when 17 # no sprite change(frames, 5, 0, @frame_height * 17) when 18 # no sprite change(frames, 5, 0, @frame_height * 18) when 19 # no sprite change(frames, 5, 0, @frame_height * 19) when 20 # no sprite change(frames, 5, 0, @frame_height * 20) # ...etc. else change(frames, 5, 0, @frame_height * number, 0) end end #-------------------------------------------------------------------------- # - Change the battle pose for an enemy # number : pose' number #-------------------------------------------------------------------------- def enemy_pose(number ,enemy_frames = 4) case number when 0 # run change(enemy_frames, 5, 0, 0, 0) when 1 # standby change(enemy_frames, 5, 0, @frame_height) when 2 # defend change(enemy_frames, 5, 0, @frame_height * 2) when 3 # Hurt, loops change(enemy_frames, 5, 0, @frame_height * 3) when 4 # attack change(enemy_frames, 5, 0, @frame_height * 4, 0, true) when 5 # skill change(enemy_frames, 5, 0, @frame_height * 5) when 6 # death change(enemy_frames, 5, 0, @frame_height * 6) when 7 # no sprite change(enemy_frames, 5, 0, @frame_height * 7) # ...etc. else change(enemy_frames, 5, 0, @frame_height * number, 0) end end #============================================================================== # sniplet end... #============================================================================== def update super if @battler == nil   |