Advertisement
Demonicskyers

Wybór postaci głównej

Jul 25th, 2013
795
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 15.66 KB | None | 0 0
  1. #==============================================================================
  2. # Wybór postaci [XP]
  3. # by Ayene
  4. # 15.07.2011 ver 2.0
  5. # www.ultimateam.pl
  6. #==============================================================================
  7. # Opis:
  8. # Skrypt pozwala na wybór postaci na początku gry. Może mieć również
  9. # zastosowanie przy wyborze więcej niż jednego bohatera (maksymalnie tyle,
  10. # ile może liczyć drużyna).
  11. #==============================================================================
  12. # Instrukcja:
  13. #==============================================================================
  14. # Na początku gry wywołaj za pomocą polecenia "Script" w zdarzeniu:
  15. # $scene = Scene_Character_Select.new
  16. #
  17. #==============================================================================
  18. # Konfiguracja:
  19. #==============================================================================
  20.  
  21. module AYENE
  22.   module Character_Select
  23.    
  24.     # Ustawienia czcionki
  25.     FONT_NAME = 'Comic Sans MS'    # nazwa czcionki (folder Fonts)
  26.     FONT_SIZE = 26                 # rozmiar czcionki
  27.     FONT_BOLD = false              # pogrubienie
  28.     FONT_ITALIC = false            # kursywa  
  29.     FONT_COLOR = Color.new(255, 255, 255, 255)   # kolor tekstu
  30.     FONT_OUTLINE = true                          # obwódka? (true/false)  
  31.     FONT_OUTLINE_COLOR = Color.new(0, 0, 0, 255) # kolor obwódki tekstu    
  32.     FONT_SHADOW = true                          # cień? (true/false)
  33.     FONT_SHADOW_COLOR = Color.new(0, 0, 0, 100)  # kolor cienia
  34.      
  35.     WLH = 32                        # interlinia
  36.    
  37.     # Ustawienia tła obrazkowego (folder Graphics/Pitures)  
  38.     BACKGROUND_IMAGE = ''           # nazwa tła; '' wyłącza tło
  39.     BACKGROUND_OPACTIY = 255    # przezroczystość tła
  40.    
  41.     # Ustawienia okna (folder Graphics/Windowskins)
  42.     WINDOW = ''                              # nazwa pliku; '' domyślne okno
  43.     WINDOW_OPACTIY = 255           # przezroczystość okna
  44.     WINDOW_HELP_TEXT = 'Wybierz bohatera glównego'
  45.    
  46.     # Ustawienia muzyki w tle
  47.     STAGE_BGM = ''                  # nazwa pliku z muzyką (folder Audio/BGM)
  48.     STAGE_BGM_VOLUME = 100          # głośność
  49.        
  50.     # Ustawienia postaci
  51.     CHAR_IDS = [1, 5, 4, 2, 3, 6, 7, 8]  # ID postaci do wyboru
  52.    
  53.     # Obrazek bohatera. By go wyświetlić należy w folderze Graphics/Pictures
  54.     # umieścić plik o nazwie "Face_ID", gdzie zamiast ID należy podać id postaci,
  55.     # np. "Face_2" to obrazek bohatera o ID 2.
  56.     CHAR_FACE = true                     # obrazek bohatera? (true/false)  
  57.        
  58.     # Ustawienia statystyk i ich pasków
  59.     # Maksymalna wartość pasków wynosi tyle, ile największa wartość danej
  60.     # statystyki u wszystkich postaci do wyboru. Innymi słowy, skrypt porównuje
  61.     # wielkość danej statystyki u postaci, następnie wyłania najwyższą.
  62.    
  63.     CHAR_PARAMS = [ :hp, :sp, :str, :dex, :agi, :int ]  # nazwy statystyk po przecinku
  64.    
  65.     CHAR_PARAMS_BAR = { # :par => "nazwa", color1, color2
  66.     :hp  => ["Życie", Color.new(0, 100, 17, 255), Color.new(0, 223, 37, 255)],
  67.     :sp  => ["Mana", Color.new(0, 60, 95, 255), Color.new(0, 142, 223, 255)],
  68.     :str => ["Siła", Color.new(140, 20, 20, 255), Color.new(230, 34, 34, 255)],
  69.     :dex => ["Celność", Color.new(124, 38, 132, 255), Color.new(209, 62, 222, 255)],
  70.     :agi => ["Szybkość", Color.new(142, 134, 12, 255), Color.new(228, 219, 71, 255)],
  71.     :int => ["Inteligencja", Color.new(33, 143, 136, 255), Color.new(68,224, 215, 255)],
  72.     }
  73.    
  74.     BAR_WIDTH = 150                 # Szerokość pasków  
  75.     COLMUNS = 3                     # Liczba kolumn
  76.    
  77.     NEXT_SCENE = Scene_Map          # kolejna scena  
  78.     PREVIOUS_SCENE = Scene_Title    # poprzednia scena
  79.    
  80.     MAX_MEMBER = 3        # maksymalna liczba bohaterów w drużynie
  81.     DELCHAR_SWITCH = 0    # przełącznik włączający usuwanie bohaterów z drużyny
  82.   end  
  83. end
  84.  
  85. #==============================================================================
  86. # ** Game_Party
  87. #==============================================================================
  88.  
  89. class Game_Party
  90.   attr_accessor   :actors                   # actors
  91. end
  92.  
  93. #==============================================================================
  94. # ** Scene_Character_Select
  95. #==============================================================================
  96.  
  97. class Scene_Character_Select
  98.   include AYENE::Character_Select
  99.   #--------------------------------------------------------------------------
  100.   # * Main Processing
  101.   #--------------------------------------------------------------------------
  102.   def main
  103.     start
  104.     Graphics.transition
  105.     loop do
  106.       Graphics.update
  107.       Input.update
  108.       update
  109.       if $scene != self
  110.         break
  111.       end
  112.     end
  113.     Graphics.freeze
  114.     terminate
  115.   end
  116.   #--------------------------------------------------------------------------
  117.   # * Start processing
  118.   #--------------------------------------------------------------------------
  119.   def start
  120.     @actor_id = 0
  121.     if STAGE_BGM != ''
  122.       Audio.bgm_play("Audio/BGM/" + STAGE_BGM, STAGE_BGM_VOLUME, 100)
  123.     end
  124.     if BACKGROUND_IMAGE != ''
  125.       @background = Sprite.new
  126.       @background.bitmap = RPG::Cache.picture(BACKGROUND_IMAGE)
  127.       @background.opacity = BACKGROUND_OPACTIY
  128.     end    
  129.     @window_command = Window_Command_Select.new
  130.     @window_help = Window_Char_Select_Help.new
  131.   end
  132.   #--------------------------------------------------------------------------
  133.   # * Termination Processing
  134.   #--------------------------------------------------------------------------
  135.   def terminate
  136.     @window_command.dispose
  137.     @window_help.dispose
  138.     unless @background.nil?
  139.       @background.bitmap.dispose
  140.       @background.dispose
  141.     end  
  142.     Audio.bgm_fade(1500) if STAGE_BGM != ''
  143.   end
  144.   #--------------------------------------------------------------------------
  145.   # * Frame Update
  146.   #--------------------------------------------------------------------------
  147.   def update  
  148.     @window_command.update
  149.     @window_help.update
  150.     if Input.trigger?(Input::C)
  151.       determine_character    
  152.       $game_party.actors = [] if not $game_switches[DELCHAR_SWITCH]
  153.       if $game_party.actors.size < MAX_MEMBER  
  154.         $game_party.add_actor(@actor_id)
  155.         $game_system.se_play($data_system.decision_se)
  156.         $scene = eval("#{NEXT_SCENE}.new")      
  157.       else
  158.         $game_system.se_play($data_system.buzzer_se)
  159.       end
  160.       return
  161.     elsif Input.trigger?(Input::B)
  162.       $game_system.se_play($data_system.cancel_se)
  163.       $scene = eval("#{PREVIOUS_SCENE}.new")
  164.       return
  165.     end  
  166.   end
  167.   #--------------------------------------------------------------------------
  168.   # * Determine Character
  169.   #--------------------------------------------------------------------------
  170.   def determine_character
  171.     actor_index = @window_command.index
  172.     data = []    
  173.     CHAR_IDS.each {|i| data.push(i) if !$game_party.actors.include?($game_actors[i])}  
  174.     @actor_id = data[actor_index]
  175.   end
  176. end
  177.  
  178. #==============================================================================
  179. # ** Window_Command_Select
  180. #==============================================================================
  181.  
  182. class Window_Command_Select < Window_Selectable
  183.   include AYENE::Character_Select
  184.   #--------------------------------------------------------------------------
  185.   # * Object Initialization
  186.   #--------------------------------------------------------------------------
  187.   def initialize  
  188.     super(0, 65, 640, 415)
  189.     data = []
  190.     CHAR_IDS.each {|i| data.push(i) if !$game_party.actors.include?($game_actors[i])}  
  191.     @commands = data
  192.     @_blink_count = 0
  193.     @item_max = @commands.size
  194.     @cursor_width = ((width-32) / COLMUNS)    
  195.     self.windowskin = RPG::Cache.windowskin(WINDOW) if WINDOW != ''
  196.     self.opacity = WINDOW_OPACTIY
  197.     self.contents = Bitmap.new(@cursor_width+@item_max * @cursor_width-32, height-32)
  198.     refresh
  199.     self.index = 0
  200.   end
  201.   #--------------------------------------------------------------------------
  202.   # * Refresh
  203.   #--------------------------------------------------------------------------
  204.   def refresh
  205.     self.contents.clear  
  206.     @commands.each_index { |i| draw_item(i)}  
  207.   end
  208.   #--------------------------------------------------------------------------
  209.   # * Draw Item
  210.   #--------------------------------------------------------------------------
  211.   def draw_item(index)
  212.     x = 4 + @cursor_width * index
  213.     y = 4    
  214.     actor = $game_actors[@commands[index]]    
  215.     draw_actor_status(actor, x, y)
  216.     x = (@cursor_width-BAR_WIDTH)/2 + @cursor_width * index
  217.     CHAR_PARAMS.each_index { |i|
  218.       draw_actor_params(actor, x, y + @bit_height + WLH * (i+2), CHAR_PARAMS[i])
  219.     }
  220.   end
  221.   #--------------------------------------------------------------------------
  222.   # * Draw Actor Status
  223.   #--------------------------------------------------------------------------
  224.   def draw_actor_status(actor, x, y)  
  225.     self.contents.font.size = FONT_SIZE
  226.     self.contents.draw_char_status(x, y, @cursor_width - 8, WLH, "#{actor.name}", FONT_COLOR, 1)          
  227.     if CHAR_FACE
  228.       bitmap = RPG::Cache.picture("Face_#{actor.id}")  
  229.       rect = Rect.new(0, 0, bitmap.width, bitmap.height)
  230.       self.contents.blt(x + (@cursor_width-bitmap.width)/2, y + WLH * 1, bitmap, rect)  
  231.       @bit_height = bitmap.height
  232.       bitmap.dispose
  233.     else
  234.       @bit_height = 0
  235.     end  
  236.     self.contents.font.size = FONT_SIZE-2
  237.     class_name = $data_classes[actor.class_id].name
  238.     text = sprintf("Klasa: %s", class_name)  
  239.     self.contents.draw_char_status(x, y + @bit_height + WLH, @cursor_width - 8, WLH, text, FONT_COLOR, 1)  
  240.   end
  241.   #--------------------------------------------------------------------------
  242.   # * Draw Actor Parameters
  243.   #--------------------------------------------------------------------------
  244.   def draw_actor_params(actor, x, y, type)
  245.     members = []
  246.     @commands.each {|i| members.push($game_actors[i])}  
  247.     case type
  248.     when :hp  
  249.       members.sort!   { |a, b| a.maxhp <=> b.maxhp }    
  250.       gw = BAR_WIDTH * actor.hp / members.pop.maxhp
  251.       text = "#{actor.maxhp}"
  252.     when :sp
  253.       members.sort!   { |a, b| a.maxsp <=> b.maxsp }    
  254.       gw = BAR_WIDTH * actor.sp / members.pop.maxsp
  255.       text = "#{actor.maxsp}"
  256.     when :str
  257.       members.sort!   { |a, b| a.str <=> b.str }
  258.       gw = BAR_WIDTH * actor.str / members.pop.str
  259.       text = "#{actor.str}"  
  260.     when :dex
  261.       members.sort!   { |a, b| a.dex <=> b.dex }
  262.       gw = BAR_WIDTH * actor.dex / members.pop.dex
  263.       text = "#{actor.dex}"
  264.     when :agi
  265.       members.sort!   { |a, b| a.agi <=> b.agi }
  266.       gw = BAR_WIDTH * actor.agi / members.pop.agi
  267.       text = "#{actor.agi}"  
  268.     when :int
  269.       members.sort!   { |a, b| a.int <=> b.int }
  270.       gw = BAR_WIDTH * actor.int / members.pop.int
  271.       text = "#{actor.int}"  
  272.     end
  273.     self.contents.fill_rect(x, y+WLH-8, BAR_WIDTH+2, 8, Color.new(0, 0, 0, 255))
  274.     self.contents.gradient_fill_rect(x+1, y+WLH-7, gw, 6, CHAR_PARAMS_BAR[type][1], CHAR_PARAMS_BAR[type][2])    
  275.     self.contents.draw_char_status(x, y, 100, WLH, CHAR_PARAMS_BAR[type][0], system_color, 0)
  276.     self.contents.draw_char_status(x + BAR_WIDTH - 42, y, 44, WLH, text, FONT_COLOR, 2)
  277.   end  
  278.   #--------------------------------------------------------------------------
  279.   # * Get Top Row
  280.   #--------------------------------------------------------------------------
  281.   def top_row  
  282.     return self.ox / @cursor_width
  283.   end
  284.   #--------------------------------------------------------------------------
  285.   # * Set Top Row
  286.   #--------------------------------------------------------------------------
  287.   def top_row=(row)  
  288.     row = 0 if row < 0
  289.     row = @item_max - 1 if row > @item_max - 1    
  290.     self.ox = row * @cursor_width
  291.   end
  292.   #--------------------------------------------------------------------------
  293.   # * Update Cursor Rectangle
  294.   #--------------------------------------------------------------------------
  295.   def update_cursor_rect    
  296.     if @index < 0
  297.       self.cursor_rect.empty
  298.       return
  299.     end  
  300.     row = @index    
  301.     self.top_row = row if row < self.top_row
  302.     self.top_row = row - (COLMUNS - 1) if row > self.top_row + (COLMUNS - 1)
  303.     x = @index * @cursor_width - self.ox
  304.     y = 0        
  305.     self.cursor_rect.set(x, y, @cursor_width, height-32)  
  306.   end
  307.   #--------------------------------------------------------------------------
  308.   # * Frame Update
  309.   #--------------------------------------------------------------------------
  310.   def update
  311.     super
  312.     if self.active and @item_max > 0 and @index >= 0
  313.       if Input.repeat?(Input::RIGHT)
  314.         $game_system.se_play($data_system.cursor_se)      
  315.         @index += 1
  316.         @index %= @item_max
  317.       end
  318.       if Input.repeat?(Input::LEFT)
  319.         $game_system.se_play($data_system.cursor_se)
  320.         @index += @item_max - 1
  321.         @index %= @item_max      
  322.       end
  323.     end  
  324.     update_cursor_rect
  325.   end  
  326. end
  327.  
  328. #==============================================================================
  329. # ** Window_Char_Select_Help
  330. #==============================================================================
  331.  
  332. class Window_Char_Select_Help < Window_Base
  333.   include AYENE::Character_Select
  334.   #--------------------------------------------------------------------------
  335.   # * Object Initialization
  336.   #--------------------------------------------------------------------------
  337.   def initialize
  338.     super(0, 0, 640, 64)
  339.     self.contents = Bitmap.new(width - 32, height - 32)
  340.     self.windowskin = RPG::Cache.windowskin(WINDOW) if WINDOW != ''
  341.     self.opacity = WINDOW_OPACTIY
  342.     refresh
  343.   end
  344.   #--------------------------------------------------------------------------
  345.   # * Refresh
  346.   #--------------------------------------------------------------------------
  347.   def refresh
  348.     self.contents.clear  
  349.     self.contents.font.size = FONT_SIZE
  350.     self.contents.draw_char_status(4, 0, width-32, WLH, WINDOW_HELP_TEXT, FONT_COLOR, 1)
  351.   end
  352. end
  353.  
  354. #==============================================================================
  355. # ** Bitmap
  356. #==============================================================================
  357.  
  358. class Bitmap
  359.   include AYENE::Character_Select
  360.   #--------------------------------------------------------------------------
  361.   # * Draw Text Outline
  362.   #--------------------------------------------------------------------------
  363.   def draw_char_status(x, y, width, height, text, color, align = 1)
  364.     font.name = FONT_NAME  
  365.     font.bold = FONT_BOLD
  366.     font.italic = FONT_ITALIC
  367.     if FONT_OUTLINE
  368.       font.color = FONT_OUTLINE_COLOR
  369.       draw_text(x + 1, y, width, height, text, align)
  370.       draw_text(x - 1, y, width, height, text, align)
  371.       draw_text(x, y + 1, width, height, text, align)
  372.       draw_text(x, y - 1, width, height, text, align)
  373.     end  
  374.     if FONT_SHADOW
  375.       font.color = FONT_SHADOW_COLOR  
  376.       draw_text(x + 1, y + 4, width, height, text, align)
  377.     end
  378.     font.color = color
  379.     draw_text(x, y, width, height, text, align)
  380.   end
  381.   #--------------------------------------------------------------------------
  382.   # * Draw Gradient Fill Rectangle
  383.   #--------------------------------------------------------------------------
  384.   def gradient_fill_rect(x, y, width, height, c1, c2)
  385.     (x...x + width).each { |i|
  386.       r = c1.red + (c2.red - c1.red) * (i - x) / (width - 1)
  387.       g = c1.green + (c2.green - c1.green) * (i - x) / (width - 1)
  388.       b = c1.blue + (c2.blue - c1.blue) * (i - x) / (width - 1)
  389.       color = Color.new(r, g, b)
  390.       fill_rect(i, y, 1, height, color)
  391.       }  
  392.   end
  393. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement