#=============================================================================== # * Minigame Susun Gambar # by hart, ported to cross engine by LiTTleDRAgo #------------------------------------------------------------------------------- # Cara Pakai: # - Copy script ini ke script editor, di atas Main # - Panggil melalui event script: # # for RMXP and RMVX # $scene = Scene_SusunGambar.new(num_of_columns, num_of_rows, filename[, time]) # # for RMVXA # $scene_susun = [num_of_columns, num_of_rows, filename [, time]] # # num_of_columns = jumlah kolom yang diinginkan # num_of_rows = jumlah baris yang diinginkan # filename = nama file yang akan dijadikan gambar dari puzzle # (file boleh berukuran bebas, tapi sebaiknya jangan melebihi # screen, karena kacau ntar . Dan file gambar harus # disimpan di folder Graphics/Pictures) # time = batas waktu dalam detik. Kosongkan bila tidak ingin # memiliki waktu # # # - Setelah permainan selesai, switch yang telah diset di bawah akan menjadi # ON bila menang, dan OFF bila kalah, kemudian variabel yg telah diset di bawah # akan berisi sisa waktu ketika menyelesaikan permainan. #------------------------------------------------------------------------------- # Term Of Use: # - Terserah anda script ini mau diapain, dan tidak credit juga tidak apa-apa, # asalkan anda sopan dan menghargai sesama manusia #------------------------------------------------------------------------------- module SusunGambar #----------------------------------------------------------------------------- # RESULT_SWITCH_ID = ID switch untuk menyimpan hasil permainan # REMAINING_TIME_ID = ID variabel untuk menyimpan sisa waktu ketika selesai # BACKGROUND = Gambar Background dibelakang permainan # COMPLETE_SE = Suara yang keluar kalo menang (di Audio/SE) #----------------------------------------------------------------------------- RESULT_SWITCH_ID = 21 REMAINING_TIME_ID = 16 BACKGROUND = '' BACKGROUND_MOVING = true COMPLETE_SE = '060-Cheer01' VOCAB_WIN = 'Congratulations!' VX = defined?(Window_ActorCommand) VXA = defined?(Window_BattleActor) #----------------------------------------------------------------------------- end #=============================================================================== class Scene_SusunGambar def main start # Start processing perform_transition # Perform transition background Input.update # Update input information while scene == self # When screen is switched, interrupt loop Graphics.update # Update game screen Input.update # Update input information update # Update frame end Graphics.update Graphics.freeze # Prepare transition terminate # Termination processing end def update background_gerak update_sprite input || game_clear end def change_scene(somescene) SusunGambar::VXA ? SceneManager.call(somescene) : $scene = somescene.new end def scene() SusunGambar::VXA ? SceneManager.scene : $scene end def perform_transition() Graphics.transition(10) end def cache() SusunGambar::VX ? Cache : RPG::Cache end if SusunGambar::VXA def initialize return not_completed if !$scene_susun.is_a?(Array) num_of_columns = $scene_susun[0] num_of_rows = $scene_susun[1] filename = $scene_susun[2] time = $scene_susun[3] || -1 $scene_susun = [] init_susungambar(num_of_columns, num_of_rows, filename, time) end else def initialize(a,b,c,d=-1) init_susungambar(a,b,c,d) end end def init_susungambar(num_of_columns, num_of_rows, filename, time = -1) @num_of_columns = num_of_columns @num_of_rows = num_of_rows @image = filename.is_a?(Bitmap) ? filename : cache.picture(filename) @image_pieces = [] @num_of_cells = @num_of_columns * @num_of_rows @removed_cell = rand(@num_of_cells) @time = time @framecount = 0 @timesprite = Sprite.new @timesprite.x = 0 @timesprite.y = 0 @timesprite.z = 50 @timesprite.bitmap = Bitmap.new(544, 12) @timesprite.bitmap.font = Font.new('Arial', 12) end def start (0 ... @num_of_cells).each {|i| @image_pieces[i] = Sprite_ImagePieces.new(i) @image_pieces[i].bitmap = Bitmap.new(@image.width / @num_of_columns, @image.height / @num_of_rows) @image_pieces[i].bitmap.blt(0, 0, @image, Rect.new((i % @num_of_columns) * @image.width / @num_of_columns, (i / @num_of_columns) * @image.height / @num_of_rows, @image.width / @num_of_columns, @image.height / @num_of_rows))} @image_pieces[@removed_cell].opacity = 0 @image_pieces[@removed_cell].removed = true randomize_position() end def background @mnback = Plane.new @mnback.bitmap = cache.picture(SusunGambar::BACKGROUND) @mnback.blend_type = 0 @mnback.z = -6 @mnback2 = Plane.new @mnback2.bitmap = cache.picture(SusunGambar::BACKGROUND) @mnback2.blend_type = 0 @mnback2.z = -6 @mnback2.opacity = 60 end def background_gerak return if !SusunGambar::BACKGROUND_MOVING @mnback.oy += 1 @mnback.ox += 1 @mnback2.oy += 1 @mnback2.ox -= 1 end def randomize_position tmp = [] (0...@num_of_cells).each {|i| tmp.push(i)} @image_pieces.each {|i| @tmp2 = rand(tmp.size) i.pos = tmp[@tmp2] tmp.delete_at(@tmp2) tmp.sort!} end def terminate @image_pieces.each {|i| i.dispose} [@mnback, @mnback2].each {|i| i.dispose} @timesprite.dispose end def update_sprite @framecount += 1 if @time >= 0 if @framecount >= 60 @time -= 1 if @time > 0 @framecount = 0 end @timesprite.bitmap.clear @timesprite.bitmap.draw_text(0,0,544,12,"Time: " + @time.to_s) if @time >= 0 @image_pieces.each {|i| i.x = (i.pos % @num_of_columns) * @image.width / @num_of_columns i.y = (i.pos / @num_of_columns) * @image.height / @num_of_rows} end def input if Input.trigger?(Input::DOWN) if @image_pieces[@removed_cell].pos + @num_of_columns < @num_of_cells swap(@image_pieces[@removed_cell], get_piece_from_pos(@image_pieces[@removed_cell].pos + @num_of_columns)) end elsif Input.trigger?(Input::UP) if @image_pieces[@removed_cell].pos - @num_of_columns >= 0 swap(@image_pieces[@removed_cell], get_piece_from_pos(@image_pieces[@removed_cell].pos - @num_of_columns)) end elsif Input.trigger?(Input::LEFT) if @image_pieces[@removed_cell].pos % @num_of_columns != 0 swap(@image_pieces[@removed_cell], get_piece_from_pos(@image_pieces[@removed_cell].pos - 1)) end elsif Input.trigger?(Input::RIGHT) if (@image_pieces[@removed_cell].pos + 1) % @num_of_columns != 0 swap(@image_pieces[@removed_cell], get_piece_from_pos(@image_pieces[@removed_cell].pos + 1)) end elsif Input.trigger?(Input::B) [not_completed] end end def game_clear return completed if completed? return not_completed if @time == 0 end def completed $game_switches[SusunGambar::RESULT_SWITCH_ID] = true $game_variables[SusunGambar::REMAINING_TIME_ID] = @time Audio.se_play("Audio/SE/" + SusunGambar::COMPLETE_SE , 70, 100) rescue nil congrats change_scene(Scene_Map) end def not_completed $game_switches[SusunGambar::RESULT_SWITCH_ID] = false $game_variables[SusunGambar::REMAINING_TIME_ID] = 0 change_scene(Scene_Map) end def congrats text = SusunGambar::VOCAB_WIN sprite = s = Sprite.new sprite.bitmap = Bitmap.new(640,480) sprite.opacity = (sprite.z += 9999) && 0 sprite.bitmap.font.name = ['Georgia',Font.default_name].flatten sprite.bitmap.font.size = 32 y = (1 * sprite.bitmap.text_size(text).height) / 2 sprite.bitmap.draw_text(0,0-y,s.bitmap.width,s.bitmap.height,text,1) (sprite.opacity += 10) && Graphics.update until sprite.opacity >= 255 [Graphics,Input].each {|i| i.update } until Input.trigger?(Input::C) (sprite.opacity -= 10) && Graphics.update until sprite.opacity <= 0 sprite.dispose end def swap(a, b) tmp = a.pos a.pos = b.pos b.pos = tmp end def completed? @image_pieces.all? {|i| i.pos == i.right_pos} end def get_piece_from_pos(pos) @image_pieces.each {|i| return i if i.pos == pos} end end if SusunGambar::VXA class Scene_Map alias drg146_upd update unless method_defined?(:drg146_upd) def update drg146_upd return unless $scene_susun && !$scene_susun.empty? SceneManager.call(Scene_SusunGambar) end end end class Sprite_ImagePieces < Sprite attr_accessor :removed, :pos, :right_pos def initialize(right_pos) @right_pos,@pos,@removed = right_pos,right_pos,false super() end end