Guest User

Untitled

a guest
Apr 6th, 2020
583
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.84 KB | None | 0 0
  1. INITONENTERING = false
  2. #Si es true, el contador comenzara nada mas entrar al mapa.
  3.  
  4. class Game_Player
  5.   attr_accessor :iluminationScene #Crea una variable en Game_Player para
  6.                                 #almacenar la clase desde la que se ejecuta todo
  7. end
  8.  
  9. def startDarkMapCounter(reset=false)
  10.   #Si se quiere que pueda resetear, se debe llamar con true
  11.   if onDarkMap?($game_map.map_id)
  12.     if reset
  13.       $game_player.iluminationScene=IlumScene.new
  14.     else
  15.       $game_player.iluminationScene||=IlumScene.new
  16.     end
  17.   else
  18.     Kernel.pbMessage("No estás en un mapa marcado como oscuro.")
  19.   end
  20. end
  21.  
  22. def onDarkMap?(map)
  23.   #Devuelve si el mapa tiene los metadatos requeridos para iniciar
  24.   return pbGetMetadata(map,MetadataDarkMap)
  25. end
  26. #Aquí modifico el proc que se ejecuta al cambiar de mapa:
  27. Events.onMapChanging+=proc{|sender,e|
  28.   if onDarkMap?(e[0])
  29.     $game_player.iluminationScene||=IlumScene.new if INITONENTERING
  30.     #Si es un mapa oscuro, lo crea y lo inicializa.
  31.   elsif $game_player.iluminationScene
  32.     #Si no es un mapa oscuro peor existe el grafico.
  33.     $game_player.iluminationScene.disposeAll
  34.     $game_player.iluminationScene=nil
  35.   end
  36. }
  37.  
  38. class IlumScene
  39.  
  40.   MAXTIME  =  10 #Segundos en acabarse la barra entera.
  41.  
  42.   def initialize
  43.     @bg=Sprite.new
  44.     @bg.bitmap = Bitmap.new("Graphics/Pictures/Fondo")
  45.     @bg.z=999999
  46.     @gauge=Sprite.new
  47.     @gauge.bitmap=Bitmap.new(Graphics.width,Graphics.height)
  48.     @gauge.z=999999
  49.     @maxframes=MAXTIME*Graphics.frame_rate
  50.     @onSceneFrames=0
  51.   end
  52.  
  53.   def update
  54.     #Actualización de la barra.
  55.     @onSceneFrames+=1
  56.    
  57.     width=472-472*(@onSceneFrames/@maxframes.to_f)
  58.     if width < 0; width = 0; end
  59.    
  60.     @gauge.bitmap.clear
  61.    
  62.     colors=
  63.     @gauge.bitmap.fill_rect(20,21,width,10,Color.new(246,215,11))
  64.     if width > 0 #Cuando se acaba...
  65.       if $PokemonTemp.darknessSprite && $PokemonTemp.darknessSprite.radius<176
  66.         $PokemonTemp.darknessSprite.radius+=4
  67.       end
  68.       $PokemonGlobal.flashUsed=true
  69.     else
  70.       if $PokemonTemp.darknessSprite && $PokemonTemp.darknessSprite.radius>64
  71.         $PokemonTemp.darknessSprite.radius-=4
  72.       end
  73.       $PokemonGlobal.flashUsed=false
  74.     end
  75.   end
  76.  
  77.   def addToTimer(int)
  78.     #Añade un número de segundos al contador.
  79.     @onSceneFrames-=(int*Graphics.frame_rate)
  80.     @onSceneFrames=0 if @onSceneFrames<0
  81.   end
  82.   def disposeAll
  83.     @bg.dispose if @bg
  84.     @gauge.dispose if @gauge
  85.   end
  86. end
  87.  
  88. module Graphics
  89.   #Actualización del Graphics.update para actualizar la barra a cada frame.
  90.   #Mientras estas en el menú, el tiempo sigue contando (TO DO)
  91.   class << self
  92.     alias_method :old_update, :update
  93.   end
  94.   def self.update
  95.     if $game_player && $game_player.iluminationScene
  96.       $game_player.iluminationScene.update
  97.     end
  98.     old_update
  99.   end
  100. end
Advertisement
Add Comment
Please, Sign In to add comment