Jump to content
Rpg²S Forum

*Minigame Puzzle


Spike92
 Share

Recommended Posts

Minigame Puzzle

Descrizione


Uno script che permette di inserire un puzzle nel vostro progetto.


Autore


DarkRog



Allegati


Screen: 1


Istruzioni per l'uso


Create una classe sopra il main e incollate questo al suo interno:

 

#==============================================================================
# ¦ Scene_Puzle - By DarkRog - Versión Pase automático de piezas.
=begin
You need a picture with size 420px x 420px, in Graphics/Pictures.
You have to call a script from an event and write:
$scene = Scene_Puzle.new(piece size , "picture", variable id (this variable will be the result of the game), time, background)
*The size has to be dividing of 420.
*The picture need to be in Graphics/Picture.
*The variable id:
1:You won, 2:Time up.
*Seconds, or false for unlimited time.
*A background image in Graphics/Picture, or false for any picture.
Example:
$scene = Scene_Puzle.new(140, "Puzle1", 3, 30, "Back")
Size:140, Picture:"Puzle1", Variable:3, Seconds:30 Background:"Back".
=end
#------------------------------------------------------------------------------

class Scene_Puzle
    def initialize(size, img, vid, tim, back)
        @pu = Window_Puzle.new(size, img, vid, tim, back)
    end
    def main
        Graphics.transition
        loop do
            Graphics.update
            Input.update
            update
            if $scene != self
                break
            end
        end
        Graphics.freeze
        @pu.dispose
        if $scene.is_a?(Scene_Title)
            Graphics.transition
            Graphics.freeze
        end
    end
    def update
        @pu.refresh
    end
end

class Window_Puzle < Window_Base
    def initialize(size, img, vid, tim, back)
        super(-16, -16, 640+32, 480+32)
        self.contents = Bitmap.new(width - 32, height - 32)
        self.contents.font.name = $fontface
        self.contents.font.size = $fontsize
        @back = back
        @vid = vid
        @piezasi = size
        @img = img
        @winb = Window_PBrillo.new
        if tim == false
            @timeh = false
        else
            @time = tim*25
            @timeh = true
        end
        @pieza = []
        piezas = []
        num = 0
        for i in 0..420/@piezasi-1
            for a in 0..420/@piezasi-1
                @pieza[num] = Pieza_Puzle.new(a, i)
                piezas[num] = num
                num += 1
            end
        end
        @op = []
        for i in 0..420/@piezasi*420/@piezasi-1
            loop do
                ra = rand(420/@piezasi*420/@piezasi)
                if piezas[ra] != nil
                    @op[i] = ra
                    piezas[ra] = nil
                    break
                end
            end
        end
        @cursor = num-1
        @o = 100
        @re = false
        refresh
    end
    def refresh
        self.contents.clear
        if @back != false
            self.contents.blt(0, 0, RPG::Cache.picture(@back), Rect.new(0, 0, 640, 480), 255)
        end
        if @timeh == true
            @time -= 1
            if @time == 0
                $game_variables[@vid] = 2
                $game_system.se_play($data_system.buzzer_se)
                $scene = Scene_Map.new
            end
        end
        if @o <= 100
            @re = false
        elsif @o >= 255
            @re = true
        end
        if @re == false
            @o += 5
        elsif @re == true
            @o -= 5
        end
        self.contents.draw_text(26, 0, 640, 32, "Pieces")
        self.contents.draw_text(300, 0, 640, 32, "Panel")
        if @timeh != false
            if @time/25%60 > 9
                self.contents.draw_text(460, 0, 640, 32, "Time: #{@time/25/60}:#{@time/25%60}")
            else
                self.contents.draw_text(460, 0, 640, 32, "Time: #{@time/25/60}:0#{@time/25%60}")
            end
        else
            self.contents.draw_text(460, 0, 640, 32, "Unlimited time")
        end
        self.contents.fill_rect(70-@piezasi/2+@piezasi/100, 240-@piezasi/2, @piezasi+2, @piezasi+2, Color.new(0, 0, 0, 200))
        self.contents.fill_rect(175, 35, 422, 422, Color.new(0, 0, 0, 200))
        self.contents.blt(176, 36, RPG::Cache.picture(@img), Rect.new(0, 0, 420, 420), 10)
        pieza = 0
        for i in 0..420/@piezasi-1
            for a in 0..420/@piezasi-1
                if @pieza[pieza].d == true
                    self.contents.blt(176+a*@piezasi, 36+i*@piezasi, RPG::Cache.picture(@img), Rect.new(@piezasi*a, @piezasi*i, @piezasi, @piezasi), 255)
                end
                pieza += 1
            end
        end
        for a in -1..1
            i = @cursor-a
            if @op[i] != nil
                if i >= 0 and a != 0
                    if @pieza[@op[i]].d == false
                    elsif @pieza[@op[i]].d == true
                    end
                end
                if a == 0
                    if @pieza[@op[i]].d == false
                        self.contents.blt(70-@piezasi/2+@piezasi/100+1, 240-@piezasi*3/2+@piezasi*(a+1), RPG::Cache.picture(@img), Rect.new(@pieza[@op[i]].x*@piezasi, @pieza[@op[i]].y*@piezasi, @piezasi, @piezasi), @o)
                    elsif @pieza[@op[i]].d == true
                        self.contents.blt(70-@piezasi/2+@piezasi/100+1, 240-@piezasi*3/2+@piezasi*(a+1), RPG::Cache.picture(@img), Rect.new(@pieza[@op[i]].x*@piezasi, @pieza[@op[i]].y*@piezasi, @piezasi, @piezasi), 20+@o/10)
                    end
                end
            end
        end
        if @fase == 1
            f1_up
            return
        elsif @fase == nil
            @fase = 1
            @cursorx = 0
            @cursory = 0
        end
    end
    def f1_up
        self.contents.blt(@piezasi*@cursorx+176, 36+@piezasi*@cursory, RPG::Cache.picture(@img), Rect.new(@pieza[@op[@cursor]].x*@piezasi, @pieza[@op[@cursor]].y*@piezasi, @piezasi, @piezasi), @o)
        if Input.repeat?(Input::RIGHT) and @cursorx < 420/@piezasi-1
            @cursorx += 1
            $game_system.se_play($data_system.cursor_se)
        elsif Input.repeat?(Input::RIGHT) and @cursorx == 420/@piezasi-1
            $game_system.se_play($data_system.cursor_se)
            @cursorx = 0
        end
        if Input.repeat?(Input::LEFT) and @cursorx > 0
            @cursorx -= 1
            $game_system.se_play($data_system.cursor_se)
        elsif Input.repeat?(Input::LEFT) and @cursorx == 0
            $game_system.se_play($data_system.cursor_se)
            @cursorx = 420/@piezasi-1
        end
        if Input.repeat?(Input::DOWN) and @cursory < 420/@piezasi-1
            @cursory += 1
            $game_system.se_play($data_system.cursor_se)
        elsif Input.repeat?(Input::DOWN) and @cursory == 420/@piezasi-1
            @cursory = 0
            $game_system.se_play($data_system.cursor_se)
        end
        if Input.repeat?(Input::UP) and @cursory >0
            @cursory -= 1
            $game_system.se_play($data_system.cursor_se)
        elsif Input.repeat?(Input::UP) and @cursory == 0
            @cursory = 420/@piezasi-1
            $game_system.se_play($data_system.cursor_se)
        end
        if Input.trigger?(Input::C)
            if @pieza[@op[@cursor]].x == @cursorx and @pieza[@op[@cursor]].y == @cursory
                $game_system.se_play($data_system.load_se)
                @pieza[@op[@cursor]].d = true
                piezac = 0
                for i in 0...420/@piezasi*420/@piezasi
                    if @pieza[i].d == true
                        piezac +=1
                    end
                end
                if piezac == 420/@piezasi*420/@piezasi
                    $game_variables[@vid] = 1
                    @o2 = 0
                    @re2 = false
                    @t2 = 0
                    Audio.se_play("Audio/SE/056-Right02.ogg", 100, 50)
                    loop do
                        Graphics.update
                        @t2 += 1
                        if @re2 == true
                            @o2 -= 5
                        elsif @re2 == false
                            @o2 += 5
                        end
                        if @o2 >= 255
                            @re2 = true
                        elsif @o2 <= 0
                            @re2 = false
                        end
                        @winb.refresh(@o2)
                        if @t2 == 102
                            @winb.dispose
                            break
                        end
                    end
                    $game_system.se_play($data_system.shop_se)
                    $scene = Scene_Map.new
                else
                    @cursor -= 1
                end
            else
                $game_system.se_play($data_system.buzzer_se)
            end
            return
        end
    end
end

class Pieza_Puzle
    attr_accessor :x
    attr_accessor :y
    attr_accessor :d
    def initialize(x, y)
        @x = x
        @y = y
        @d = false
    end
end

class Window_PBrillo < Window_Base
    def initialize
        super(-16, -16, 640+32, 480+32)
        self.contents = Bitmap.new(width - 32, height - 32)
        self.contents.font.name = $fontface
        self.contents.font.size = $fontsize
        self.opacity = 0
        refresh(0)
    end
    def refresh(o)
        self.contents.clear
        self.contents.fill_rect(175, 35, 422, 422, Color.new(255, 255, 255, o))
    end
end

 

 


L'immagine del puzzle deve essere 420x420 pixels.

Per chiamare l'evento inserite sto codice di esempio:


$scene = Scene_Puzle.new(140, "Puzle1", 3, 30, "Back")

 

Dove:

1) 140 è la misura dei pezzi;
2) Puzle1 è l'immagine del puzzle che va messa in Graphics\Pictures;
3) 30 sono i secondi che avete per risolverlo, mettere "false" per tempo illimitato;
4) Back è l'immagine che volete mettere come sfondo al vostro puzzle, sempre 420 x 420 pixel, cartella Graphics\Pictures.

Setta dei makeratori originali™ - SMO - #settadeimakeratorioriginali

 

 

<DarK-SePHiRoTH-> raga sono mancato un anno ma a quanto vedo mahun non ha ancora imparato a disegnare :O

 

<cip_e_ciop> picasso ha fatto per la pittura ciò che mahun ha fatto per i fumetti

Link to comment
Share on other sites

  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...