Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. module Lune_Sliding
  2. Game = []
  3.  
  4. #=======================================================
  5. # Sliding Puzzle Game
  6. # Author: Raizen
  7. # Comunity: www.centrorpg.com
  8. #
  9. # It is the basic sliding puzzle, sometimes known as
  10. # 15-puzzle/8-puzzle or gem puzzle.
  11. # To win you must complete the image
  12. #=======================================================
  13. # NOTE: The script CAN be added anytime during game development.
  14.  
  15.  
  16. # To call de script.
  17. # Script: slide_game(n)
  18. # where n is the game number, that can be configured below.
  19.  
  20.  
  21. # Speed at which the blocks move.
  22. Speed = 10
  23.  
  24. # Sound in the moment a block is moved.
  25. Sound_B = 'Wind7'
  26.  
  27. # Sound when you win the game.
  28. Victory = 'Decision2'
  29.  
  30. # The number of times the blocks are shuffled,
  31. # The higher the more shuffled, but takes more processing time to start.
  32.  
  33. Shuffle = 200
  34.  
  35.  
  36. # Create below the games that you wish, just do the following.
  37. # Game[n] = { Where n is the game number.
  38.  
  39.  
  40. # All images inside Graphics/Sliding
  41. #==============================================================================
  42. # Game 1 => Miku
  43. #==============================================================================
  44. Game[1] = {
  45. 'Background' => 'back1', # background image
  46. 'Image' => 'Miku', # Block Image
  47. 'Xaxis' => 3, # Number of blocks on X Axis
  48. 'Yaxis' => 3, # Number of blocks on Y Axis
  49. 'Escape?' => false, # Able to get out of the game without winning?
  50. 'Switch' => 1, # Switch activated after winning
  51. 'Music' => 'Dungeon6', # Game Music
  52. }
  53.  
  54. #==============================================================================
  55. # Game 2 => Misa
  56. #==============================================================================
  57. Game[2] = {
  58. 'Background' => 'back1', # background image
  59. 'Image' => 'Misa', # Block Image
  60. 'Xaxis' => 4, # Number of blocks on X Axis
  61. 'Yaxis' => 5, # Number of blocks on Y Axis
  62. 'Escape?' => true, # Able to get out of the game without winning?
  63. 'Switch' => 1, # Switch activated after winning
  64. 'Music' => 'Dungeon6', # Game Music
  65. }
  66. end
  67.  
  68. #==============================================================================
  69. # ** Scene_Panel
  70. #------------------------------------------------------------------------------
  71. # Esta classe é a classe principal do mini-game.
  72. #==============================================================================
  73.  
  74. class Scene_Panel < Scene_MenuBase
  75. include Lune_Sliding
  76. #--------------------------------------------------------------------------
  77. # * Inicialização do processo
  78. #--------------------------------------------------------------------------
  79. def start
  80. @map_bgm = RPG::BGM.last
  81. @map_bgs = RPG::BGS.last
  82. RPG::BGS.stop
  83. @game = Game[$config_panel_game]
  84. super
  85. create_game_variables
  86. create_game_pictures
  87. shuffle_board
  88. end
  89. #--------------------------------------------------------------------------
  90. # * Criação das variáveis
  91. #--------------------------------------------------------------------------
  92. def create_game_variables
  93. @speed = Speed
  94. @cursor = 0
  95. @aux = []
  96. @move = 0
  97. @block = []
  98. @direction = 0
  99. @count = 10
  100. @victory = false
  101. end
  102. #--------------------------------------------------------------------------
  103. # * Criação das Imagens
  104. #--------------------------------------------------------------------------
  105. def create_game_pictures
  106. @back = Sprite.new
  107. @im = Array.new
  108. RPG::BGM.new(@game['Music']).play
  109. @back.bitmap = Cache.sliding(@game['Background'])
  110. @back.x = (Graphics.width - @back.bitmap.width)/2
  111. @back.x = (Graphics.height - @back.bitmap.height)/2
  112. @map = Array.new(@game['Xaxis'])
  113. for n in 0...@game['Xaxis']
  114. @im[n] = Array.new
  115. @map[n] = Array.new
  116. end
  117. for x in 0...@game['Xaxis']
  118. for y in 0...@game['Yaxis']
  119. @im[x][y] = Sprite.new
  120. @im[x][y].bitmap = Cache.sliding(@game['Image'])
  121. @im[x][y].x = (Graphics.width - @im[x][y].bitmap.width)/2 + x*@im[x][y].bitmap.width/@game['Xaxis']
  122. @im[x][y].y = (Graphics.height - @im[x][y].bitmap.height)/2 + y*@im[x][y].bitmap.height/@game['Yaxis']
  123. @im[x][y].src_rect.set(x*@im[x][y].bitmap.width/@game['Xaxis'], y*@im[x][y].bitmap.height/@game['Yaxis'], @im[x][y].bitmap.width/@game['Xaxis'], @im[x][y].bitmap.height/@game['Yaxis'])
  124. @map[x][y] = [@im[x][y].x, @im[x][y].y]
  125. @im[x][y].bitmap = Cache.sliding('') if (x+1) == @game['Xaxis'] && (y+1) == @game['Yaxis']
  126. @map[x][y] = (x+1) + y*@game['Xaxis']
  127. end
  128. end
  129. @cursor = @game['Xaxis'] * @game['Yaxis']
  130. end
  131. #--------------------------------------------------------------------------
  132. # * Atualização da classe
  133. #--------------------------------------------------------------------------
  134. def update
  135. super
  136. if @victory
  137. return_scene if Input.trigger?(:B)
  138. return
  139. end
  140. return if block_moving?
  141. if Input.trigger?(:B)
  142. @game['Escape?'] ? return_scene : Sound.play_buzzer
  143. end
  144. move_block(Input.dir4)
  145. end
  146. #--------------------------------------------------------------------------
  147. # * Mover os quadros
  148. #--------------------------------------------------------------------------
  149. def block_moving?
  150. return false if @direction == 0
  151. x = @block[0]
  152. y = @block[1]
  153. case @direction
  154. when 8
  155. if @count < @speed
  156. @im[x][y].y -= (@im[x][y].bitmap.height/@game['Yaxis'])/@speed
  157. else
  158. @im[x][y].y -= @correctiony
  159. end
  160. when 6
  161. if @count < @speed
  162. @im[x][y].x += (@im[x][y].bitmap.width/@game['Xaxis'])/@speed
  163. else
  164. @im[x][y].x += @correctionx
  165. end
  166. when 4
  167. if @count < @speed
  168. @im[x][y].x -= (@im[x][y].bitmap.width/@game['Xaxis'])/@speed
  169. else
  170. @im[x][y].x -= @correctionx
  171. end
  172. when 2
  173. if @count < @speed
  174. @im[x][y].y += (@im[x][y].bitmap.height/@game['Yaxis'])/@speed
  175. else
  176. @im[x][y].y += @correctiony
  177. end
  178. end
  179. @count += 1
  180. if @count == (@speed + 1)
  181. @direction = 0
  182. if orded
  183. $game_switches[@game['Switch']] = true
  184. @victory = true
  185. RPG::SE.new(Victory).play
  186. end
  187. end
  188. true
  189. end
  190. #--------------------------------------------------------------------------
  191. # * Mover o bloco
  192. #--------------------------------------------------------------------------
  193. def move_block(dir)
  194. return if dir == 0
  195. @move = @map[(@cursor-1) % @game['Xaxis']][(@cursor-1)/@game['Xaxis']]
  196. @aux = [(@move-1) % @game['Xaxis'],(@move-1)/@game['Xaxis']]
  197. @old_cursor = @cursor
  198. case dir
  199. when 8
  200. if @cursor + @game['Xaxis'] <= @game['Xaxis']*@game['Yaxis']
  201. @cursor += @game['Xaxis']
  202. else
  203. return
  204. end
  205. when 6
  206. if (@cursor - 1) % @game['Xaxis'] != 0
  207. @cursor -= 1
  208. else
  209. return
  210. end
  211. when 4
  212. if @cursor % @game['Xaxis'] != 0
  213. @cursor += 1
  214. else
  215. return
  216. end
  217. when 2
  218. if @cursor - @game['Xaxis'] > 0
  219. @cursor -= @game['Xaxis']
  220. else
  221. return
  222. end
  223. end
  224. RPG::SE.new(Sound_B).play
  225. @move = @map[(@cursor-1) % @game['Xaxis']][(@cursor-1)/@game['Xaxis']]
  226. @block = [(@move-1) % @game['Xaxis'],(@move-1)/@game['Xaxis']]
  227. @old = @map[(@cursor-1) % @game['Xaxis']][(@cursor-1)/@game['Xaxis']]
  228. @map[(@cursor-1) % @game['Xaxis']][(@cursor-1)/@game['Xaxis']] = @map[(@old_cursor-1) % @game['Xaxis']][(@old_cursor-1)/@game['Xaxis']]
  229. @map[(@old_cursor-1) % @game['Xaxis']][(@old_cursor-1)/@game['Xaxis']] = @old
  230. @correctionx = @im[0][0].bitmap.width/@game['Xaxis'] % @speed
  231. @correctiony = @im[0][0].bitmap.height/@game['Yaxis'] % @speed
  232. @count = 0
  233. @direction = dir
  234. end
  235. #--------------------------------------------------------------------------
  236. # * Embaralhar o quadro
  237. #--------------------------------------------------------------------------
  238. def shuffle_board
  239. @count = 0
  240. while @count <= Shuffle
  241. move_shuffle
  242. block_shuffle
  243. @count+= 1
  244. end
  245. until @cursor == @game['Xaxis'] * @game['Yaxis']
  246. move_shuffle
  247. block_shuffle
  248. end
  249. @count = 0
  250. end
  251. #--------------------------------------------------------------------------
  252. # * Embaralhar os quadros
  253. #--------------------------------------------------------------------------
  254. def block_shuffle
  255. return false if @direction == 0
  256. x = @block[0]
  257. y = @block[1]
  258. case @direction
  259. when 8
  260. @im[x][y].y -= (@im[x][y].bitmap.height/@game['Yaxis'])
  261. when 6
  262. @im[x][y].x += (@im[x][y].bitmap.width/@game['Xaxis'])
  263. when 4
  264. @im[x][y].x -= (@im[x][y].bitmap.width/@game['Xaxis'])
  265. when 2
  266. @im[x][y].y += (@im[x][y].bitmap.height/@game['Yaxis'])
  267. end
  268. @direction = 0
  269. true
  270. end
  271. #--------------------------------------------------------------------------
  272. # * Embaralhar as variáveis
  273. #--------------------------------------------------------------------------
  274. def move_shuffle
  275. @move = @map[(@cursor-1) % @game['Xaxis']][(@cursor-1)/@game['Xaxis']]
  276. @aux = [(@move-1) % @game['Xaxis'],(@move-1)/@game['Xaxis']]
  277. @old_cursor = @cursor
  278. dir = (rand(4)+1)*2
  279. p dir
  280. case dir
  281. when 8
  282. if @cursor + @game['Xaxis'] <= @game['Xaxis']*@game['Yaxis']
  283. @cursor += @game['Xaxis']
  284. else
  285. return
  286. end
  287. when 6
  288. if (@cursor - 1) % @game['Xaxis'] != 0
  289. @cursor -= 1
  290. else
  291. return
  292. end
  293. when 4
  294. if @cursor % @game['Xaxis'] != 0
  295. @cursor += 1
  296. else
  297. return
  298. end
  299. when 2
  300. if @cursor - @game['Xaxis'] > 0
  301. @cursor -= @game['Xaxis']
  302. else
  303. return
  304. end
  305. end
  306. @move = @map[(@cursor-1) % @game['Xaxis']][(@cursor-1)/@game['Xaxis']]
  307. @block = [(@move-1) % @game['Xaxis'],(@move-1)/@game['Xaxis']]
  308. @old = @map[(@cursor-1) % @game['Xaxis']][(@cursor-1)/@game['Xaxis']]
  309. @map[(@cursor-1) % @game['Xaxis']][(@cursor-1)/@game['Xaxis']] = @map[(@old_cursor-1) % @game['Xaxis']][(@old_cursor-1)/@game['Xaxis']]
  310. @map[(@old_cursor-1) % @game['Xaxis']][(@old_cursor-1)/@game['Xaxis']] = @old
  311. @direction = dir
  312. end
  313. #--------------------------------------------------------------------------
  314. # * Verificação de vitória
  315. #--------------------------------------------------------------------------
  316. def orded
  317. for x in 0...@game['Xaxis']
  318. for y in 0...@game['Yaxis']
  319. return false unless @map[x][y] == (y*@game['Xaxis']+x+1)
  320. end
  321. end
  322. true
  323. end
  324. #--------------------------------------------------------------------------
  325. # * Retornar para cena anterior
  326. #--------------------------------------------------------------------------
  327. def return_scene
  328. super
  329. Sound.play_cancel
  330. @map_bgm.replay
  331. @map_bgs.replay
  332. for x in 0...@game['Xaxis']
  333. for y in 0...@game['Yaxis']
  334. @im[x][y].bitmap.dispose
  335. @im[x][y].dispose
  336. @back.dispose
  337. end
  338. end
  339. end
  340. end
  341.  
  342. #==============================================================================
  343. # ** Game_Interpreter
  344. #------------------------------------------------------------------------------
  345. # Um interpretador para executar os comandos de evento. Esta classe é usada
  346. # internamente pelas classes Game_Map, Game_Troop e Game_Event.
  347. #==============================================================================
  348.  
  349. class Game_Interpreter
  350. #--------------------------------------------------------------------------
  351. # * Inicialização do objeto
  352. # depth : profundidade
  353. #--------------------------------------------------------------------------
  354. def slide_game(index)
  355. $config_panel_game = index
  356. SceneManager.call(Scene_Panel)
  357. end
  358. end
  359.  
  360. #==============================================================================
  361. # ** Cache
  362. #------------------------------------------------------------------------------
  363. # Este modulo carrega cada gráfico, cria um objeto de Bitmap e retém ele.
  364. # Para acelerar o carregamento e preservar memória, este módulo matém o
  365. # objeto de Bitmap em uma Hash interna, permitindo que retorne objetos
  366. # pré-existentes quando mesmo Bitmap é requerido novamente.
  367. #==============================================================================
  368.  
  369.  
  370. module Cache
  371. #--------------------------------------------------------------------------
  372. # * Carregamento dos gráficos de batalha (piso)
  373. # filename : nome do arquivo
  374. # hue : informações da alteração de tonalidade
  375. #--------------------------------------------------------------------------
  376. def self.sliding(filename)
  377. load_bitmap("Graphics/Sliding/", filename)
  378. end
  379. end