Advertisement
Zetu

Z20 : Achievements v1.01

Jul 11th, 2011
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.61 KB | None | 0 0
  1. module Z20
  2.   LockedIndex   = 96
  3.   BarGraphic    = "AchievementBar"
  4.   Unknown       = "Achievement Locked!"
  5.   DATA = [
  6.     ["Game.new",                5, "Accept the mission.",                :fenixfx],
  7.     ["Airport Security",        6, "Have CaptainJet join the party",     :captainjet],
  8.     ["Is it cold in here?",     7, "Have IceDragon join the party",      :icedragon],
  9.     ["It takes four to Stabby", 8, "Have Zetu join the party",           :zetu],
  10.     ["Divide By Zero",          4, "Divide by Zero in the Menu Screen.", :divzero]
  11.   ]
  12.  
  13.   DURATION = 300  #### HARDCODED FOR NOW D:<
  14.  
  15.   def self.achieve(symbol)
  16.     for i in 0...DATA.size
  17.       if symbol == DATA[i][3]
  18.         unlock(i)
  19.         return
  20.       end
  21.     end
  22.   end
  23.  
  24.   def self.unlock(i)
  25.     return false if DATA[i].nil?
  26.     if $game_party.achieve.include?(i)
  27.       return false
  28.     else
  29.       $game_party.achieve.push(i)
  30.       $scene.popup(i)
  31.       return true
  32.     end
  33.   end
  34.  
  35.   def self.description(i)
  36.     return Unknown unless $game_party.achieve.include?(i)
  37.     title       = DATA[i][0]
  38.     description = DATA[i][2]
  39.     return "Achievement: \"#{title}\". \"#{description}\""
  40.   end
  41.  
  42.   def self.stats
  43.     amount = $game_party.achieve.size
  44.     ratio = amount*100 / DATA.size
  45.     return "#{amount} Achievements Unlocked! (#{ratio}%)"
  46.   end
  47.  
  48. end
  49.  
  50. class Z20_Achievements < Scene_Base
  51.  
  52.   def initialize
  53.     @help_window = Window_Help.new
  54.     @stats_window = Window_Help.new
  55.     @stats_window.y = 56
  56.     @stats_window.set_text(Z20.stats)
  57.     @data_window = Window_Achieve.new(0, 112, 640, 368)
  58.     @last_index = -2
  59.   end
  60.  
  61.   def update
  62.     @data_window.update
  63.     if @last_index != @data_window.index
  64.       @last_index = @data_window.index
  65.       @help_window.set_text(Z20.description(@data_window.index))
  66.     end
  67.     if Input.trigger?(Input::B)
  68.       $scene = Scene_Menu.new(0)
  69.     end
  70.   end
  71.  
  72.   def terminate
  73.     @data_window.dispose
  74.     @help_window.dispose
  75.     @stats_window.dispose
  76.   end
  77.  
  78. end
  79.  
  80. class Window_Achieve < Window_Command
  81.  
  82.   def initialize(x, y, width, height)
  83.     column_max = (width-32) / 24
  84.     commands = Z20::DATA
  85.     row_max = (commands.size + column_max - 1) / column_max
  86.     super(width, commands, column_max, 0, 0)
  87.     self.x = x
  88.     self.y = y
  89.     self.height = height
  90.     @item_max = commands.size
  91.     refresh
  92.     self.index = 0
  93.   end
  94.  
  95.   def draw_item(index, enabled = true)
  96.     rect = item_rect(index)
  97.     self.contents.clear_rect(rect)
  98.     self.contents.font.color = normal_color
  99.     self.contents.font.color.alpha = enabled ? 255 : 128
  100.     enabled = $game_party.achieve.include?(index)
  101.     if enabled
  102.       index = Z20::DATA[index][1]
  103.     else
  104.       index = Z20::LockedIndex
  105.     end
  106.     draw_icon(index, rect.x, rect.y-1, enabled)
  107.   end
  108.  
  109. end
  110.  
  111. class Game_Party
  112.   attr_accessor :achieve
  113.  
  114.   alias z20_initialize initialize
  115.   def initialize
  116.     z20_initialize
  117.     @achieve = []
  118.   end
  119.  
  120. end
  121.  
  122. class Scene_Base
  123.  
  124.   def popup(i)
  125.     clear_ach
  126.     Sound.play_decision
  127.     @z20_timer = Z20::DURATION
  128.     @achsprite = Sprite.new
  129.     @achsprite.bitmap = Cache.system(Z20::BarGraphic)
  130.     @achsprite.x = (640 - @achsprite.bitmap.width) / 2
  131.     @achsprite.y =  480 - @achsprite.bitmap.height
  132.     tbitmap = Cache.system("Iconset")
  133.     icon_index = Z20::DATA[i][1]
  134.     rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  135.     @achsprite.bitmap.blt(4, 3, tbitmap, rect, 255)
  136.     tbitmap.dispose
  137.     text = Z20::DATA[i][0]
  138.     width = @achsprite.bitmap.width - 40
  139.     @achsprite.bitmap.draw_text(36, 3, width, 24, text)
  140.   end
  141.  
  142.   def update_achievement
  143.     return if @achsprite.nil?
  144.     sprite_update(@z20_timer)
  145.     clear_ach if @z20_timer == 0
  146.     @z20_timer -= 1
  147.   end
  148.  
  149.   def clear_ach
  150.     return if @achsprite.nil?
  151.     @achsprite.dispose
  152.     @achsprite = nil
  153.     @z20_timer = -1
  154.   end
  155.  
  156.   def sprite_update(i)
  157.     if i >= 270
  158.       @achsprite.opacity = scale_value(30, 255, 0, i-270)
  159.     elsif i <= 150
  160.       @achsprite.opacity = scale_value(150, 255, 0, 150-i)
  161.     end
  162.   end
  163.  
  164.   def scale_value(duration, min, max, time)
  165.     return (max - min)*time / duration + min
  166.   end
  167.  
  168. end
  169.  
  170. class Scene_Map < Scene_Base
  171.  
  172.   alias z20_update update
  173.   def update
  174.     z20_update
  175.     update_achievement
  176.   end
  177.  
  178.   alias z20_terminate terminate
  179.   def terminate
  180.     z20_terminate
  181.     clear_ach
  182.   end
  183.  
  184. end
  185.  
  186. class Scene_Menu < Scene_Base
  187.  
  188.   alias z20_update update
  189.   def update
  190.     z20_update
  191.     update_achievement
  192.   end
  193.  
  194.   alias z20_terminate terminate
  195.   def terminate
  196.     z20_terminate
  197.     clear_ach
  198.   end
  199.  
  200. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement