Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Slot machine
#1
Slot machine
by Leon Westbrooke
June 10 2007

This is a locked, single-post thread from Creation Asylum.  Archived here to prevent its loss.
No support is given.  If you are the owner of the thread, please contact administration.


All right, for all you gamblers out there (Zeriab...) I have made a slot machine for you to have fun on. This is also easily implemented into a game as well. This is a really basic thing, the instructions are in the script. Accompanied is the pictures needed, the code, and a screenshot. Enjoy!

p.s. Special thanks to SephirothSpawn. He helped me understand the plane class. if not for that, there would be no slots.

Screenshot:
[Image: slots-1.jpg]

Pictures: (You need all 4)
[Image: Reel1.png][Image: Reel2.png][Image: Reel3.png]
[Image: Outcome.png]

Code:
#===================================
#  Leon's Slot System
#  v 1.0
#  June 10th, 2007
#===================================
#
#  Features:
#    Creates a slot machine to pay games on.
#    You can customize the reels.
#    You can customize the bid amount, and payouts.
#    
#  Drawbacks:
#    You can only have 5 possible 'winning' combinations.
#
#  Instructions:
#    You will need 4 pictures total, 3 being the reels, and 1 being the 'outcome'.
#    Name the pictures as follows:
#    Reel 1:  Reel 1
#    Reel 2:  Reel 2
#    Reel 3:  Reel 3
#    Outcome:  Outcome
#    Very simple, but needed to be emphasized.
#
#    Import all 4 pictures in the 'Pictures' folder through RmXP.
#-----------------------------------------------------------------------
#
#  If you make custom reels:
#    The reels' width must be 175 pixels.
#    The reels' height must be a multiple of 75.
#    Each picture on the reel must be 175 in width and 75 in height.
#    The outcome picture must be 525x375
#    
#    In the module, for each reel, put the upper left pixel number and picture.
#      -For example, if the first one is Cherries, and the second is Bar 1, pixel 75 would be Bar 1.
#
#    Each time you type the picture, be exact.
#    If there is nothing there, leave empty quotes. (For example, a 'blank' on the reel.
#    In the 'Payoff' part of the module, use the picture's name from the above three reels, and the payoff.
#
#   NOTES:
#    Be sure each time you put the image's name in the module, it is spelled the EXACT same each time.
#    You can only have 5 possible outcomes.
#    To make the outcome picture, set the combinations next to eachother (making a 525 x 75 picture)
#     then stack the 5 combinations on top of eachother (the picture will then be 525x375),
#     the one with the highest payoff on top, and in decending order.
#
#    This machine was built for the bid amounts of 1, 2, and 3 gold.  You can work out
#    the payouts on your own, and balance the machine to your liking.  To do this, look
#    in the module under 'payout' and 'bid'.
#
#===================================


module Slot_Machine
 #--------------------------------------------------------------------
 #  Reel_One = { Upper_Left_Pixel => "Picture_Name"
 #--------------------------------------------------------------------
 Reel_One = {
 0 => "Cherries",
 75 => "",
 150 => "Bar 1",
 225 => "Bar 2",
 300 => "",
 375 => "7",
 450 => "",
 525 => "Bar 3",
 600 => "Cherries",
 675 => "Bar 2",
 750 => "Cherries",
 825 => "Bar 1"
 }
 
 #--------------------------------------------------------------------
 #  Reel_Two = { Upper_Left_Pixel => "Picture_Name"
 #--------------------------------------------------------------------
 Reel_Two = {
 0 => "Cherries",
 75 => "Bar 2",
 150 => "",
 225 => "Bar 1",
 300 => "Cherries",
 375 => "",
 450 => "Bar 3",
 525 => "7",
 600 => "",
 675 => "Cherries",
 750 => "",
 825 => "Bar 1"
 }
 
 #--------------------------------------------------------------------
 #  Reel_Three = { Upper_Left_Pixel => "Picture_Name"
 #--------------------------------------------------------------------
 Reel_Three = {
 0 => "Bar 1",
 75 => "",
 150 => "Cherries",
 225 => "7",
 300 => "",
 375 => "Bar 3",
 450 => "",
 525 => "Bar 1",
 600 => "",
 675 => "Cherries",
 750 => "Bar 2",
 825 => ""
 }
 
 #--------------------------------------------------------------------
 #  Payoff = { "Picture_Name" => Gold_gained,
 #  Always leave the empty quotes paying out 0, for a total of 6 payouts.
 #--------------------------------------------------------------------
 Payoff = {
 "7" => 50,
 "Bar 3" => 25,
 "Bar 2" => 10,
 "Bar 1" => 5,
 "Cherries" => 3,
 "" => 0
 }
 #--------------------------------------------------------------------
 #  Bid = []  Only 3 bid increments.
 #--------------------------------------------------------------------
 Bid = [1, 2, 3]
 
