Advertisement
Holy87

Ending Credits - VX

Jul 12th, 2013
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 10.41 KB | None | 0 0
  1. #===============================================================================
  2. # TITOLI DI CODA
  3. #===============================================================================
  4. # Autore: Holy87
  5. # Versione: 1.0
  6. #-------------------------------------------------------------------------------
  7. # Mostrare dei titoli di coda alla fine del gioco non è mai stato così facile.
  8. #-------------------------------------------------------------------------------
  9. # Istruzioni:
  10. # Copiare lo script sotto Materials, prima del Main. Create un file di testo
  11. # (possibilmente con Notepad++) e piazzateci tutto quello che volete scriverci.
  12. # Nella configurazione, impostate il nome del file di testo dove c'è scritto
  13. # Nome_File. Potete cambiare anche font, grandezza, velocità e scorrimento.
  14. # Per avviare i titoli di coda, basta inserire in un "chiama script"
  15. # call_ending
  16. #-------------------------------------------------------------------------------
  17. # Nota: è anche possibile inserire delle immagini su un rigo scrivendo all'inizio
  18. # di esso il tag [IMG]nomeimmagine
  19. # l'immagine deve risiedere nella cartella pictures.
  20. #-------------------------------------------------------------------------------
  21.  
  22. module H87_Ending
  23. #===============================================================================
  24. # ** CONFIGURAZIONE **
  25. #===============================================================================
  26.   #Nome del file che contiene il testo dei titoli di coda
  27.   Nome_File = "crediti.txt"
  28.   #Permettere lo scorrimento veloce con INVIO?
  29.   AllowFast = true
  30.   #Velocità di scorrimento standard
  31.   Speed = 2
  32.   #Spaziatura rigo
  33.   WLH = 24
  34.   #Nome del font:
  35.   Name = "Verdana"
  36.   #Grandezza del font:
  37.   Size = 20
  38.   #Grassetto?
  39.   Bold = false
  40.   #Corsivo?
  41.   Italic = false
  42.   #Ombrato?
  43.   Shadow = false
  44.   #Colore del testo:
  45.   Colore = Color.new(255,255,255)#(Rosso,Verde,Blu) da 0 a 255
  46. end
  47.  
  48. #===============================================================================
  49. # ** Classe Scene_Ending
  50. #===============================================================================
  51. class Scene_Ending < Scene_Base
  52.   include H87_Ending
  53.   def start
  54.     super
  55.     @timecount = 0
  56.     create_menu_background
  57.     carica_testo
  58.     crea_finestra
  59.   end
  60.  
  61.   #-----------------------------------------------------------------------------
  62.   # * Carica il testo dal file
  63.   #-----------------------------------------------------------------------------
  64.   def carica_testo
  65.     if File.exist? (Nome_File) #apre il file in sola lett.
  66.       array = []
  67.       File.open(Nome_File,"r") do |f|
  68.         f.each_line {|riga| array.push(riga.to_s)}
  69.         @testo = array
  70.       end
  71.     else
  72.       p "File non trovato"
  73.       @testo = "Vuoto"
  74.     end
  75.   end
  76.  
  77.   #-----------------------------------------------------------------------------
  78.   # * Crea la finestra del testo
  79.   #-----------------------------------------------------------------------------
  80.   def crea_finestra
  81.     @quadrato = Viewport.new(0,0,Graphics.width,Graphics.height)
  82.     @finestra = Ending_Text.new(@testo)
  83.     @finestra.viewport = @quadrato
  84.     @finestra.y = Graphics.height
  85.   end
  86.  
  87.   #-----------------------------------------------------------------------------
  88.   # * aggiornamento
  89.   #-----------------------------------------------------------------------------
  90.   def update
  91.     super
  92.     aggiorna_finestra(Input.press?(Input::C))
  93.     close if @finestra.ended?
  94.   end
  95.  
  96.   #-----------------------------------------------------------------------------
  97.   # * aggiornamento del testo
  98.   #-----------------------------------------------------------------------------
  99.   def aggiorna_finestra(accelerato)
  100.     @timecount += 1
  101.     if @timecount >= Speed or accelerato
  102.       @finestra.y -= 1
  103.       @timecount = 0
  104.     end
  105.   end
  106.  
  107.   #-----------------------------------------------------------------------------
  108.   # * chiusura
  109.   #-----------------------------------------------------------------------------
  110.   def close
  111.     $scene = Scene_Map.new
  112.   end
  113.  
  114.   #-----------------------------------------------------------------------------
  115.   # * terminate
  116.   #-----------------------------------------------------------------------------
  117.   def terminate
  118.     super
  119.     dispose_menu_background
  120.     @finestra.dispose
  121.   end
  122. end
  123.  
  124. #===============================================================================
  125. # Classe Info_Text
  126. #===============================================================================
  127. class Ending_Text
  128.   include H87_Ending
  129.   attr_reader :height
  130.   attr_reader :width
  131.  
  132.   #-----------------------------------------------------------------------------
  133.   # * inizializzazione
  134.   #-----------------------------------------------------------------------------
  135.   def initialize(testo)
  136.     @tw = WLH
  137.     @testo = testo
  138.     @height = calc_lenght
  139.     @width = Graphics.width
  140.     @spritetext = Sprite.new
  141.     @spritetext.bitmap = create_bitmap
  142.   end
  143.  
  144.   #-----------------------------------------------------------------------------
  145.   # * restituisce la x
  146.   #-----------------------------------------------------------------------------
  147.   def x
  148.     return @spritetext.x
  149.   end
  150.  
  151.   #-----------------------------------------------------------------------------
  152.   # * restituisce la y
  153.   #-----------------------------------------------------------------------------
  154.   def y
  155.     return @spritetext.y
  156.   end
  157.  
  158.   #-----------------------------------------------------------------------------
  159.   # * imposta la x da valore
  160.   #-----------------------------------------------------------------------------
  161.   def x=(value)
  162.     @spritetext.x=value
  163.   end
  164.  
  165.   #-----------------------------------------------------------------------------
  166.   # * imposta la y da valore
  167.   #-----------------------------------------------------------------------------
  168.   def y=(value)
  169.     @spritetext.y=value
  170.   end
  171.  
  172.   #-----------------------------------------------------------------------------
  173.   # * imposta il viewport
  174.   #-----------------------------------------------------------------------------
  175.   def viewport=(viewport)
  176.     @spritetext.viewport = viewport
  177.   end
  178.  
  179.   #-----------------------------------------------------------------------------
  180.   # * imposta l'opacità
  181.   #-----------------------------------------------------------------------------
  182.   def opacity=(opa)
  183.     @spritetext.opacity = opa
  184.   end
  185.  
  186.   #-----------------------------------------------------------------------------
  187.   # * restituisce l'opacità
  188.   #-----------------------------------------------------------------------------
  189.   def opacity
  190.     return @spritetext.opacity
  191.   end
  192.    
  193.   #-----------------------------------------------------------------------------
  194.   # * calcola quanto è grande l'immagine
  195.   #-----------------------------------------------------------------------------
  196.   def calc_lenght
  197.     l = 0
  198.     for i in 0..@testo.size-1
  199.       if image?(@testo[i])
  200.         l += img_lenght(@testo[i])
  201.       else
  202.         l += @tw
  203.       end
  204.     end
  205.     return l+8
  206.   end
  207.  
  208.   #-----------------------------------------------------------------------------
  209.   # * il testo si riferisce ad un'immagine?
  210.   #-----------------------------------------------------------------------------
  211.   def image?(text)
  212.     return true if text[0..4].upcase == "[IMG]"
  213.   end
  214.  
  215.   #-----------------------------------------------------------------------------
  216.   # * calcola l'altezza dell'immagine del testo
  217.   #-----------------------------------------------------------------------------
  218.   def img_lenght(txt)
  219.     bitmap = Cache.picture(image_from_text(txt).chomp)
  220.     return bitmap.height
  221.   end
  222.  
  223.   #-----------------------------------------------------------------------------
  224.   # * prende il nome della picture
  225.   #-----------------------------------------------------------------------------
  226.   def image_from_text(txt)
  227.     return txt.gsub("[IMG]","")
  228.   end
  229.  
  230.   #-----------------------------------------------------------------------------
  231.   # * crea la bitmap principale
  232.   #-----------------------------------------------------------------------------
  233.   def create_bitmap
  234.     bitmap = Bitmap.new(@width,@height)
  235.     bitmap.font.color = Colore
  236.     bitmap.font.name = Name
  237.     bitmap.font.size = Size
  238.     bitmap.font.bold = Bold
  239.     bitmap.font.italic = Italic
  240.     bitmap.font.shadow = Shadow
  241.     l = 4
  242.     @lenght = l #meglio usare una variabile d'istanza...
  243.     for i in 0..@testo.size-1
  244.       fetch_text(@testo[i],bitmap)
  245.     end
  246.     return bitmap
  247.   end
  248.  
  249.   #-----------------------------------------------------------------------------
  250.   # * crea il testo al rigo designato
  251.   #-----------------------------------------------------------------------------
  252.   def fetch_text(text,bitmap)
  253.     if image?(text) #se è un immagine
  254.       text.chomp!
  255.       bitmap2 = Cache.picture(image_from_text(text))
  256.       x = (@width - bitmap2.width)/2
  257.       rect = Rect.new(0,0,bitmap2.width,bitmap2.height)
  258.       bitmap.blt(x, @lenght, bitmap2, rect)
  259.       @lenght += bitmap2.height
  260.     else #se è del normale testo
  261.       bitmap.draw_text(4,@lenght,self.width-4,@tw,formatted_text(text),1)
  262.       @lenght += @tw
  263.     end
  264.   end
  265.  
  266.   #-----------------------------------------------------------------------------
  267.   # * dimissione dello sprite
  268.   #-----------------------------------------------------------------------------
  269.   def dispose
  270.     @spritetext.dispose
  271.   end
  272.  
  273.   #-----------------------------------------------------------------------------
  274.   # * formatta il rigo
  275.   #-----------------------------------------------------------------------------
  276.   def formatted_text(text)
  277.     text.gsub!("\n","") if text.gsub("\n","") != nil
  278.     text.gsub!("[R]","®")
  279.     text.gsub!("[C]","©")
  280.     text.gsub!("[L]","♥")
  281.     text.gsub!("[S]","★")
  282.     text.gsub!("[B]","●")
  283.     return text
  284.   end
  285.  
  286.   #-----------------------------------------------------------------------------
  287.   # * restituisce true se i titoli di coda sono finiti
  288.   #-----------------------------------------------------------------------------
  289.   def ended?
  290.     return true if self.y <=  0-self.height
  291.     return false
  292.   end
  293.  
  294. end #infotext
  295.  
  296. #===============================================================================
  297. # ** Classe Game_Interpreter
  298. #===============================================================================
  299. class Game_Interpreter
  300.   def call_credits
  301.     $scene = Scene_Ending.new
  302.   end
  303. end #game_interpreter
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement