Guill

GI_HUD & GI_Actor 1.1

Nov 6th, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.17 KB | None | 0 0
  1. #===============================================================================
  2. #                      G I _ H U D   &   G I _ A c t o r
  3. #===============================================================================
  4. # Usage Terms
  5. #-------------------------------------------------------------------------------
  6. #   The following script was developed exclusively to Wonderland Project and
  7. # anyone else should match the conditions below by under penalty of having longs
  8. # and strange conversations about rules, and of being overspammed with game
  9. # envites at its facebook profile.
  10. #
  11. # * To use tihs script you must first contact the original creator Guill by one
  12. # of the contact ways at the end of this register.
  13. #
  14. # * You you are not allowed to post this script in any forum or internet page
  15. # without a previous authorization given by the original creator Guill.
  16. #-------------------------------------------------------------------------------
  17. # How to Use
  18. #-------------------------------------------------------------------------------
  19. # 1: Paste the attached pictures at "Project/Graphics/Pictures" folder.
  20. # 2: Go to Configuration section at line 34 and set your preferences.
  21. # 3: Go to Commands section at line 24 and learn the basic functions.
  22. # 4: Type the functions at Event's Call Script command.
  23. #-------------------------------------------------------------------------------
  24. # Commands
  25. #-------------------------------------------------------------------------------
  26. # $gi_actor.heal(n) -> Heals the player in <n> health points.
  27. # $gi_actor.hurt(n) -> Hurts the player in <n> health points.
  28. # $gi_actor.grow_life(n) -> Enhance player's life by <n> hearts.
  29. # $gi_actor.get_key(x) -> Add <x> key.
  30. # Where <x> must be in ["cup","sword","club","gold"]
  31. # $gi_actor.drop_key -> Drop player's atual key.
  32. # $char_hud.change_face(x) -> Change HUD face to "<x>.png".
  33. #-------------------------------------------------------------------------------
  34. # Configuration
  35. #-------------------------------------------------------------------------------
  36. module GI_HUD_Config
  37. # Change the values after "=" by your preferences
  38.   X = 0 # HUD screen X position in pixels
  39.   Y = 0 # HUD screen Y position in pixels
  40.   BG = "HUDBG.png" # File name at HUD background's image
  41.   Heart = "Heart.png" # File name at empty heart image
  42.   P1 = "P1.png" # File name at default player image
  43.   Z = 90 # HUD screen Z position
  44.   HUD_Switch = 1 # Visibility yelding switch
  45.   # Put true if you want to regerate life when growing a new heart
  46.   # Put false to otherwise
  47.   Renew_Life = false
  48. end
  49. #-------------------------------------------------------------------------------
  50. #                       DO NOT CHANGE EVEN A DOT BELOW
  51. #-------------------------------------------------------------------------------
  52.  
  53. class Spriteset_Map
  54.   alias gi_ini initialize
  55.   alias gi_upd update
  56.   alias gi_dis dispose
  57.   def initialize
  58.     gi_ini
  59.     $gi_actor = GI_Actor.new
  60.     $char_hud = GI_HUD.new
  61.   end  
  62.   def update
  63.     $char_hud.update if not $char_hud == nil
  64.     gi_upd    
  65.   end
  66.   def dispose
  67.     $char_hud.dispose if not $char_hud == nil
  68.     gi_dis
  69.   end  
  70. end
  71.  
  72. class GI_Actor
  73.   attr_accessor :max_life  
  74.   attr_accessor :life
  75.   attr_accessor :key
  76.   def initialize
  77.     self.life = 12
  78.     self.max_life = 12
  79.     self.key = ""
  80.   end
  81.   def grow_life(n)
  82.     $char_hud.grow_heart(n)
  83.   end
  84.   def hurt(n)
  85.     $char_hud.drop_life(n)
  86.     SceneManager.goto(Scene_Gameover) if self.life == 0
  87.   end
  88.   def heal(n)
  89.     $char_hud.add_life(n)
  90.   end
  91.   def get_key(x)
  92.     if self.key == ""
  93.       $char_hud.add_key(x)
  94.       self.key = x
  95.     end  
  96.   end
  97.   def drop_key
  98.     if not self.key == ""
  99.       $char_hud.drop_key
  100.       self.key = ""
  101.     end
  102.   end
  103. end
  104.  
  105. class GI_HUD
  106.   include GI_HUD_Config
  107.   def initialize
  108.     @vp = Viewport.new(0,0,544,416)
  109.     @vp.z = Z
  110.     @bg = Sprite.new(@vp)
  111.     @bg.x = X
  112.     @bg.y = Y
  113.     @bg.bitmap = Cache.picture(BG)
  114.     @bg.z = 1
  115.     @hearts = []
  116.     i = 0
  117.     while i < 3 do
  118.       @hearts[i] = Sprite.new(@vp)
  119.       @hearts[i].x = X + 50 + (18 * i)
  120.       @hearts[i].y = Y + 8
  121.       @hearts[i].bitmap = Cache.picture(Heart)  
  122.       @hearts[i].z = 4 + i
  123.       i += 1
  124.     end
  125.     @player = Sprite.new(@vp)
  126.     @player.x = X + 3
  127.     @player.y = Y
  128.     @player.bitmap = Cache.picture(P1)
  129.     @player.z = 2
  130.     @key = Sprite.new(@vp)
  131.     @key.x = X + 160
  132.     @key.y = Y + 8
  133.     @key.z = 3
  134.     @life = $gi_actor.life
  135.     @max_life = $gi_actor.max_life
  136.     @lifes = []
  137.     i = 0
  138.     @liner = 8
  139.     @h_liner = 8
  140.     while i < 3 do
  141.       draw_heart(i,4,i)
  142.       i += 1
  143.     end
  144.   end
  145.   def update
  146.     @bg.update
  147.     @player.update
  148.     @key.update
  149.     @hearts.each do |i|    
  150.         i.update if not i.disposed?
  151.     end
  152.     @lifes.each do |i|    
  153.         i.update if not i.disposed?  
  154.     end
  155.     $gi_actor.life = @life
  156.     $gi_actor.max_life = @max_life
  157.     if $game_switches[HUD_Switch]
  158.       @vp.visible = true
  159.     else
  160.       @vp.visible = false
  161.     end      
  162.   end
  163.   def dispose
  164.     @bg.dispose
  165.     @player.dispose
  166.     @key.dispose
  167.     @hearts.each do |i|    
  168.         i.dispose if not i == nil  
  169.     end
  170.     @lifes.each do |i|    
  171.         i.dispose if not i == nil  
  172.     end  
  173.   end
  174.   def change_face(x)
  175.     if File.exists("graphics/pictures/" + x + ".png")
  176.       @player = Sprite.new(@vp)
  177.       @player.x = X + 3
  178.       @player.y = Y
  179.       @player.bitmap = Cache.picture(x + ".png")
  180.       @player.z = 2
  181.     end  
  182.   end
  183.   def drop_life(n)      
  184.     aux = @life - n
  185.     @life = 0
  186.     @lifes.each do |i|    
  187.         i.dispose if not i == nil  
  188.     end
  189.     add_life(aux)
  190.   end
  191.   def grow_heart(n)
  192.     aux = @max_life + n * 4
  193.     while aux > 48 do
  194.       aux -= 4
  195.       n -= 1
  196.     end
  197.     if n == 0
  198.       return
  199.     end
  200.     n -= 1
  201.     heart_n = (@max_life / 4).to_i
  202.     i = heart_n
  203.     while n >= 0 do
  204.       i = 0 if heart_n == 6
  205.       i = 1 if heart_n == 7  
  206.       i = 2 if heart_n == 8
  207.       i = 3 if heart_n == 9
  208.       i = 4 if heart_n == 10
  209.       i = 5 if heart_n == 11
  210.       if @max_life < 24
  211.         @h_liner = 8
  212.       else  
  213.         @h_liner = 22
  214.       end
  215.       @hearts[heart_n] = Sprite.new(@vp)
  216.       @hearts[heart_n].x = X + 50 + (18 * i)
  217.       @hearts[heart_n].y = Y + @h_liner
  218.       @hearts[heart_n].bitmap = Cache.picture(Heart)  
  219.       @hearts[heart_n].z = 4 + heart_n
  220.       @max_life += 4
  221.       i += 1
  222.       heart_n += 1
  223.       n -= 1
  224.     end  
  225.     if Renew_Life
  226.       n = @max_life - @life
  227.       add_life(n)      
  228.     end  
  229.   end
  230.   def add_life(n)
  231.     aux = @life + n
  232.     while aux > @max_life do
  233.       aux -= 1
  234.       n -= 1
  235.     end  
  236.     if n == 0 then return; end
  237.     life = @life % 4
  238.     heart_n = (@life / 4).to_i
  239.     @life -= life
  240.     if not @lifes[heart_n] == nil
  241.       @lifes[heart_n].dispose
  242.       @lifes[heart_n] = nil
  243.     end  
  244.     n += life
  245.     while n > 3 do
  246.       draw_heart(heart_n,4,heart_n)
  247.       @life += 4
  248.       heart_n += 1
  249.       n -= 4
  250.     end
  251.     if n > 0
  252.       draw_heart(heart_n,n,heart_n)
  253.       @life += n
  254.     end
  255.   end
  256.   def draw_heart(s,k,i)
  257.     if i == 6 then i = 0 end; if i == 7 then i = 1 end
  258.     if i == 8 then i = 2 end; if i == 9 then i = 3 end
  259.     if i == 10 then i = 4 end; if i == 11 then i = 5 end
  260.     if @life < 24
  261.       @liner = 8
  262.     else  
  263.       @liner = 22
  264.     end  
  265.     @lifes[s.to_i] = Sprite.new(@vp)
  266.     @lifes[s.to_i].x = X + 50 + 18 * i
  267.     @lifes[s.to_i].y = Y + @liner
  268.     @lifes[s.to_i].z = 16 + s.to_i
  269.     @lifes[s.to_i].bitmap = Cache.picture(k.to_s + ".png")
  270.   end
  271.   def add_key(x)
  272.     @key.bitmap = Cache.picture(x + "_k.png")
  273.   end
  274.   def drop_key
  275.     @key.bitmap.dispose
  276.     @key.bitmap = nil
  277.     @key = Sprite.new(@vp)
  278.     @key.x = X + 160
  279.     @key.y = Y + 8
  280.     @key.z = 3  
  281.   end
  282. end
  283. #===============================================================================
  284. # Contacts
  285. #-------------------------------------------------------------------------------
  286. # Forum Mundo RPG Maker: http://forums.mundorpgmaker.com.br/index.php?action=profile;u=57956
  287. # Facebook Page: https://www.facebook.com/souza.psg
  288. #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment