Advertisement
M3rein

Untitled

Jul 20th, 2020
1,777
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.05 KB | None | 0 0
  1. #==============================================================================#
  2. #                               Footsteps for v17                              #
  3. #                                    by Marin                                  #
  4. #==============================================================================#
  5. #    If an event walks on a tile with terrain tag 3 (Sand), it will produce    #
  6. #             visual footprints. Works with Following Pokémon.                 #
  7. #==============================================================================#
  8. #                    Please give credit when using this.                       #
  9. #==============================================================================#
  10.  
  11. class Sprite_Character
  12.   # This is the amount the opacity is lowered per frame. It needs to go 256 -> 0,
  13.   # which means setting this to 4 would make each step pair last 64 frames (~1.5s)
  14.   FADE_OUT_SPEED = 4
  15.  
  16.   # A configurable X/Y offset for the step sprites, in case they don't align
  17.   # nicely with the player's graphic.
  18.   WALK_X_OFFSET = -16
  19.   WALK_Y_OFFSET = 0
  20.  
  21.   # A configurable X/Y offset for bike print sprites, in case they don't align
  22.   # nicely with the player's graphic.
  23.   BIKE_X_OFFSET = -16
  24.   BIKE_Y_OFFSET = 0
  25.  
  26.   # If true, both the player AND the follower will create footprints.
  27.   # If false, only the follower will create footprints.
  28.   DUPLICATE_FOOSTEPS_WITH_FOLLOWER = false
  29.  
  30.   CHARNAME_MAY_NOT_INCLUDE = [
  31.     "NoFootprint",
  32.     ".noprint",
  33.     ".nostep",
  34.     ".nofootprint",
  35.     ".nofootstep"
  36.   ]
  37.      
  38.   alias footsteps_initialize initialize
  39.   def initialize(*args)
  40.     footsteps_initialize(*args)
  41.     @steps = []
  42.   end
  43.  
  44.   alias footsteps_update update
  45.   def update
  46.     footsteps_update
  47.     @old_x ||= @character.x
  48.     @old_y ||= @character.y
  49.     if (@character.x != @old_x || @character.y != @old_y) && !["", "nil"].include?(@character.character_name) &&
  50.        (!@character.respond_to?(:name) || !CHARNAME_MAY_NOT_INCLUDE.include?(@character.name))
  51.       if @character == $game_player && $PokemonTemp.dependentEvents &&
  52.          $PokemonTemp.dependentEvents.respond_to?(:realEvents) &&
  53.          $PokemonTemp.dependentEvents.realEvents.select { |e| !["", "nil"].include?(e.character_name) }.size > 0 &&
  54.          !DUPLICATE_FOOSTEPS_WITH_FOLLOWER
  55.         make_steps = false
  56.       else
  57.         tilesetid = @character.map.instance_eval { @map.tileset_id }
  58.         make_steps = [2,1,0].any? do |e|
  59.           tile_id = @character.map.data[@old_x, @old_y, e]
  60.           next $data_tilesets[tilesetid].terrain_tags[tile_id] == PBTerrain::Sand
  61.         end
  62.       end
  63.       if make_steps
  64.         fstep = Sprite.new(self.viewport)
  65.         fstep.z = 0
  66.         dirs = [nil,"DownLeft","Down","DownRight","Left","Still","Right","UpLeft",
  67.             "Up", "UpRight"]
  68.         if @character == $game_player && $PokemonGlobal.bicycle
  69.           fstep.bmp("Graphics/Characters/steps#{dirs[@character.direction]}Bike")
  70.         else
  71.           fstep.bmp("Graphics/Characters/steps#{dirs[@character.direction]}")
  72.         end
  73.         @steps ||= []
  74.         if @character == $game_player && $PokemonGlobal.bicycle
  75.           x = BIKE_X_OFFSET
  76.           y = BIKE_Y_OFFSET
  77.         else
  78.           x = WALK_X_OFFSET
  79.           y = WALK_Y_OFFSET
  80.         end
  81.         @steps << [fstep, @old_x + x / Game_Map::TILEWIDTH.to_f, @old_y + y / Game_Map::TILEHEIGHT.to_f, self.src_rect.width / 2]
  82.       end
  83.     end
  84.     @old_x = @character.x
  85.     @old_y = @character.y
  86.     if @steps
  87.       for i in 0...@steps.size
  88.         next unless @steps[i]
  89.         sprite, x, y, ox = @steps[i]
  90.         sprite.x = -@character.map.display_x / Game_Map::XSUBPIXEL + (x + 1) * Game_Map::TILEWIDTH
  91.         sprite.y = -@character.map.display_y / Game_Map::YSUBPIXEL + (y + 1) * Game_Map::TILEHEIGHT
  92.         sprite.x -= ox
  93.         sprite.y -= Game_Map::TILEHEIGHT
  94.         sprite.opacity -= FADE_OUT_SPEED
  95.         if sprite.opacity <= 0
  96.           sprite.dispose
  97.           @steps[i] = nil
  98.         end
  99.       end
  100.       @steps.compact!
  101.     end
  102.   end
  103. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement