Advertisement
Holy87

Ending Credits - Ace

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