Guest User

8-frame walk script

a guest
Nov 27th, 2015
674
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.33 KB | None | 0 0
  1. #----------------------------------
  2. # Thera's variation of the multiple frame script.
  3. #
  4. # My first RSS script ever. I'm pretty proud of it.
  5. # It's meant to be used with a sprite set of 9 frames wide, with the first frame
  6. # being a 'standing still' frame, and the rest the actual walkcycle.
  7. #
  8. # It only works on files using a '%' at the beggining of their name.
  9. #----------------------------------
  10. class Sprite_Character < Sprite_Base
  11.   #--------------------------------------------------------------------------
  12.   # * Set Character Bitmap
  13.   #
  14.   # Thera's notes: Character Bitmap analyses the spriteset and sets how big
  15.   # the frames in the sprite set are.
  16.   # It also checks before hand whether the file start with a '!', '$' or '%'
  17.   # After wards it sets the drawing origin of the sprite relative to the
  18.   # character origin.
  19.   #--------------------------------------------------------------------------
  20.   def set_character_bitmap
  21.     self.bitmap = Cache.character(@character_name)
  22.     #start changes#
  23.     # Yes, this is a nested if_statement, but files starting with '!' would
  24.     # complain if I did otherwise.
  25.         sign = @character_name[/^[\!\$\%]./]
  26.           if sign && sign.include?('$')
  27.           @cw = bitmap.width / 3 #Orginal Value 3
  28.           @ch = bitmap.height / 4 #original value:4
  29.           @sixframes = false
  30.           else
  31.             if sign && sign.include?('%')
  32.             @cw = bitmap.width / 9 #Original Value:9
  33.             @ch = bitmap.height / 4 #Original Value:4
  34.             @sixframes = true
  35.              
  36.             else
  37.               @cw = bitmap.width / 12 #I made a change here Original value:12
  38.               @ch = bitmap.height / 8 #I made a change here Original Value:8
  39.               @sixframes = false
  40.             end
  41.           end
  42.                 #end changes#
  43.     self.ox = @cw / 2
  44.     self.oy = @ch
  45.   end
  46.   #--------------------------------------------------------------------------
  47.   # * Update Transfer Origin Rectangle
  48.   #
  49.   # Thera's notes: Update Transfer Origin Rectangle changes the part of the
  50.   # spritesheet that is being used as the current sprite of the character.
  51.   # So it moves this rectangle around on the spritesheet.
  52.   # I make it check whether 'sixframes' and thus the special sheet is true,
  53.   # applying different rectangle movements for different spritesheets.
  54.   #--------------------------------------------------------------------------
  55.   def update_src_rect
  56.     if @tile_id == 0
  57.       index = @character.character_index
  58.       #start changes#
  59.       if @sixframes
  60.         pattern = @character.pattern+1 #I had to do this, this way, so that the
  61.         #animation doesn't do back to the second frame after visiting the third.
  62.         #The '+1" Allows it to skip over the first frame, the standing still
  63.         #frame
  64.         sx = (index % 4 * 9 + pattern) * @cw #orginal second value: 9 Orginal first value: 4
  65.       else
  66.         pattern = @character.pattern < 3 ? @character.pattern : 1
  67.         sx = (index % 4 * 3 + pattern) * @cw
  68.       end
  69.       sy = (index / 4 * 4 + (@character.direction - 2) / 2) * @ch
  70.       self.src_rect.set(sx, sy, @cw, @ch)
  71.     end
  72.   end
  73. end
  74. class Game_CharacterBase
  75.      
  76.   #--------------------------------------------------------------------------
  77.   # * Update Animation Pattern
  78.   #
  79.   # Thera's notes: Update Animation Pattern makes sure that a character cycles
  80.   # through it's sprite animation. Again, it first checks the filename before
  81.   # applying operations.
  82.   # The @pattern variable if very important when editing sprite animation.
  83.   # Thus I edited basically any instance of it being modified when making this
  84.   # script.
  85.   #--------------------------------------------------------------------------
  86.   def update_anime_pattern
  87.     if @character_name[0, 1] == '%'
  88.     if !@step_anime && @stop_count > 0
  89.         @original_pattern = -1
  90.         @pattern = @original_pattern
  91.       else
  92.         @pattern = (@pattern + 1) % 6 #original value 8
  93.         #Changed it to 8 here because we want to have an 8 frame animation.
  94.       end
  95.     else
  96.  
  97.     if !@step_anime && @stop_count > 0
  98.       @original_pattern = 1
  99.       @pattern = @original_pattern
  100.     else
  101.       @pattern = (@pattern + 1) % 4
  102.     end
  103.     end
  104.   end
  105.   # Thera's notes: I actually don't know what straighten position is supossed to
  106.   # do exactly, but as it was modifying the @pattern variable, I decided to
  107.   # adapt it to this script's standards.
  108.   def straighten
  109.     if @character_name[0, 1] == '%'
  110.  
  111.     @pattern = -1 if @walk_anime || @step_anime
  112.     @anime_count = 0
  113.  
  114.     else
  115.  
  116.       @pattern = 1 if @walk_anime || @step_anime
  117.       @anime_count = 0
  118.     end
  119.   end
  120.   # Similar as with straighten, I adapted this one because of the appearance of
  121.   # the @original_pattern variable.
  122.   def set_graphic(character_name, character_index)
  123.     @tile_id = 0
  124.     @character_name = character_name
  125.     @character_index = character_index
  126.     #changed from 1 to -1
  127.     if @character_name[0, 1] == '%'
  128.     @original_pattern = -1
  129.     else
  130.     @original_pattern = 1
  131.     end
  132.     #end change
  133.   end
  134.  
  135. end
  136. class Game_Event < Game_Character
  137. #--------------------------------------------------------------------------
  138.   # * Set Up Event Page Settings
  139.   #
  140.   # Thera's notes: This sets up the event with all the parameters defined in
  141.   # the event page in the editor. I chenged the part where the character graphic
  142.   # was set up, because otherwise it would default to the second frame when
  143.   # character were standing still.
  144.   #--------------------------------------------------------------------------
  145.   def setup_page_settings
  146.     @tile_id          = @page.graphic.tile_id
  147.     @character_name   = @page.graphic.character_name
  148.     @character_index  = @page.graphic.character_index
  149.     if @original_direction != @page.graphic.direction
  150.       @direction          = @page.graphic.direction
  151.       @original_direction = @direction
  152.       @prelock_direction  = 0
  153.     end
  154.     if @character_name[0, 1] == '%'
  155.     if @original_pattern != @page.graphic.pattern
  156.       @pattern          = @page.graphic.pattern
  157.       @original_pattern   = -1
  158.     end
  159.     else
  160.     if @original_pattern != @page.graphic.pattern
  161.       @pattern          = @page.graphic.pattern
  162.       @original_pattern   = @pattern
  163.     end
  164.     end
  165.     @move_type        = @page.move_type
  166.     @move_speed      = @page.move_speed
  167.     @move_frequency  = @page.move_frequency
  168.     @move_route      = @page.move_route
  169.     @move_route_index   = 0
  170.     @move_route_forcing = false
  171.     @walk_anime      = @page.walk_anime
  172.     @step_anime      = @page.step_anime
  173.     @direction_fix    = @page.direction_fix
  174.     @through            = @page.through
  175.     @priority_type    = @page.priority_type
  176.     @trigger            = @page.trigger
  177.     @list              = @page.list
  178.     @interpreter = @trigger == 4 ? Game_Interpreter.new : nil
  179.   end
  180. end
Advertisement
Add Comment
Please, Sign In to add comment