#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-# # Zexion's Movement & Animation Script #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-# #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-# # Instructions: # If you want 8-directional movement, set the below to true otherwise set to # false. # # The standing pose is the first pose of the characterset. Default style rtp # does not need a standing pose. This could be used to make charsets smaller. # # For a standard charset, no mod is needed: # Charset.png # # For a charset with more walking frames: # Charset cs_[5].png # # For a charset with a standing frame: # Charset stn.png # # For a charset with vertical correction: (Fixes the charset appearing "too high") # Charset v_[50].png [50] is the y offset of the graphic. Must be POSITIVE # # For a charset with 8-directional poses: # Charset iso.png # # You can use one or all of the tags. (Two is fine also, haha.) # Charset cs_[8] v_[50] iso stn.png # That is the setup for an isometric charset with a vertical correction of 50 # and 8 walking frames. # (if you need a vertical correction of 50, you should prob edit the charset XD) # #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-# # Configuration #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-# module ANIM_DATA ISO_TAG = "iso" # Tag for 8 pose charset. EIGHT_DIR = true # Does not require certain number # of frames, or custom charset. STND_TAG = "stn" # This uses the first pose as # a standing pose. Useful for # larger animation sheets. ANIMATION_SPEED = 3.5 # This speeds up walking animations # when they are above 6 frames long # Because they appear slower than # normal walking animations. # Leave at 3.5 for best results. # Good ranges are 2-4 # Decimals are accepted end #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-# # This section by: # Dirtie # 16th December 2006 #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-# class Game_Actor < Game_Battler #-------------------------------------------------------------------------- # * Get Number of Frames for Character Graphic #-------------------------------------------------------------------------- def character_frames @character_name.gsub(/cs\_(\d)/) do if $1 != @character_name return $1.to_i end end return 4 end end class Sprite_Character < RPG::Sprite #-------------------------------------------------------------------------- # * Get Number of Frames for Character Graphic #-------------------------------------------------------------------------- def character_frames @character_name.gsub(/cs\_(\d)/) do if $1 != @character_name return $1.to_i end end return 4 end end class Game_Character #-------------------------------------------------------------------------- # * Get Number of Frames for Character Graphic #-------------------------------------------------------------------------- def character_frames @character_name.gsub(/cs\_(\d)/) do if $1 != @character_name return $1.to_i end end return 4 end #-------------------------------------------------------------------------- # * Get Vertical Adjustment for Character Graphic #-------------------------------------------------------------------------- def character_adjust_y @character_name.gsub(/v\_(\d+)/) do if $1 != @character_name return $1.to_i end end return nil end end class Window_Base < Window #-------------------------------------------------------------------------- # * Draw Graphic (modified lines marked) # actor : actor # x : draw spot x-coordinate # y : draw spot y-coordinate #-------------------------------------------------------------------------- def draw_actor_graphic(actor, x, y) bitmap = RPG::Cache.character(actor.character_name, actor.character_hue) cw = bitmap.width / actor.character_frames if actor.character_name.include?(ANIM_DATA::ISO_TAG) ch = bitmap.height / 8 else ch = bitmap.height / 4 end src_rect = Rect.new(0, 0, cw, ch) self.contents.blt(x - cw / 2, y - ch, bitmap, src_rect) end end #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-# # End of section by: Dirtie #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-# #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-# # This section by: # DerVVulfman # With small edits by Zexion to allow custom amounts of frames. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-# class Game_Character #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_reader :step_anime # Holds a sprite's step flag attr_reader :walk_anime # Holds an event's movement flag attr_reader :stop_count # The number of steps left to count attr_reader :jump_count # The number of steps in a jump #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update # Branch with jumping, moving, and stopping if jumping? update_jump elsif moving? update_move else update_stop end # If animation count exceeds maximum value # * Maximum value is move speed * 1 taken from basic value 18 if self.character_frames > 6 if @anime_count > 18 - @move_speed * ANIM_DATA::ANIMATION_SPEED # If stop animation is OFF when stopping if not @step_anime and @stop_count > 0 # Return to original pattern @pattern = @original_pattern # If stop animation is ON when moving else # Update pattern @pattern = (@pattern + 1) % self.character_frames end # Clear animation count @anime_count = 0 end else if @anime_count > 18 - @move_speed * 2 # If stop animation is OFF when stopping if not @step_anime and @stop_count > 0 # Return to original pattern @pattern = @original_pattern # If stop animation is ON when moving else # Update pattern @pattern = (@pattern + 1) % self.character_frames end # Clear animation count @anime_count = 0 end end # If waiting if @wait_count > 0 # Reduce wait count @wait_count -= 1 return end # If move route is forced if @move_route_forcing # Custom move move_type_custom return end # When waiting for event execution or locked if @starting or lock? # Not moving by self return end # If stop count exceeds a certain value (computed from move frequency) if @stop_count > (40 - @move_frequency * 2) * (6 - @move_frequency) # Branch by move type case @move_type when 1 # Random move_type_random when 2 # Approach move_type_toward_player when 3 # Custom move_type_custom end end end #-------------------------------------------------------------------------- # * Move Lower Left #-------------------------------------------------------------------------- def move_lower_left # If no direction fix unless @direction_fix turn_down_left end # When a down to left or a left to down course is passable if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) or (passable?(@x, @y, 4) and passable?(@x - 1, @y, 2)) # Update coordinates @x -= 1 @y += 1 # Increase steps increase_steps end end #-------------------------------------------------------------------------- # * Move Lower Right #-------------------------------------------------------------------------- def move_lower_right # If no direction fix unless @direction_fix turn_down_right end # When a down to right or a right to down course is passable if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) or (passable?(@x, @y, 6) and passable?(@x + 1, @y, 2)) # Update coordinates @x += 1 @y += 1 # Increase steps increase_steps end end #-------------------------------------------------------------------------- # * Move Upper Left #-------------------------------------------------------------------------- def move_upper_left # If no direction fix unless @direction_fix turn_up_left end # When an up to left or a left to up course is passable if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) or (passable?(@x, @y, 4) and passable?(@x - 1, @y, 8)) # Update coordinates @x -= 1 @y -= 1 # Increase steps increase_steps end end #-------------------------------------------------------------------------- # * Move Upper Right #-------------------------------------------------------------------------- def move_upper_right # If no direction fix unless @direction_fix turn_up_right end # When an up to right or a right to up course is passable if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) or (passable?(@x, @y, 6) and passable?(@x + 1, @y, 8)) # Update coordinates @x += 1 @y -= 1 # Increase steps increase_steps end end #-------------------------------------------------------------------------- # * Turn Up Left (Added for diagonal animation) #-------------------------------------------------------------------------- def turn_up_left unless @direction_fix if @character_name.include?(ANIM_DATA::ISO_TAG) @direction = 7 else # Face left if facing right, and face up if facing down @direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction) end end end #-------------------------------------------------------------------------- # * Turn Up Right (Added for diagonal animation) #-------------------------------------------------------------------------- def turn_up_right unless @direction_fix if @character_name.include?(ANIM_DATA::ISO_TAG) @direction = 9 else # Face right if facing left, and face up if facing down @direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction) end end end #-------------------------------------------------------------------------- # * Turn Down Left (Added for diagonal animation) #-------------------------------------------------------------------------- def turn_down_left unless @direction_fix if @character_name.include?(ANIM_DATA::ISO_TAG) # Face down-left @direction = 1 else # Face down is facing right or up @direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction) end end end #-------------------------------------------------------------------------- # * Turn Down Right (Added for diagonal animation) #-------------------------------------------------------------------------- def turn_down_right unless @direction_fix if @character_name.include?(ANIM_DATA::ISO_TAG) @direction = 3 else # Face right if facing left, and face down if facing up @direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction) end end end #------------------------------------------------------------------------ # * Move Random #------------------------------------------------------------------------ def move_random case rand(8) when 0 ; move_down(false) when 1 ; move_left(false) when 2 ; move_right(false) when 3 ; move_up(false) when 4 ; move_lower_left when 5 ; move_lower_right when 6 ; move_upper_left when 7 ; move_upper_right end end #------------------------------------------------------------------------ # * Move Toward Player #------------------------------------------------------------------------ def move_toward_player sx = @x - $game_player.x sy = @y - $game_player.y return if sx == 0 and sy == 0 abs_sx = sx.abs abs_sy = sy.abs if abs_sx == abs_sy rand(2) == 0 ? abs_sx += 1 : abs_sy += 1 end if abs_sx move_upper_right if sx < 0 and sy > 0 move_upper_left if sx > 0 and sy > 0 move_lower_left if sx > 0 and sy < 0 move_lower_right if sx < 0 and sy < 0 move_right if sx < 0 move_left if sx > 0 move_up if sy > 0 move_down if sy < 0 end end #------------------------------------------------------------------------ # * Move Away from Player #------------------------------------------------------------------------ def move_away_from_player sx = @x - $game_player.x sy = @y - $game_player.y return if sx == 0 and sy == 0 abs_sx = sx.abs abs_sy = sy.abs if abs_sx == abs_sy rand(2) == 0 ? abs_sx += 1 : abs_sy += 1 end if abs_sx move_lower_left if sx < 0 and sy > 0 move_lower_right if sx > 0 and sy > 0 move_upper_right if sx > 0 and sy < 0 move_upper_left if sx < 0 and sy < 0 move_left if sx < 0 move_right if sx > 0 move_down if sy > 0 move_up if sy < 0 end end #-------------------------------------------------------------------------- # * Set Custom Animation #-------------------------------------------------------------------------- def set_custom_anim return if @animating @frame_count = self.character_frames @animating = true @anim_wait = 40 @pattern = 0 @direction_fix = true end end #============================================================================== # ** Sprite_Character #------------------------------------------------------------------------------ # This sprite is used to display the character.It observes the Game_Character # class and automatically changes sprite conditions. #============================================================================== class Sprite_Character < RPG::Sprite #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :character # character attr_accessor :pattern #-------------------------------------------------------------------------- # * Object Initialization # viewport : viewport # character : character (Game_Character) #-------------------------------------------------------------------------- def initialize(viewport, character = nil) super(viewport) @character = character update end #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update super # If tile ID, file name, or hue are different from current ones if @tile_id != @character.tile_id or @character_name != @character.character_name or @character_hue != @character.character_hue # Remember tile ID, file name, and hue @tile_id = @character.tile_id @character_name = @character.character_name @character_hue = @character.character_hue # If tile ID value is valid if @tile_id >= 384 self.bitmap = RPG::Cache.tile($game_map.tileset_name, @tile_id, @character.character_hue) self.src_rect.set(0, 0, 32, 32) self.ox = 16 self.oy = 32 # If tile ID value is invalid else self.bitmap = RPG::Cache.character(@character.character_name, @character.character_hue) if @character.character_name.include?(ANIM_DATA::ISO_TAG) if @character.character_name.include?(ANIM_DATA::STND_TAG) @cw = bitmap.width / (self.character_frames + 1) @ch = bitmap.height / 8 else @cw = bitmap.width / self.character_frames @ch = bitmap.height / 8 end else if @character.character_name.include?(ANIM_DATA::STND_TAG) @cw = bitmap.width / (self.character_frames + 1) @ch = bitmap.height / 4 else @cw = bitmap.width / self.character_frames @ch = bitmap.height / 4 end end self.ox = @cw if @character.character_adjust_y != nil self.oy = @ch - @character.character_adjust_y else self.oy = @ch end end end # Set visible situation self.visible = (not @character.transparent) # If graphic is character if @tile_id == 0 if not @character.step_anime and @character.stop_count > 0 sx = (@character.pattern) * @cw else if @character.walk_anime if @character.character_name.include?(ANIM_DATA::STND_TAG) sx = (@character.pattern + 1) * @cw else sx = (@character.pattern) * @cw end end # Basic direction value dir = @character.direction # If a custom character in use if @character.character_name.include?(ANIM_DATA::ISO_TAG) dec = (dir == 7 or dir== 9) ? 3 : 1 # directional movement. sy = (dir - dec) * @ch else sy = (dir - 2) / 2 * @ch end # Typical block transfer self.src_rect.set(sx, sy, @cw, @ch) end # Set sprite coordinates self.x = @character.screen_x self.y = @character.screen_y self.z = @character.screen_z(@ch) # Set opacity level, blend method, and bush depth self.opacity = @character.opacity self.blend_type = @character.blend_type self.bush_depth = @character.bush_depth # Animation if @character.animation_id != 0 animation = $data_animations[@character.animation_id] animation(animation, true) @character.animation_id = 0 end end end #============================================================================== # ** Game_Player #------------------------------------------------------------------------------ # This class handles the player. Its functions include event starting # determinants and map scrolling. Refer to "$game_player" for the one # instance of this class. #============================================================================== class Game_Player < Game_Character @@poin1 = 0 @@poin2 = 0 @@wait_time = 0 #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :waiting attr_accessor :wait_time #------------------------------------------------------------------------ # * Update Character Movement #------------------------------------------------------------------------ def update last_moving = moving? #---------------------------------------------------------------------- # * Movement Handling #---------------------------------------------------------------------- unless moving? or $game_system.map_interpreter.running? or @move_route_forcing or $game_temp.message_window_showing if ANIM_DATA::EIGHT_DIR == true case Input.dir8 when 1 ; move_lower_left when 3 ; move_lower_right when 7 ; move_upper_left when 9 ; move_upper_right when 2 ; move_down when 4 ; move_left when 6 ; move_right when 8 ; move_up end else case Input.dir4 when 2 ; move_down when 4 ; move_left when 6 ; move_right when 8 ; move_up end end end #---------------------------------------------------------------------- # * Screen Positioning #---------------------------------------------------------------------- last_real_x = @real_x last_real_y = @real_y super if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y $game_map.scroll_down(@real_y - last_real_y) end if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X $game_map.scroll_left(last_real_x - @real_x) end if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X $game_map.scroll_right(@real_x - last_real_x) end if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y $game_map.scroll_up(last_real_y - @real_y) end #---------------------------------------------------------------------- # * Encounter and Event Processing #---------------------------------------------------------------------- unless moving? if last_moving result = check_event_trigger_here([1,2]) if result == false unless $DEBUG and Input.press?(Input::CTRL) @encounter_count -= 1 if @encounter_count > 0 end end end if Input.trigger?(Input::C) check_event_trigger_here([0]) check_event_trigger_there([0,1,2]) end end end #------------------------------------------------------------------------ # * Encounter and Event Processing #------------------------------------------------------------------------ def idle_wait(duration, value) for i in 0...duration @@wait_time += 1 if value == false break if i >= duration / 2 end end end