"virtual" slot machine with source

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
Nituvious
Addict
Addict
Posts: 1029
Joined: Sat Jul 11, 2009 4:57 am
Location: United States

"virtual" slot machine with source

Post by Nituvious »

Hi, I was going through some old stuff freeing up space and found this lame gem. I originally made it for a virtual machine programming competition as a joke.. No one thought it was funny. :(

Maybe someone interested in simple games would enjoy it or use the source. It's very, very simple and there are a million different ways of accomplishing the same thing.
Currently there is no win or lose condition.

Image: Reel2.png

Code: Select all

; virtual machine... virtual SLOT machine

Structure WHEEL
	
	isSpinning.b
	speed.d
	pos.d
	
EndStructure


Global.WHEEL Dim gReel(2)
gReel(0)\speed = -7 : gReel(1)\speed = -5 : gReel(2)\speed = -2
gReel(0)\pos = -342 : gReel(1)\pos = -342 : gReel(2)\pos = -342

Global.b gIsRunning = 1, gIsSpinning = 0
Global.l reel

Declare SpinSlot()
Declare GetInput()


Global.l gWindow = OpenWindow(#PB_Any, 0, 0, 800, 600, "Virtual *slot* Machine. Version #0.hue", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)

If InitSprite() And InitKeyboard()
	
	UsePNGImageDecoder()
	OpenWindowedScreen(WindowID(gWindow), 0, 0, 800, 600)
	
	reel = LoadSprite(#PB_Any, "reel2.png")
	
	cushions = CreateSprite(#PB_Any, 800, 175)
	StartDrawing(SpriteOutput(cushions))
	Box(0, 0, 800, 256, RGB(0, 50, 211))
	StopDrawing()
	
	sides = CreateSprite(#PB_Any, 10, 600)
	StartDrawing(SpriteOutput(sides))
	Box(0, 0, 10, 600, RGB(200, 50, 21))
	StopDrawing()
	
	middle = CreateSprite(#PB_Any, 800, 20)
	StartDrawing(SpriteOutput(middle))
	Box(0, 0, 800, 20, RGB(170, 50, 30))
	StopDrawing()
	
EndIf


While gIsRunning = 1
	
	event = WaitWindowEvent(1)
	
	If event
		
		Select WindowEvent()
				
			Case #PB_Event_Gadget
			Case #PB_Event_CloseWindow
				
				gIsRunning = 0
				
		EndSelect
		
	EndIf
	
	GetInput()
	
	ClearScreen(0)
	
	DisplaySprite(reel, 16, gReel(0)\pos)
	DisplaySprite(reel, 16+256, gReel(1)\pos)
	DisplaySprite(reel, 16+256 * 2, gReel(2)\pos)
	
	DisplaySprite(cushions, 0, 0)
	DisplaySprite(cushions, 0, 425)
	DisplaySprite(sides, 790, 0)
	DisplaySprite(sides, 0, 0)
	DisplaySprite(middle, 0, 290)
	
	FlipBuffers()
	
	If gIsSpinning = 1 : SpinSlot() : EndIf
	
	
	
Wend
End

Procedure StopReel(id)
	
	Define.l thing
	
	Select(Random(5)) ; set position of the reel
						
		Case 0 : thing = 170
		
		Case 1 : thing = -86
			
		Case 2: thing = -342
			
		Case 3: thing = -598
			
		Case 4: thing = -854
			
		Default: thing = 170
						
	EndSelect
		
		gReel(id)\pos = thing
	
EndProcedure

Procedure StartSlot()
	
	gReel(0)\isSpinning = 1
	gReel(1)\isSpinning = 1
	gReel(2)\isSpinning = 1
	
	gReel(0)\speed = -Random(15)
	gReel(1)\speed = -Random(10)
	gReel(2)\speed = -Random(5)
	
EndProcedure

Procedure SpinSlot()
	
	If gReel(0)\isSpinning = 1
		
		gReel(0)\pos + gReel(0)\speed
		If gReel(0)\speed < 32 : gReel(0)\speed + 0.2 : Else : If Random(100)=0 : gReel(0)\isSpinning = 0 : StopReel(0) : EndIf : EndIf
		If gReel(0)\pos >= 170 : gReel(0)\pos = -1110 : EndIf
		
	EndIf
	
	If gReel(1)\isSpinning = 1
		
		gReel(1)\pos + gReel(1)\speed
		If gReel(1)\speed < 32 : gReel(1)\speed + 0.2 : Else : If Random(100)=0 : gReel(1)\isSpinning = 0 : StopReel(1) : EndIf : EndIf
		If gReel(1)\pos >= 170 : gReel(1)\pos = -1110 : EndIf
		
	EndIf
	
	If gReel(2)\isSpinning = 1
		
		gReel(2)\pos + gReel(2)\speed
		If gReel(2)\speed < 32 : gReel(2)\speed + 0.1 : Else : If Random(100)=0 : gReel(2)\isSpinning = 0 : StopReel(2) : EndIf : EndIf 
		If gReel(2)\pos >= 170 : gReel(2)\pos = -1110 : EndIf
		
	EndIf
	
EndProcedure

Procedure GetInput()
	
	ExamineKeyboard()
	
	If KeyboardReleased(#PB_Key_Space) : gIsSpinning = 1 : Debug "Pressed space!"
		
		StartSlot()
		
	EndIf
	If KeyboardReleased(#PB_Key_Q	) : gIsSpinning = 0 : EndIf
	If KeyboardReleased(#PB_Key_W) : gReel(0)\pos - 256 : Debug gReel(0)\pos : EndIf
	If KeyboardReleased(#PB_Key_E) : gReel(0)\pos = 170 : EndIf
	
EndProcedure
▓▓▓▓▓▒▒▒▒▒░░░░░
User avatar
IceSoft
Addict
Addict
Posts: 1694
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: "virtual" slot machine with source

Post by IceSoft »

The grafik is free for using anywere?
Belive! C++ version of Puzzle of Mystralia
Bug Planet
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: "virtual" slot machine with source

Post by applePi »

Thanks for this. i find it useful and funny, i have not used sprites like this before so i will learn from it.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: "virtual" slot machine with source

Post by PB »

The third wheel spins for way too long. Other than that, looks great!
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Nituvious
Addict
Addict
Posts: 1029
Joined: Sat Jul 11, 2009 4:57 am
Location: United States

Re: "virtual" slot machine with source

Post by Nituvious »

IceSoft wrote:The grafik is free for using anywere?
The image isn't mine. I found an old slot machine reel image and cut the pieces I liked together and formed the image that the program uses.
The individual images it was created with were/are public domain images, though.
▓▓▓▓▓▒▒▒▒▒░░░░░
Post Reply