Advertisement
Caeles

Código Taller PLW - Interfaz de vida

Jun 25th, 2022
1,181
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.11 KB | None
  1. ################################################################################
  2. #SCRIPT DE INTERFAZ DE VIDA
  3. #Créditos a Polectron
  4. #
  5. #Este script permite mostrar una interfaz de vida al jugador dibujando un gráfico.
  6. #Fue desarrollado para un taller de la comunidad de PokéLiberty como ejemplo
  7. #de mecánica.
  8. #
  9. #Más información en: https://newpokeliberty.blogspot.com
  10. #o en el discord https://discord.gg/8BQfSkD
  11. ################################################################################
  12.  
  13. class PokeBattle_Trainer
  14.   attr_accessor :pv
  15.  
  16.   def pv
  17.       @pv = 100 if !@pv
  18.       return @pv
  19.   end
  20. end
  21.  
  22. module PBTerrain
  23.   ToxicWater = 20
  24.  
  25.   class << self
  26.       alias isWaterOriginal?          isWater?        
  27.       alias isPassableWaterOriginal?  isPassableWater?
  28.       alias  isJustWaterOriginal?     isJustWater?    
  29.   end
  30.  
  31.   def PBTerrain.isWater?(tag)
  32.       return PBTerrain.isWaterOriginal?(tag) ||
  33.           tag==PBTerrain::ToxicWater
  34.   end
  35.  
  36.   def PBTerrain.isPassableWater?(tag)
  37.       return PBTerrain.isPassableWaterOriginal?(tag) ||
  38.           tag==PBTerrain::ToxicWater
  39.   end
  40.  
  41.   def PBTerrain.isJustWater?(tag)
  42.       return PBTerrain.isJustWaterOriginal?(tag) ||
  43.           tag==PBTerrain::ToxicWater
  44.   end
  45.  
  46.   def PBTerrain.isToxic?(tag)
  47.       return tag==PBTerrain::ToxicWater
  48.   end
  49. end
  50.  
  51. Events.onStepTakenTransferPossible+=proc {|sender,e|
  52. if $PokemonGlobal.stepcount % 1 == 0
  53.       tag = pbGetTerrainTag($game_player)
  54.       if PBTerrain.isToxic?(tag)
  55.           $Trainer.pv-=1
  56.           $Trainer.pv=0 if $Trainer.pv<0
  57.       end
  58. end
  59. }
  60.  
  61. class Game_Player
  62.  
  63.   alias  update_original update
  64.  
  65.   def update
  66.       if PBTerrain.isToxic?(pbGetTerrainTag)
  67.           @move_speed = $RPGVX ? 3.5 : 2.8
  68.       end
  69.       update_original
  70.   end
  71. end
  72.  
  73. class Spriteset_Map
  74. class Life_HUD
  75.  
  76.   # Make as 'true' to only show HUD in the pause menu
  77.   DRAWONLYINMENU=false
  78.  
  79.   # Make as 'false' to don't show the hp bars
  80.   SHOWHPBARS=true
  81.  
  82.   # When above 0, only displays HUD when this switch is on.
  83.   SWITCHNUMBER = 0
  84.  
  85.   def initialize(viewport1)
  86.     @viewport1 = viewport1
  87.     @sprites = {}
  88.     @yposition = Graphics.height-64
  89.     @zposition = 99999999
  90.   end
  91.  
  92.   def showHUD?
  93.     return (
  94.       $Trainer &&
  95.       (SWITCHNUMBER<=0 || $game_switches[SWITCHNUMBER]) &&
  96.       (!DRAWONLYINMENU || $game_temp.in_menu)
  97.     )
  98.   end
  99.  
  100.   def create
  101.     @sprites["heart"]=IconSprite.new(4,@yposition+5,@viewport1)
  102.     @sprites["heart"].setBitmap("Graphics/Pictures/heart")
  103.     @sprites["heart"].z = @zposition
  104.   end
  105.  
  106.   def drawText
  107.     baseColor=Color.new(72,72,72)
  108.     shadowColor=Color.new(160,160,160)
  109.  
  110.     if @sprites.include?("overlay")
  111.       @sprites["overlay"].bitmap.clear
  112.     else
  113.       width = Graphics.width
  114.       @sprites["overlay"] = BitmapSprite.new(width,64,@viewport1)
  115.       @sprites["overlay"].y = @yposition-10
  116.       @sprites["overlay"].z = @zposition
  117.  
  118.     end
  119.  
  120.     textPositions=[
  121.       [$Trainer.pv.to_s,66,20,2,baseColor,shadowColor],
  122.     ]
  123.  
  124.     pbSetSystemFont(@sprites["overlay"].bitmap)
  125.     pbDrawTextPositions(@sprites["overlay"].bitmap,textPositions)
  126.   end
  127.  
  128.   def drawPV
  129.     @sprites["bar"]=IconSprite.new(0,@yposition,@viewport1)
  130.     barBitmap = Bitmap.new($Trainer.pv,8)
  131.     barRect = Rect.new(38,0,barBitmap.width,barBitmap.height)
  132.     barBitmap.fill_rect(barRect,Color.new(0, 255, 0))
  133.     @sprites["bar"].bitmap = barBitmap
  134.     @sprites["bar"].z = @zposition
  135.  
  136.   end
  137.  
  138.   def update
  139.     if showHUD?
  140.       if @sprites.empty?
  141.         create
  142.       else
  143.         if Graphics.frame_count%5==0
  144.           drawText
  145.           drawPV
  146.         end
  147.       end
  148.       pbUpdateSpriteHash(@sprites)
  149.     else
  150.       dispose if !@sprites.empty?
  151.     end
  152.   end
  153.  
  154.   def dispose
  155.     pbDisposeSpriteHash(@sprites)
  156.   end
  157.  
  158. end
  159.  
  160. alias :initializeOldLife :initialize
  161. alias :disposeOldLife :dispose
  162. alias :updateOldLife :update
  163.  
  164. def initialize(map=nil)
  165.   initializeOldLife(map)
  166. end
  167.  
  168. def dispose
  169.   @life_hud.dispose if @life_hud
  170.   disposeOldLife
  171. end
  172.  
  173. def update
  174.   updateOldLife
  175.   @life_hud = Life_HUD.new(@viewport1) if !@life_hud
  176.   @life_hud.update
  177. end
  178.  
  179. end
  180.  
Advertisement
RAW Paste Data Copied
Advertisement