end

#===================================
#  Game_Party
#===================================
class Game_Party
 
 attr_accessor :won
 attr_accessor :gold
 
 alias leon_slotmachinegame_gameparty_initialize initialize
 
 def initialize
   leon_slotmachinegame_gameparty_initialize
   @won = 0
 end
end
#===================================
#  END Game_Party
#===================================


#===================================
#  Window_Base
#===================================
class Window_Base
 def draw_slot_bar(x, y, min, max, width = 152, height = 6,
     bar_color = Color.new(60, 130, 60, 255), end_color = Color.new(180, 250, 180, 255))
   self.contents.fill_rect(x, y, width, height, Color.new(50, 50, 50, 255))
   for i in 1..( (min.to_f / max.to_f) * width -1)
     r = bar_color.red * (width - i) / width + end_color.red * i / width
     g = bar_color.green * (width - i) / width + end_color.green * i / width
     b = bar_color.blue * (width - i) / width + end_color.blue * i / width
     a = bar_color.alpha * (width - i) / width + end_color.alpha * i / width
     self.contents.fill_rect(x + 1 + i, y + 1, 1, height - 2, Color.new(r, g, b, a))
   end
 end
end
#===================================
#  END Window_Base
#===================================

#===================================
# Window_Slot_Instruct
#===================================
class Window_Slot_Instruct < Window_Base
 def initialize
   super(0, 0, 640, 64)
   self.contents = Bitmap.new(width - 32, height - 32)
   self.contents.font.name = "Arial"
   self.contents.font.size = 22
 end
 
 def update(info_text)
   self.contents.clear
   self.contents.draw_text(0, 0, 618, 32, info_text, 1)
 end
end
#===================================
# END Window_Slot_Instruct
#===================================


#===================================
# Window_Slot_Pictures
#===================================
class Window_Slot_Pictures < Window_Base
 def initialize
   super(0, 64, 640, 257)
   self.contents = Bitmap.new(width - 32, height - 32)
   self.contents.font.name = "Arial"
   self.contents.font.size = 22
   refresh
 end
 
 def refresh
   self.contents.clear
   draw_slot_bar(0, 112, 3, 3, 618, 2, Color.new(85, 85, 85, 255), Color.new(105, 105, 105, 255))
 end
end
#===================================
# END Window_Slot_Pictures
#===================================


#===================================
#  Window_Slot_Press
#===================================
class Window_Slot_Press < Window_Base
 def initialize
   super(185, 321, 270, 64)
   self.contents = Bitmap.new(width - 32, height - 32)
   self.contents.font.name = "Arial"
   self.contents.font.size = 21
   refresh
 end
 
 def refresh
   self.contents.clear
   text = "Press 'Enter' to stop the reels."
   self.contents.draw_text(0, 0, 238, 32, text, 1)
 end
end
#===================================
#  END Window_Slot_Press
#===================================

#===================================
#  Window_Slot_Bid
#===================================
class Window_Slot_Bid < Window_Selectable
 def initialize
   super(220, 160, 200, 160)
   @options = ["One gold", "Two gold", "Three gold"]
   @item_max = @options.size
   self.contents = Bitmap.new(width - 32, height - 32)
   self.contents.font.name = "Arial"
   self.contents.font.size = 22
   self.visible = true
   self.active = true
   self.index = 0
   self.z += 200
   refresh
 end
 
 def refresh
   self.contents.clear
   slt = Slot_Machine
   self.contents.draw_text(0, 0, 168, 32, "Bid how much?")
   for i in 0...slt::Bid.size
     y = i * 32 + 32
     self.contents.draw_text(4, y, 168, 32, slt::Bid[i].to_s + " #{$data_system.words.gold.to_s}")
   end
 end
 
 def update_cursor_rect
   if @index < 0
     self.cursor_rect.empty
   else
     self.cursor_rect.set(0, @index * 32 + 32, (self.width - 32), 32)
   end
 end
end
#===================================
#  END Window_Slot_Bid
#===================================

#===================================
#  Window_Slot_Replay
#===================================
class Window_Slot_Replay < Window_Selectable
 def initialize
   super(245, 160, 150, 160)
   @options = ["Yes", "No"]
   @item_max = @options.size
   self.contents = Bitmap.new(width - 32, height - 32)
   self.contents.font.name = "Arial"
   self.contents.font.size = 22
   self.index = 0
   self.visible = false
   self.active = false
   self.z += 200
   refresh
 end
 
 def refresh
   self.contents.clear
   self.contents.draw_text(0, 0, 118, 32, "Won #{$game_party.won}")
   self.contents.draw_text(0, 32, 118, 32, "Play again?")
   for i in 0...@options.size
     y = i * 32 + 64
     self.contents.draw_text(4, y, 118, 32, @options[i])
   end
 end
 
 def update_cursor_rect
   if @index < 0
     self.cursor_rect.empty
   else
     self.cursor_rect.set(0, @index * 32 + 64, (self.width - 32), 32)
   end
 end
 
end
#===================================
#  Window_Slot_Replay
#===================================

#===================================
#  Window_Slot_Coins
#===================================
class Window_Slot_Coins < Window_Base
 def initialize
   super(0, 321, 185, 64)
   self.contents = Bitmap.new(width - 32, height - 32)
   self.contents.font.name = "Arial"
   self.contents.font.size = 22
 end
 
 def update
   self.contents.clear
   self.contents.font.color = system_color
   self.contents.draw_text(0, 0, 128, 32, "Gold:")
   self.contents.font.color = normal_color
   self.contents.draw_text(0, 0, 128, 32, $game_party.gold.to_s, 2)
 end
end
#===================================
#  Window_Slot_Coins
#===================================

#===================================
#  Window_Slots_Possibilities
#===================================
class Window_Slots_Possibilities < Window_Base
 def initialize
   super(0, 64, 640, 416)
   self.contents = Bitmap.new(width - 32, height - 32)
   self.contents.font.name = "Arial"
   self.contents.font.size =24
   self.visible = false
   self.z += 300
   refresh
 end
 
 def refresh
   slt = Slot_Machine
   self.contents.clear
   key = []
   for i in 1...slt::Payoff.keys.size
     key.push(slt::Payoff[slt::Payoff.keys[i]])
   end
   key.sort!
   key.reverse!
   for i in 0...key.size
     y = i * 75
     self.contents.draw_text(0, y + 17, 590, 36, "= #{key[i]} x bid", 2)
   end
 end
end
#===================================
#  END Window_Slots_Possibilities
#===================================
   

#===================================
#  Scene_Slots
#===================================
class Scene_Slots
 def main
   
   @instruct_window = Window_Slot_Instruct.new
   @pic_window = Window_Slot_Pictures.new
   @press_window = Window_Slot_Press.new
   @bid_window = Window_Slot_Bid.new
   @replay_window = Window_Slot_Replay.new
   @coin_window = Window_Slot_Coins.new
   @possible_window = Window_Slots_Possibilities.new
   
   @viewport1 = Viewport.new(47, 80, 175, 225)
   @viewport1.z = 104
   
   @viewport2 = Viewport.new(237, 80, 175, 225)
   @viewport2.z = 104
   
   @viewport3 = Viewport.new(427, 80, 175, 225)
   @viewport3.z = 104
   
   
   @plane1 = Plane.new(@viewport1)
   @plane1.bitmap = RPG::Cache.picture("Reel 1")
   @plane1.visible = true
   @plane1.opacity = 255
   @plane1.visible = true
   
   @plane2 = Plane.new(@viewport2)
   @plane2.bitmap = RPG::Cache.picture("Reel 2")
   @plane2.visible = true
   @plane2.opacity = 255
   @plane2.oy = 150
   @plane2.visible = true
   
   @plane3 = Plane.new(@viewport3)
   @plane3.bitmap = RPG::Cache.picture("Reel 3")
   @plane3.visible = true
   @plane3.opacity = 255
   @plane3.visible = true
   
   
   @sprite1 = Sprite.new
   @sprite1.bitmap = RPG::Cache.picture("Outcome")
   @sprite1.y = 80
   @sprite1.z = 401
   @sprite1.visible = false
   
   @slot1 = []
   @slot2 = []
   @slot3 = []
   
   @counter = 0
   @total = 0
   @wait = 3
   
   Graphics.transition
   loop do
     Graphics.update
     Input.update
     update
     if @bid_window.visible == false
       if @counter < 1
         @plane1.oy += 25
         if @plane1.oy == @plane1.bitmap.height
           @plane1.oy = 0
         end
       elsif @plane1.oy % 75 != 0
         @plane1.oy += 25
       end
     
       if @counter < 2
         @plane2.oy += 25
         if @plane2.oy == @plane2.bitmap.height
           @plane2.oy = 0
         end
       elsif @plane2.oy % 75 != 0
         @plane2.oy += 25
       end
     
       if @counter < 3
         @plane3.oy += 25
         if @plane3.oy == @plane3.bitmap.height
           @plane3.oy = 0
         end
       elsif @plane3.oy % 75 != 0
         @plane3.oy += 25
       end
     end
     if $scene != self
       break
     end
   end
   Graphics.freeze
   
   @instruct_window.dispose
   @pic_window.dispose
   @press_window.dispose
   @plane1.dispose
   @plane2.dispose
   @plane3.dispose
   @bid_window.dispose
   @replay_window.dispose
   @coin_window.dispose
   @possible_window.dispose
   @sprite1.dispose
 end
 
 def update
   @instruct_window.update("Press 'Q' or 'W' to see possible wins.")
   @pic_window.update
   @press_window.update
   @bid_window.update
   @replay_window.update
   @coin_window.update
   @possible_window.update
   slt = Slot_Machine
   
   
   
   if @replay_window.active
     update_replay
     return
   end
   
   if @possible_window.visible
     update_possible
     return
   end
   
   if @counter == 3
     update_payoff_1
     return
   end
   
   if @bid_window.visible == false
     if Input.trigger?(Input::C)
       @counter += 1
       return
     end
     return
   end
   
   if Input.trigger?(Input::B)
     $game_system.se_play($data_system.cancel_se)
     $scene = Scene_Map.new
   end
   
   if Input.trigger?(Input::L) or Input.trigger?(Input::R)
     @sprite1.visible = true
     @bid_window.active = false
     @possible_window.visible = true
     return
   end
   
   if Input.trigger?(Input::C)
     if $game_party.gold < slt::Bid[@bid_window.index]
       $game_system.se_play($data_system.buzzer_se)
     else
       $game_party.gold -= slt::Bid[@bid_window.index]
       @bid = slt::Bid[@bid_window.index]
       @bid_window.visible = false
       @bid_window.active = false
     end
     return
   end
 end
 
 def update_payoff_1
   slt = Slot_Machine
   #Reel One
   if @plane1.oy % 75 != 0
     @plane1.oy += 25
     return
   end
   if @plane2.oy % 75 != 0
     @plane2.oy += 25
     return
   end
   if @plane3.oy % 75 != 0
     @plane3.oy += 25
     return
   end
   @slot1[0] = slt::Reel_One[@plane1.oy]
   if @plane1.oy == @plane2.bitmap.height
     @plane1.oy = 0
   end
   if @plane2.oy == @plane2.bitmap.height
     @plane2.oy = 0
   end
   if @plane3.oy == @plane2.bitmap.height
     @plane3.oy = 0
   end
   if @plane1.oy == (@plane2.bitmap.height - 75)
     @slot1[1] = slt::Reel_One[0]
   else
     @slot1[1] = slt::Reel_One[@plane1.oy + 75]
   end
   
   if @plane1.oy == (@plane2.bitmap.height - 25)
     @slot1[2] = slt::Reel_One[75]
   elsif @plane1.oy == (@plane2.bitmap.height - 150)
     @slot1[2] = slt::Reel_One[0]
   else
     @slot1[2] = slt::Reel_One[@plane1.oy + 150]
   end
   #End of Reel One
   
   #Reel Two
   @slot2[0] = slt::Reel_Two[@plane2.oy]
   
   if @plane2.oy == (@plane2.bitmap.height - 25)
     @slot2[1] = slt::Reel_Two[0]
   else
     @slot2[1] = slt::Reel_Two[@plane2.oy + 75]
   end
   
   if @plane2.oy == (@plane2.bitmap.height - 25)
     @slot2[2] = slt::Reel_Two[75]
   elsif @plane2.oy == (@plane2.bitmap.height - 150)
     @slot2[2] = slt::Reel_Two[0]
   else
     @slot2[2] = slt::Reel_Two[@plane2.oy + 150]
   end
   #End of Reel Two
   
   #Reel Three
   @slot3[0] = slt::Reel_Three[@plane3.oy]
   
   if @plane3.oy == (@plane2.bitmap.height - 25)
     @slot3[1] = slt::Reel_Three[0]
   else
     @slot3[1] = slt::Reel_Three[@plane3.oy + 75]
   end
   
   if @plane3.oy == (@plane2.bitmap.height - 25)
     @slot3[2] = slt::Reel_Three[75]
   elsif @plane3.oy == (@plane2.bitmap.height - 150)
     @slot3[2] = slt::Reel_Three[0]
   else
     @slot3[2] = slt::Reel_Three[@plane3.oy + 150]
   end
   #End of Reel Three
   update_payoff_2
 end
   
 def update_payoff_2
   slt = Slot_Machine
   if @slot1[1] == @slot2[1] and @slot3[1] == @slot2[1]
     @total += (slt::Payoff[@slot1[1]] * @bid)
   end
   $game_party.won = @total
   @replay_window.refresh
   $game_party.gold += @total
   @replay_window.visible = true
   @replay_window.active = true
 end
 
 def update_replay
   if Input.trigger?(Input::C)
     case @replay_window.index
     when 0
       @replay_window.visible = false
       @replay_window.active = false
       @replay_window.index = 0
       @bid_window.visible = true
       @bid_window.index = 0
       @bid_window.active = true
       @counter = 0
       @total = 0
       @wait = 3
       @slot1 = []
       @slot2 = []
       @slot3 = []
       return
     when 1
       $scene = Scene_Map.new
     end
   end
 end
 
 def update_possible
   if Input.trigger?(Input::B)
     $game_system.se_play($data_system.cancel_se)
     $scene = Scene_Map.new
     return
   end
   
   if Input.trigger?(Input::L) or Input.trigger?(Input::R)
     @sprite1.visible = false
     @bid_window.active = true
     @possible_window.visible = false
     return
   end
 end
 
end
}




Users browsing this thread: