Advertisement
AngryPacman

PAC Face/Sprites

Jul 29th, 2011
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 13.96 KB | None | 0 0
  1. #===============================================================================
  2. #
  3. # Pacman Advanced Creative (PAC) Engine - Faces and Sprites
  4. # 18/5/2011
  5. # Type: System
  6. # Installation: Medium Configuration.
  7. # Level: Super-Average
  8. # With: Modern Algebra
  9. #
  10. #===============================================================================
  11. #
  12. # Description:
  13. # This script will draw actor sprites along with or instead of faces in
  14. # specified scenes. Modern Algebra's notes and much of his code has been left
  15. # in because I was scared to find out what happened when I tried it. I have
  16. # altered incredibly slight things, and I hope he doesn't mind. I say this
  17. # because I know he'll read this.
  18. #
  19. #===============================================================================
  20. #
  21. # Instructions
  22. # INSTALLATION
  23. # Paste above main, below materials and following PAC format where applicable.
  24. # Compatible and intended for use with but not dependent on other PAC scripts.
  25. # CONFIGURATION
  26. # In every scene you want to replace or draw the face graphic with the actor
  27. # sprite, use the following sample with edited values. You may omit values
  28. # that you do not change.
  29. #
  30. #    Scene => {
  31. #      :x_offset => 0,
  32. #      :y_offset => 0,
  33. #      :zoom => 100,
  34. #      :remove_face => false,
  35. #      :default_start_pose => 0,
  36. #      :alternate_start_pose => false,
  37. #      :change_directions => false,
  38. #      :direction_frames => 120,
  39. #      :animate_sprites => false,
  40. #      :move_speed => 4,
  41. #      :opacity => 255,
  42. #      :blend_type => 0,
  43. #      :angle => 0,
  44. #    },
  45. #
  46. #  where:
  47. # Scene is the name of the scene, Scene_Menu; Scene_Battle; Scene_Name etc.
  48. #
  49. # :x_offset is an integer, representing how many pixels left or right it
  50. # should be moved from the center of where the face would be drawn. Positive
  51. # numbers will be drawn right of that, and negative numbers drawn left of that.
  52. # Defaults to 0 if ommited.
  53. #
  54. # :y_offset is an integer, representing how many pixels up or down it should be
  55. # moved from the bottom of where the face would be drawn. If negative, it will
  56. # be drawn higher and if positive, it will be drawn lower. Defaults to 0.
  57. #
  58. # :zoom is an integer, representing percent zoom along the x axis. 100 is 100%,
  59. # meaning it will be normal size. 200% would be twice its normal size, etc...
  60. # Defaults to 100.
  61. #
  62. # :remove_face is a boolean. If true, the face won't be drawn. If false, the
  63. # face will be drawn along with the sprite. Defaults to false.
  64. #
  65. # :default_start_pose is an integer, 0-3. This is the starting pose of the first
  66. # drawn sprite. 0 => Down; 1 => Right; 2 => Up; 3 => Left. If excluded, defaults
  67. # to 0.
  68. #
  69. # :alternate_start_pose is a boolean. If true, then each time a new sprite is
  70. # drawn, its start position will differ. So, if you have three actor sprites are
  71. # being drawn, and the default start pose is 0 (Down), then the first sprite
  72. # would start facing down, the second sprite would start facing Right, and the
  73. # third sprite would start facing Up. If excluded, defaults to false.
  74. #
  75. # :change_directions is a boolean. If true, the sprites would change over the
  76. # time interval set in :direction_frames. If false, the sprites will only face
  77. # one direction for the duration of the scene. If excluded, defaults to false.
  78. #
  79. # :direction_frames is an integer. If :change_directions is true, this integer
  80. # will determine the number of frames before the sprite changes direction. 60
  81. # frames = 1 second. If excluded, defaults to 120.
  82. #
  83. # :animate_sprites is a boolean. If true, the sprites will be shown walking. If
  84. # false, they will remain stationary. If excluded, defaults to false.
  85. #
  86. # :move_speed is an integer, 1-6. If :animate_sprites is true, this is the speed
  87. # that the sprite will be animating. 1 is the slowest and 6 is the fastest.
  88. # Defaults to 4.
  89. #
  90. # :opacity ~ an integer between 0 and 255. This is a scale, with 0 being totally
  91. # transparent and 255 totally opaque. Defaults to 255.
  92. #
  93. # :blend_type ~ Either 0, 1, or 2. 0 => normal, 1 => addition; 2 => subtraction.
  94. # Defaults to 0 if excluded
  95. #
  96. # :angle ~ an integer between 0 and 360. This corresponds to degrees on a
  97. # circle. For instance, 0 is rightside up, 180 is upside down, etc... If
  98. # excluded, defaults to 0.
  99. #
  100. # If you get a syntax error when test playing your game, you most likely
  101. # forgot to put a comma or curly bracket in. If you set up entries for more
  102. # than one scene, you need to put a comma after each } except for the last
  103. # entry. For all of the attributes you specify in each scene entry, you need
  104. # a comma after the value except for the last entry.
  105. #
  106. #===============================================================================
  107. #
  108. # EDITING BEGINS AT LINE 113. DO NOT TOUCH LINES 108-109.
  109. #
  110. #===============================================================================
  111.  
  112. module PAC
  113.   module SYSTEM
  114.    
  115. #===============================================================================
  116. #
  117. # BEGIN EDITING
  118. #
  119. #===============================================================================
  120.    
  121. SF_CONFIGURATION = {
  122.  
  123. #~   Scene_Menu => {      # Scene Menu has been removed from this feature
  124. #~     :x_offset => 32,   # of conflicting issues with PAC Main Menu.
  125. #~     :y_offset => 0,
  126. #~     :remove_face => false,
  127. #~     :default_start_pose => 0,
  128. #~     :alternate_start_pose => true,
  129. #~     :animate_sprites => true,
  130. #~     :move_speed => 1,
  131. #~     :change_directions => true,
  132. #~     :direction_frames => 120,
  133. #~   },
  134.   Scene_Status => {
  135.     :x_offset => 0,
  136.     :y_offset => -24,
  137.     :zoom => 150,
  138.     :remove_face => true,
  139.     :default_start_pose => 0,
  140.     :animate_sprites => true,
  141.   },
  142.   Scene_Party => {
  143.     :x_offset => 0,
  144.     :y_offset => -16,
  145.     :remove_face => true,
  146.     :default_start_pose => 0,
  147.     :alternate_start_pose => false,
  148.     :animate_sprites => true,
  149.     :move_speed => 2,
  150.     :change_directions => true,
  151.     :direction_frames => 60,
  152.   },
  153.  
  154. #===============================================================================
  155. #
  156. # This script requires no editing. Do not edit anything in this script unless
  157. # you are a compenent scripter. Should you edit without any scripting education,
  158. # it may result in me tutting at you for getting it wrong.
  159. #
  160. #===============================================================================
  161.  
  162. }
  163.   end
  164. end
  165.  
  166.  
  167. #==============================================================================
  168. # ** Bitmap
  169. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  170. #  Summary of Changes:
  171. #    new attr_accessor - SF_just_cleared
  172. #    aliased method - clear
  173. #==============================================================================
  174.  
  175. class Bitmap
  176.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  177.   # * Public Instance Variable
  178.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  179.   attr_accessor :SF_just_cleared
  180.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  181.   # * Clear
  182.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  183.   alias mala_wlksprtmnu_clr_2gc1 clear unless self.method_defined? (:mala_wlksprtmnu_clr_2gc1)
  184.   def clear (*args)
  185.     mala_wlksprtmnu_clr_2gc1 (*args) # Run Original Method
  186.     @SF_just_cleared = true
  187.   end
  188. end
  189.  
  190. #==============================================================================
  191. # ** Game_Character
  192. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  193. #  Compatibility patch for Composite Characters
  194. #==============================================================================
  195.  
  196. class Game_Character
  197.   attr_writer :composite_character if self.method_defined? (:composite_character)
  198. end
  199.  
  200. #==============================================================================
  201. # ** Sprite_MenuActor
  202. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  203. #  This window displays the walking sprite of an actor.
  204. #==============================================================================
  205.  
  206. class Sprite_MenuActor < Sprite_Character
  207.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  208.   # * Object Initialization
  209.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  210.   def initialize (actor_id, x, y, dir, config, viewport = nil)
  211.     @frame_count = 0
  212.     @change_direction, @SF_animation = config[:change_directions], config[:animate_sprites]
  213.     @direction_frames = config[:direction_frames].is_a? (Integer) ? config[:direction_frames] : 120
  214.     actor = $game_actors[actor_id]
  215.     character = Game_Character.new
  216.     # Set to composite character if that script exists.
  217.     if character.methods.include? ("composite_character")
  218.       character.composite_character = actor.composite_character
  219.     else
  220.       character.set_graphic (actor.character_name, actor.character_index)
  221.     end
  222.     super (viewport, character)
  223.     self.x, self.y = x, y
  224.     case dir
  225.     when 1 then @character.turn_right
  226.     when 2 then @character.turn_up
  227.     when 3 then @character.turn_left
  228.     end
  229.     # Change sprite properties
  230.     self.zoom_x = self.zoom_y = config[:zoom].to_f / 100.0 if config[:zoom]
  231.     self.opacity = config[:opacity] if config[:opacity]
  232.     self.angle = config[:angle] if config[:angle]
  233.     self.blend_type = config[:blend_type] if config[:blend_type]
  234.     # Change Speed and Frequency of the Sprite
  235.     freq = config[:move_speed] ? config[:move_speed] : 4
  236.     move_route = RPG::MoveRoute.new
  237.     move_route.list.unshift (RPG::MoveCommand.new (29, [freq]))
  238.     @character.force_move_route (move_route)
  239.     update_bitmap
  240.     update
  241.   end
  242.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  243.   # * Frame Update
  244.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  245.   def update
  246.     # Turn at user-specified intervals
  247.     if @change_direction
  248.       if @frame_count >= @direction_frames
  249.         @character.turn_right_90
  250.         @frame_count = 0
  251.       end
  252.       @frame_count += 1
  253.     end
  254.     if @SF_animation
  255.       @character.update_move
  256.       @character.update_animation
  257.     end
  258.     update_src_rect
  259.   end
  260. end
  261.  
  262. #==============================================================================
  263. # ** Window_Base
  264. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  265. #  Summary of Changes:
  266. #    aliased methods - initialize, update, dispose, draw_actor_face
  267. #    new methods - dispose_walking_sprites
  268. #==============================================================================
  269.  
  270. class Window_Base
  271.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  272.   # * Object Initialization
  273.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  274.   alias ma_SF_init_wlkng_7jk2 initialize
  275.   def initialize (*args)
  276.     @ma_walking_sprites = []
  277.     ma_SF_init_wlkng_7jk2 (*args) # Run Original Method
  278.   end
  279.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  280.   # * Dispose
  281.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  282.   alias malgba_wlksprts_disps_5yu2 dispose
  283.   def dispose (*args)
  284.     @ma_walking_sprites.each { |sprite| sprite.dispose }
  285.     @ma_walking_sprites.clear
  286.     malgba_wlksprts_disps_5yu2 (*args) # Run Original Method
  287.   end
  288.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  289.   # * Frame Update
  290.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  291.   alias mrnalb_sprtwlk_updt_7uj2 update
  292.   def update (*args)
  293.     # Dispose all sprites if bitmap recently cleared and new faces not drawn
  294.     if self.contents.SF_just_cleared
  295.       @ma_walking_sprites.each { |sprite| sprite.dispose }
  296.       @ma_walking_sprites.clear
  297.       self.contents.SF_just_cleared = false
  298.     end
  299.     # Check if contents have scrolled
  300.     x_plus, y_plus = 0, 0
  301.     if @SF_scroll_x != self.ox
  302.       @SF_scroll_x = 0 unless @SF_scroll_x
  303.       x_plus += (@SF_scroll_x - self.ox)
  304.       @SF_scroll_x = self.ox
  305.     end
  306.     if @SF_scroll_y != self.oy
  307.       @SF_scroll_y = 0 unless @SF_scroll_y
  308.       y_plus += (@SF_scroll_y - self.oy)
  309.       @SF_scroll_y = self.oy
  310.     end
  311.     @ma_walking_sprites.each { |sprite|
  312.       sprite.update
  313.       # Scroll if contents have scrolled.
  314.       sprite.x += x_plus
  315.       sprite.y += y_plus
  316.       }
  317.     mrnalb_sprtwlk_updt_7uj2 (*args) # Run Original Method
  318.   end
  319.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  320.   # * Draw Actor Face Graphic
  321.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  322.   alias malg_drwactrface_spritereplce_6uj2 draw_actor_face
  323.   def draw_actor_face(actor, x, y, size = 96, *args)
  324.     # If scene is specified to replace the face graphic
  325.     if PAC::SYSTEM::SF_CONFIGURATION.keys.include? ($scene.class)
  326.       # Dispose all sprites if bitmap recently cleared
  327.       if self.contents.SF_just_cleared
  328.         @ma_walking_sprites.each { |sprite| sprite.dispose }
  329.         @ma_walking_sprites.clear
  330.         self.contents.SF_just_cleared = false
  331.       end
  332.       config = PAC::SYSTEM::SF_CONFIGURATION[$scene.class]
  333.       malg_drwactrface_spritereplce_6uj2 (actor, x, y, size, *args) unless config[:remove_face]
  334.       # Get offset
  335.       x_off = config[:x_offset] ? config[:x_offset] : 0
  336.       y_off = config[:y_offset] ? config[:y_offset] : 0
  337.       sx = x + (size / 2) + x_off
  338.       sy = y + size + y_off
  339.       pose = config[:default_start_pose] ? config[:default_start_pose] : 0
  340.       dir = config[:alternate_start_pose] ? @ma_walking_sprites.size % 4 : pose
  341.       # Create Sprite
  342.       viewport = Viewport.new (self.x + 16, self.y + 16, contents.width, contents.height)
  343.       viewport.z = self.z + 50
  344.       viewport.z += self.viewport.z if self.viewport
  345.       sprite = Sprite_MenuActor.new (actor.id, sx, sy, dir, config, viewport)
  346.       @ma_walking_sprites.push (sprite)
  347.     else
  348.       # Draw face if scene not affected
  349.       malg_drwactrface_spritereplce_6uj2 (actor, x, y, size, *args)
  350.     end
  351.   end
  352. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement