Registrarse

[Otros] Slot Machine estilo HG/SS

Jaizu

Héroe de WaH

Testeado en 17.2

Reemplazar PMinigame_SlotMachine por
Código:
################################################################################
# "Slot Machine" mini-game
# By Maruno
#-------------------------------------------------------------------------------
# Run with:      pbSlotMachine(1)
# - The number is either 0 (easy), 1 (default) or 2 (hard).
################################################################################
class SlotMachineReel < BitmapSprite
  attr_accessor :reel
  attr_accessor :toppos
  attr_accessor :spinning
  attr_accessor :stopping
  attr_accessor :slipping
  SCROLLSPEED = 16 # Must be a divisor of 48
  ICONSPOOL = [[0,0,0,0,1,1,2,2,3,3,3,4,4,4,5,5],  # 0 - Easy
               [0,0,0,0,1,1,1,2,2,2,3,3,4,4,5],    # 1 - Medium (default)
               [0,0,1,1,1,2,2,2,3,3,4,4,5]         # 2 - Hard
              ]
  SLIPPING = [0,0,0,0,0,0,1,1,1,2,2,3]

  def initialize(x,y,difficulty=1)
    @viewport=Viewport.new(x,y,64,144)
    @viewport.z=99999
    super(64,144,@viewport)
    @reel=[]
    for i in 0...ICONSPOOL[difficulty].length
      @reel.push(ICONSPOOL[difficulty][i])
    end
    @reel.shuffle!
    @toppos=0
    @spinning=false
    @stopping=false
    @slipping=0
    @index=rand(@reel.length)
    @images=AnimatedBitmap.new(_INTL("Graphics/Pictures/Slot Machine/images"))
    [MENTION=15468]shad[/MENTION]ing=AnimatedBitmap.new(_INTL("Graphics/Pictures/Slot Machine/ReelOverlay"))
    update
  end

  def startSpinning
    @spinning=true
  end

  def stopSpinning(noslipping=false)
    @stopping=true
    @slipping=SLIPPING[rand(SLIPPING.length)]
    @slipping=0 if noslipping
  end

  def showing
    array=[]
    for i in 0...3
      num=@index-i
      num+=@reel.length if num<0
      array.push(@reel[num])
    end
    return array   # [0] = top, [1] = middle, [2] = bottom
  end

  def update
    self.bitmap.clear
    if @toppos==0 && @stopping && @slipping==0
      @spinning=@stopping=false
    end
    if @spinning
      @toppos+=SCROLLSPEED
      if @toppos>0
        @toppos-=48
        @index=(@index+1)%@reel.length
        @slipping-=1 if @slipping>0
      end
    end
    for i in 0...4
      num=@index-i
      num+=@reel.length if num<0
      self.bitmap.blt(0,@toppos+i*48,@images.bitmap,Rect.new(@reel[num]*64,0,64,48))
    end
    self.bitmap.blt(0,0 [MENTION=15468]shad[/MENTION]ing.bitmap,Rect.new(0,0,64,144))
  end
end



class SlotMachineScore < BitmapSprite
  attr_reader :score

  def initialize(x,y,score=0)
    @viewport=Viewport.new(x,y,70,22)
    @viewport.z=99999
    super(70,22,@viewport)
    @numbers=AnimatedBitmap.new(_INTL("Graphics/Pictures/Slot Machine/numbers"))
    self.score=score
  end

  def score=(value)
    @score=value
    @score=MAXCOINS if @score>MAXCOINS
    refresh
  end

  def refresh
    self.bitmap.clear
    for i in 0...5
      digit=(@score/(10**i))%10 # Least significant digit first
      self.bitmap.blt(14*(4-i),0,@numbers.bitmap,Rect.new(digit*14,0,14,22))
    end
  end
end



class SlotMachineScene
  attr_accessor :gameRunning
  attr_accessor :gameEnd
  attr_accessor :wager
  attr_accessor :replay

  def update
    pbUpdateSpriteHash [MENTION=24071]Sprite[/MENTION]s)
  end

  def pbPayout
    @replay=false
    payout=0
    bonus=0
    wonRow=[]
    # Get reel pictures
    reel1 [MENTION=24071]Sprite[/MENTION]s["reel1"].showing
    reel2 [MENTION=24071]Sprite[/MENTION]s["reel2"].showing
    reel3 [MENTION=24071]Sprite[/MENTION]s["reel3"].showing
    combinations=[[reel1[1],reel2[1],reel3[1]], # Centre row
                  [reel1[0],reel2[0],reel3[0]], # Top row
                  [reel1[2],reel2[2],reel3[2]], # Bottom row
                  [reel1[0],reel2[1],reel3[2]], # Diagonal top left -> bottom right
                  [reel1[2],reel2[1],reel3[0]], # Diagonal bottom left -> top right
                 ]
    for i in 0...combinations.length
      break if i>=1 && @wager<=1 # One coin = centre row only
      break if i>=3 && @wager<=2 # Two coins = three rows only
      wonRow[i]=true
      case combinations[i]
      when [1,1,1] # Three replays
        @replay=true
      when [2,2,2] # Three Marills
        payout+=10
      when [3,3,3] # Three Pikachus
        payout+=15
      when [4,4,4] # 3 Pokéball
        payout+=300
        bonus=2 if bonus<2
      when [5,5,5] # 777
        payout+=300
        bonus=2 if bonus<1
      else
        if combinations[i][0]==0 # Left cherry
          if combinations[i][1]==0 # Centre cherry as well
            payout+=4
          else
            payout+=2
          end
        else
          wonRow[i]=false
        end
      end
    end
    [MENTION=24071]Sprite[/MENTION]s["payout"].score=payout
    frame=0
    if payout>0 || @replay
      if bonus>0
        pbMEPlay("Slots big win")
      else
        pbMEPlay("Slots win")
      end
      # Show winning animation
      until frame==120 # 40 frames per seconds
        Graphics.update
        Input.update
        update
        [MENTION=24071]Sprite[/MENTION]s["window2"].bitmap.clear if [MENTION=24071]Sprite[/MENTION]s["window2"].bitmap
        [MENTION=24071]Sprite[/MENTION]s["window1"].setBitmap(sprintf("Graphics/Pictures/Slot Machine/win"))
        [MENTION=24071]Sprite[/MENTION]s["window1"].src_rect.set(152*((frame/5)%4),0,152,208)
        if bonus>0
          [MENTION=24071]Sprite[/MENTION]s["window2"].setBitmap(sprintf("Graphics/Pictures/Slot Machine/bonus"))
          [MENTION=24071]Sprite[/MENTION]s["window2"].src_rect.set(152*(bonus-1),0,152,208)
        end
        [MENTION=24071]Sprite[/MENTION]s["light1"].visible=true
        [MENTION=24071]Sprite[/MENTION]s["light1"].src_rect.set(0,26*((frame/5)%4),96,26)
        [MENTION=24071]Sprite[/MENTION]s["light2"].visible=true
        [MENTION=24071]Sprite[/MENTION]s["light2"].src_rect.set(0,26*((frame/5)%4),96,26)
        for i in 1..5
          if wonRow[i-1]
            [MENTION=24071]Sprite[/MENTION]s["row#{i}"].visible=(frame%10<5)
          else
            [MENTION=24071]Sprite[/MENTION]s["row#{i}"].visible=false
          end
        end
        frame+=1
      end
      [MENTION=24071]Sprite[/MENTION]s["light1"].visible=false
      [MENTION=24071]Sprite[/MENTION]s["light2"].visible=false
      [MENTION=24071]Sprite[/MENTION]s["window1"].src_rect.set(0,0,152,208)
      # Pay out
      loop do
        break if [MENTION=24071]Sprite[/MENTION]s["payout"].score<=0
        Graphics.update
        Input.update
        update
        [MENTION=24071]Sprite[/MENTION]s["payout"].score-=1
        [MENTION=24071]Sprite[/MENTION]s["credit"].score+=1
        if Input.trigger?(Input::C) || [MENTION=24071]Sprite[/MENTION]s["credit"].score==MAXCOINS
          [MENTION=24071]Sprite[/MENTION]s["credit"].score+ [MENTION=24071]Sprite[/MENTION]s["payout"].score
          [MENTION=24071]Sprite[/MENTION]s["payout"].score=0
        end
      end
      20.times do
        Graphics.update
        Input.update
        update
      end
    else
      # Show losing animation
      until frame==80 # 40 frames per seconds
        Graphics.update
        Input.update
        update
        [MENTION=24071]Sprite[/MENTION]s["window2"].bitmap.clear if [MENTION=24071]Sprite[/MENTION]s["window2"].bitmap
        [MENTION=24071]Sprite[/MENTION]s["window1"].setBitmap(sprintf("Graphics/Pictures/Slot Machine/lose"))
        [MENTION=24071]Sprite[/MENTION]s["window1"].src_rect.set(152*((frame/10)%2),0,152,208)
        frame+=1
      end
    end
    @wager=0
  end

  def pbStartScene(difficulty)
    [MENTION=24071]Sprite[/MENTION]s={}
    @viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
    @viewport.z=99999
    addBackgroundPlane [MENTION=24071]Sprite[/MENTION]s,"bg","Slot Machine/bg",@viewport)
    [MENTION=24071]Sprite[/MENTION]s["reel1"]=SlotMachineReel.new(64,112,difficulty)
    [MENTION=24071]Sprite[/MENTION]s["reel2"]=SlotMachineReel.new(144,112,difficulty)
    [MENTION=24071]Sprite[/MENTION]s["reel3"]=SlotMachineReel.new(224,112,difficulty)
    for i in 1..3
      [MENTION=24071]Sprite[/MENTION]s["button#{i}"]=IconSprite.new(68+80*(i-1),260,@viewport)
      [MENTION=24071]Sprite[/MENTION]s["button#{i}"].setBitmap(sprintf("Graphics/Pictures/Slot Machine/button"))
      [MENTION=24071]Sprite[/MENTION]s["button#{i}"].visible=false
    end
    for i in 1..5
      y=[170,122,218,82,82][i-1]
      [MENTION=24071]Sprite[/MENTION]s["row#{i}"]=IconSprite.new(2,y,@viewport)
      [MENTION=24071]Sprite[/MENTION]s["row#{i}"].setBitmap(sprintf("Graphics/Pictures/Slot Machine/line%1d%s",
         1+i/2,(i>=4) ? ((i==4) ? "a" : "b") : ""))
      [MENTION=24071]Sprite[/MENTION]s["row#{i}"].visible=false
    end
    [MENTION=24071]Sprite[/MENTION]s["light1"]=IconSprite.new(16,32,@viewport)
    [MENTION=24071]Sprite[/MENTION]s["light1"].setBitmap(sprintf("Graphics/Pictures/Slot Machine/lights"))
    [MENTION=24071]Sprite[/MENTION]s["light1"].visible=false
    [MENTION=24071]Sprite[/MENTION]s["light2"]=IconSprite.new(240,32,@viewport)
    [MENTION=24071]Sprite[/MENTION]s["light2"].setBitmap(sprintf("Graphics/Pictures/Slot Machine/lights"))
    [MENTION=24071]Sprite[/MENTION]s["light2"].mirror=true
    [MENTION=24071]Sprite[/MENTION]s["light2"].visible=false
    [MENTION=24071]Sprite[/MENTION]s["window1"]=IconSprite.new(358,96,@viewport)
    [MENTION=24071]Sprite[/MENTION]s["window1"].setBitmap(sprintf("Graphics/Pictures/Slot Machine/insert"))
    [MENTION=24071]Sprite[/MENTION]s["window1"].src_rect.set(0,0,152,208)
    [MENTION=24071]Sprite[/MENTION]s["window2"]=IconSprite.new(358,96,@viewport)
    [MENTION=24071]Sprite[/MENTION]s["credit"]=SlotMachineScore.new(360,66,$PokemonGlobal.coins)
    [MENTION=24071]Sprite[/MENTION]s["payout"]=SlotMachineScore.new(438,66,0)
    @wager=0
    update
    pbFadeInAndShow [MENTION=24071]Sprite[/MENTION]s)
  end

  def pbMain
    frame=0
    loop do
      Graphics.update
      Input.update
      update
      [MENTION=24071]Sprite[/MENTION]s["window1"].bitmap.clear if [MENTION=24071]Sprite[/MENTION]s["window1"].bitmap
      [MENTION=24071]Sprite[/MENTION]s["window2"].bitmap.clear if [MENTION=24071]Sprite[/MENTION]s["window2"].bitmap
      if [MENTION=24071]Sprite[/MENTION]s["credit"].score==MAXCOINS
        Kernel.pbMessage(_INTL("You've got 99,999 Coins."))
        break
      elsif $PokemonGlobal.coins==0
        Kernel.pbMessage(_INTL("No tienes más monedas.\n¡Game over!"))
        break
      elsif @gameRunning # Reels are spinning
        [MENTION=24071]Sprite[/MENTION]s["window1"].setBitmap(sprintf("Graphics/Pictures/Slot Machine/stop"))
        [MENTION=24071]Sprite[/MENTION]s["window1"].src_rect.set(152*((frame/10)%4),0,152,208)
        if Input.trigger?(Input::C)
          pbSEPlay("Slots stop")
          if [MENTION=24071]Sprite[/MENTION]s["reel1"].spinning
            [MENTION=24071]Sprite[/MENTION]s["reel1"].stopSpinning(@replay)
            [MENTION=24071]Sprite[/MENTION]s["button1"].visible=true
          elsif [MENTION=24071]Sprite[/MENTION]s["reel2"].spinning
            [MENTION=24071]Sprite[/MENTION]s["reel2"].stopSpinning(@replay)
            [MENTION=24071]Sprite[/MENTION]s["button2"].visible=true
          elsif [MENTION=24071]Sprite[/MENTION]s["reel3"].spinning
            [MENTION=24071]Sprite[/MENTION]s["reel3"].stopSpinning(@replay)
            [MENTION=24071]Sprite[/MENTION]s["button3"].visible=true
          end
        end
        if  [MENTION=24071]Sprite[/MENTION]s["reel3"].spinning
          @gameEnd=true
          @gameRunning=false
        end
      elsif @gameEnd # Reels have been stopped
        pbPayout
        # Reset graphics
        [MENTION=24071]Sprite[/MENTION]s["button1"].visible=false
        [MENTION=24071]Sprite[/MENTION]s["button2"].visible=false
        [MENTION=24071]Sprite[/MENTION]s["button3"].visible=false
        for i in 1..5
          [MENTION=24071]Sprite[/MENTION]s["row#{i}"].visible=false
        end
        @gameEnd=false
      else # Awaiting coins for the next spin
        [MENTION=24071]Sprite[/MENTION]s["window1"].setBitmap(sprintf("Graphics/Pictures/Slot Machine/insert"))
        [MENTION=24071]Sprite[/MENTION]s["window1"].src_rect.set(152*((frame/15)%2),0,152,208)
        if @wager>0
          [MENTION=24071]Sprite[/MENTION]s["window2"].setBitmap(sprintf("Graphics/Pictures/Slot Machine/press"))
          [MENTION=24071]Sprite[/MENTION]s["window2"].src_rect.set(152*((frame/15)%2),0,152,208)
        end
        if Input.trigger?(Input::DOWN) && @wager<3 && [MENTION=24071]Sprite[/MENTION]s["credit"].score>0
          pbSEPlay("Slots coin")
          @wager+=1
          [MENTION=24071]Sprite[/MENTION]s["credit"].score-=1
          if @wager>=3
            [MENTION=24071]Sprite[/MENTION]s["row5"].visible=true
            [MENTION=24071]Sprite[/MENTION]s["row4"].visible=true
          elsif @wager>=2
            [MENTION=24071]Sprite[/MENTION]s["row3"].visible=true
            [MENTION=24071]Sprite[/MENTION]s["row2"].visible=true
          elsif @wager>=1
            [MENTION=24071]Sprite[/MENTION]s["row1"].visible=true
          end
        elsif @wager>=3 || (@wager>0 && [MENTION=24071]Sprite[/MENTION]s["credit"].score==0) ||
              (Input.trigger?(Input::C) && @wager>0) || @replay
          if @replay
            @wager=3
            for i in 1..5
              [MENTION=24071]Sprite[/MENTION]s["row#{i}"].visible=true
             end
          end
          [MENTION=24071]Sprite[/MENTION]s["reel1"].startSpinning
          [MENTION=24071]Sprite[/MENTION]s["reel2"].startSpinning
          [MENTION=24071]Sprite[/MENTION]s["reel3"].startSpinning
          frame=0
          @gameRunning=true
        elsif Input.trigger?(Input::B) && @wager==0
          break
        end
      end
      frame=(frame+1)%120
    end
    $PokemonGlobal.coins [MENTION=24071]Sprite[/MENTION]s["credit"].score
  end

  def pbEndScene
    pbFadeOutAndHide [MENTION=24071]Sprite[/MENTION]s)
    pbDisposeSpriteHash [MENTION=24071]Sprite[/MENTION]s)
    @viewport.dispose
  end
end



class SlotMachine
  def initialize(scene)
    @scene=scene
  end

  def pbStartScreen(difficulty)
    @scene.pbStartScene(difficulty)
    @scene.pbMain
    @scene.pbEndScene
  end
end



def pbSlotMachine(difficulty=1)
  if hasConst?(PBItems,:COINCASE) && !$PokemonBag.pbHasItem?(:COINCASE)
    Kernel.pbMessage(_INTL("Es una máquina tragaperras."))
  elsif $PokemonGlobal.coins==0
    Kernel.pbMessage(_INTL("¡No tienes monedas para jugar!"))
  elsif $PokemonGlobal.coins==MAXCOINS
    Kernel.pbMessage(_INTL("¡Tienes el Monedero lleno!"))
  else
    pbFadeOutIn(99999){
      scene = SlotMachineScene.new
      screen = SlotMachine.new(scene)
      screen.pbStartScreen(difficulty)
    }
  end
end
Gráficos: aquí

Modo de uso



Créditos a Jaizu si se usa.
 
Última edición:
Arriba