Guest User

Pokemon-like badge system

a guest
Feb 25th, 2013
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 5.87 KB | None | 0 0
  1. #~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#
  2. # --------credits--------
  3. # * Diagostimo for composing this script
  4. # * Darkness for requesting it
  5. #
  6. # ------Author Notes------
  7. # * this script shows badge images and details depending if they have been
  8. # obtained or not
  9. #
  10. # * to call the script use this script call : "$scene = Scene_Badges.new"
  11. #
  12. # * to add badges to your possesion use this script call : "$game_system.badge_array.push(BADGE_ID)"
  13. # or you can push multiple like so : "$game_system.badge_array.push(BADGE_ID, BADGE_ID, BADGE_ID)"
  14. #
  15. # * add the graphics of the badge to the pictures directory and call it "badge'BADGE_ID'"
  16. # so for example I add badge 1 : "badge1.png"
  17. #
  18. # * if for any reason you need to remove a badge from your possesion you use
  19. # this script call : "$game_system.badge_array.delete(BADGE_ID)"
  20. #
  21. # * if you want to have a conditional branch inside an event to condition to a
  22. # badge been in possesion use this script call : "$game_system.badge_array.include?(BADGE_ID)"
  23. #
  24. # * see below for all other related configuration, note this script only supports
  25. # 8 badges like pokemon games, adding more details/images for other values than
  26. # specified will simply be ingnored, also note that badge images should be 32x32 sized images.
  27. #
  28. #~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#
  29. #
  30. #                        C O N F I G U R A T I O N                         
  31. #
  32. #~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#
  33. module Badges
  34. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-#
  35. # * set the image opacity for badges not in possession
  36. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-#
  37. NOT_POSSESSION_OPACITY = 100 #255 max, 0 min
  38. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
  39. # * configure the following descriptions for badges IN possession
  40. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
  41. def self.badge_in_possession(index)
  42. case index
  43.      when 1 then 'this is the first description'
  44.      when 2 then 'this is the second description'
  45.      when 3 then 'this is the third description'
  46.      when 4 then 'this is a really long description, long long long long long long long long long long long long.'
  47.      when 5 then 'and so on'
  48.      when 6 then 'and so on'
  49.      when 7 then 'and so on'
  50.      when 8 then 'and so on'
  51. end
  52. end
  53. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
  54. # * configure the following descriptions for badges NOT in possession
  55. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
  56. def self.badge_not_in_possession(index)
  57. case index
  58.      when 1 then 'not in possesion 1'
  59.      when 2 then 'not in possesion 2'
  60.      when 3 then 'not in possesion 3'
  61.      when 4 then 'not in possesion 4'
  62.      when 5 then 'not in possesion 5'
  63.      when 6 then 'not in possesion 6'
  64.      when 7 then 'not in possesion 7'
  65.      when 8 then 'not in possesion 8'
  66. end
  67. end
  68. end
  69. #~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#
  70. #
  71. #                    E N D C O N F I G U R A T I O N
  72. #
  73. #~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#
  74. class Bitmap
  75. def format_text(text, width)
  76. words = text.split(' ')
  77. return words if words.size == 1
  78. result, current_text = [], words.shift
  79. words.each_index {|i|
  80.      if self.text_size("#{current_text} #{words[i]}").width > width
  81.          result.push(current_text)
  82.          current_text = words[i]
  83.      else
  84.          current_text = "#{current_text} #{words[i]}"
  85.      end
  86.      result.push(current_text) if i >= words.size - 1}
  87. return result
  88. end
  89. end
  90. class Game_System
  91. attr_accessor :badge_array
  92. alias init_init initialize
  93. def initialize
  94. init_init
  95. @badge_array = []
  96. end
  97. end
  98. class Window_Badges < Window_Base
  99. attr_reader :index
  100. def initialize
  101. centre = (640 - 288) / 2
  102. super(centre, 0, 288, 64)
  103. self.contents = Bitmap.new(width - 32, height - 32)
  104. self.index = 0
  105. refresh
  106. end
  107. def index=(index)
  108. @index = index
  109. update_cursor_rect
  110. end
  111. def update_cursor_rect
  112. x = 0 + @index * 32
  113. y = 0
  114. self.cursor_rect.set(x, y, 32, 32)
  115. end
  116. def refresh
  117. self.contents.clear
  118. for i in 1..8
  119.      @bitmap = RPG::Cache.picture("badge#{i}")
  120.      x = 0 + (i - 1) % 8 * 32
  121.      rect = Rect.new(0, 0, @bitmap.width, @bitmap.height)
  122.      if $game_system.badge_array.include?(i)
  123.      self.contents.blt(x, 0, @bitmap, rect, 255)
  124.      else
  125.      self.contents.blt(x, 0, @bitmap, rect, Badges::NOT_POSSESSION_OPACITY)
  126.      end
  127. end
  128. end
  129. def update
  130. super
  131. if Input.repeat?(Input::RIGHT) && @index < 7
  132.      @index += 1
  133.      $game_system.se_play($data_system.cursor_se)
  134. end
  135. if Input.repeat?(Input::LEFT) && @index > 0
  136.      @index -= 1
  137.      $game_system.se_play($data_system.cursor_se)
  138. end
  139. update_cursor_rect
  140. refresh
  141. end
  142. end
  143. class Window_Badge_Description < Window_Base
  144. attr_accessor :text
  145. def initialize
  146. @text = ''
  147. super(0, 0, 288, 128)
  148. self.contents = Bitmap.new( width - 32, height - 32)
  149. end
  150. def refresh
  151. self.contents.clear
  152. text = self.contents.format_text(@text, 256)
  153. text.each_index {|i|
  154.      self.contents.draw_text(0, 0 + i*32, 256, 32, text[i])}
  155. end
  156. def update
  157. super
  158. refresh
  159. end
  160. end
  161. class Scene_Badges
  162. def main
  163. @badges_window = Window_Badges.new
  164. @description_window = Window_Badge_Description.new
  165. @badges_window.y = (480 - @description_window.height) - @badges_window.height
  166. @description_window.y = @badges_window.y + @badges_window.height
  167. @description_window.x = @badges_window.x
  168. @sprite = Spriteset_Map.new
  169. Graphics.transition
  170. loop { Graphics.update; Input.update; update; break if $scene != self }
  171. @badges_window.dispose
  172. @description_window.dispose
  173. end
  174. def update
  175. $scene = Scene_Map.new if Input.trigger?(Input::B)
  176. if $game_system.badge_array.include?(@badges_window.index + 1)
  177.      @description_window.text = Badges.badge_in_possession(@badges_window.index + 1)
  178. else
  179.      @description_window.text = Badges.badge_not_in_possession(@badges_window.index + 1)
  180. end
  181. @badges_window.update
  182. @description_window.update
  183. end
  184. end
Advertisement
Add Comment
Please, Sign In to add comment