PureCardDraw: Making card games is easy
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
PureCardDraw: Making card games is easy
Would you like to draw playing cards straight from the cards.dll supplied with Windows? Here is a lib that lets you do it:
http://www.networkmaestro.com/PureCardDraw.zip (3.x for now, v4 version to come soon)
Enjoy it!
http://www.networkmaestro.com/PureCardDraw.zip (3.x for now, v4 version to come soon)
Enjoy it!
Last edited by netmaestro on Wed Feb 22, 2006 4:56 am, edited 3 times in total.
BERESHEIT
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
oops I forgot to document the Color parameter - sorry, fixed now.
Last edited by netmaestro on Wed Feb 22, 2006 4:54 am, edited 2 times in total.
BERESHEIT
Here's some quick code that lets you access the playing cards.
Code: Select all
#ClubA = 1
#Club2 = 2
#Club3 = 3
#Club4 = 4
#Club5 = 5
#Club6 = 6
#Club7 = 7
#Club8 = 8
#Club9 = 9
#Club10 = 10
#ClubJ = 11
#ClubQ = 12
#ClubK = 13
#DiamondA = 14
#Diamond2 = 15
#Diamond3 = 16
#Diamond4 = 17
#Diamond5 = 18
#Diamond6 = 19
#Diamond7 = 20
#Diamond8 = 21
#Diamond9 = 22
#Diamond10 = 23
#DiamondJ = 24
#DiamondQ = 25
#DiamondK = 26
#HeartA = 27
#Heart2 = 28
#Heart3 = 29
#Heart4 = 30
#Heart5 = 31
#Heart6 = 32
#Heart7 = 33
#Heart8 = 34
#Heart9 = 35
#Heart10 = 36
#HeartJ = 37
#HeartQ = 38
#HeartK = 39
#SpadeA = 40
#Spade2 = 41
#Spade3 = 42
#Spade4 = 43
#Spade5 = 44
#Spade6 = 45
#Spade7 = 46
#Spade8 = 47
#Spade9 = 48
#Spade10 = 49
#SpadeJ = 50
#SpadeQ = 51
#SpadeK = 52
Global Dim Cards(52)
Procedure.l GetCard(dll.l, face.l)
CreateImage(face, 71, 96)
card.l = LoadImage_(dll, face, #IMAGE_BITMAP, 71, 96, #LR_DEFAULTCOLOR)
StartDrawing(ImageOutput(face))
DrawImage(card, 0, 0)
StopDrawing()
DeleteObject_(card)
ProcedureReturn ImageID(face)
EndProcedure
If OpenWindow(0, 0, 0, 500, 400, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
cards.l = OpenLibrary(0, "cards.dll")
ImageGadget(0, 10, 10, 71, 96, GetCard(cards, #SpadeA))
ImageGadget(1, 90, 10, 71, 96, GetCard(cards, #SpadeK))
ImageGadget(2, 170, 10, 71, 96, GetCard(cards, #SpadeQ))
ImageGadget(3, 250, 10, 71, 96, GetCard(cards, #SpadeJ))
ImageGadget(4, 330, 10, 71, 96, GetCard(cards, #Spade10))
CloseLibrary(0)
Repeat
Event.l = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
End
What goes around comes around.
PB 5.21 LTS (x86) - Windows 8.1
PB 5.21 LTS (x86) - Windows 8.1
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Nice clean example, Sparkie. It's just missing a couple of features: transparent card drawing, backs and placeholders. I'm not really planning to release a compiled lib this time around as it's fairly short, so here's my includefile offering that works like this:
-cardnumbers start at the ace and go 1-13
-suits are clubs, diamonds, hearts, spades: 1-4
-suit 5 are the 13 available cardbacks
-suit 6 has two cardnumbers, 1 and 2 for the two placeholders
do: result=InitCards(transcolor) ; transcolor is the color of your table
A result of 1 means a successful initialization of the cards. You can now do: ImageID=GetCard(cardnumber,suit) for any card, back or placeholder.
It's actually far simpler to use than my original lib compiled for 3.94. That one is deprecated now.
Here's the code:
And here's the obligatory test proggie:
-cardnumbers start at the ace and go 1-13
-suits are clubs, diamonds, hearts, spades: 1-4
-suit 5 are the 13 available cardbacks
-suit 6 has two cardnumbers, 1 and 2 for the two placeholders
do: result=InitCards(transcolor) ; transcolor is the color of your table
A result of 1 means a successful initialization of the cards. You can now do: ImageID=GetCard(cardnumber,suit) for any card, back or placeholder.
It's actually far simpler to use than my original lib compiled for 3.94. That one is deprecated now.
Here's the code:
Code: Select all
;========================================================
; Program: PureCardDraw.pbi
; Author: netmaestro
; Date: November 14, 2006
; Target OS: MS Windows All
; Target Compiler: PureBasic Version 4.0+
; License: Totally free and unrestricted
; Credit appreciated, not required
;========================================================
#Clubs = 1
#Diamonds = 2
#Hearts = 3
#Spades = 4
#Back = 5
#PlaceHolder = 6
#Jack = 11
#Queen = 12
#King = 13
Global Dim Cards(13,6)
ProcedureDLL InitCards(transcolor)
lib = OpenLibrary(#PB_Any,"cards.dll")
If lib
CallFunction(lib,"cdtInit",@w.l,@h.l)
;Card fronts
For i=1 To 13
For j=1 To 5
CurCard = CreateImage(#PB_Any, 71, 96, 24)
Cards(i,j) = ImageID(CurCard)
hdc = StartDrawing(ImageOutput(CurCard))
Box(0,0,71,96,transcolor)
If j=#Back
CallFunction(lib,"cdtDraw",hdc,0,0,i+52,1,RGB(100,200,100))
Else
CallFunction(lib,"cdtDraw",hdc,0,0,(i-1)*4+j-1,0,0)
EndIf
StopDrawing()
Next
Next
;Placeholders
For i=1 To 2
CurCard = CreateImage(#PB_Any, 71, 96, 24)
Cards(i,6) = ImageID(CurCard)
hdc = StartDrawing(ImageOutput(CurCard))
Box(0,0,71,96,transcolor)
CallFunction(lib,"cdtDraw",hdc,0,0,i+66,1,0)
StopDrawing()
Next
CallFunction(lib,"cdtTerm")
CloseLibrary(1)
ProcedureReturn 1
Else
ProcedureReturn 0
EndIf
EndProcedure
ProcedureDLL GetCard(value, suit)
ProcedureReturn Cards(value, suit)
EndProcedure
Code: Select all
IncludeFile "PureCardDraw.pbi"
InitCards(RGB(0,128,0))
OpenWindow(0, 0, 0, 1000, 700, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
SetWindowColor(0,RGB(0,128,0))
CreateGadgetList(WindowID(0))
For i=1 To 13
ImageGadget(#PB_Any,75*i-65,60,0,0,GetCard(i,#Clubs))
ImageGadget(#PB_Any,75*i-65,160,0,0,GetCard(i,#Diamonds))
ImageGadget(#PB_Any,75*i-65,260,0,0,GetCard(i,#Hearts))
ImageGadget(#PB_Any,75*i-65,360,0,0,GetCard(i,#Spades))
ImageGadget(#PB_Any,75*i-65,460,0,0,GetCard(i,#Back))
Next
ImageGadget(#PB_Any,10,560,0,0,GetCard(1,#PlaceHolder))
ImageGadget(#PB_Any,85,560,0,0,GetCard(2,#PlaceHolder))
Repeat
Event.l = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
Last edited by netmaestro on Tue Nov 14, 2006 8:52 am, edited 2 times in total.
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
netmaestro,
I was having trouble with one function in my own code and just confirmed it with your code. When trying to draw cards in the inverse mode, the two black suits show only an empty white image for the cards ace through 10 (the face cards are OK).
Change this line: to: to see what I mean.
This occurs for me in Windows XP - can someone please try it on a different Windows version and let me know what happens?
Thanks,
Eric
I was having trouble with one function in my own code and just confirmed it with your code. When trying to draw cards in the inverse mode, the two black suits show only an empty white image for the cards ace through 10 (the face cards are OK).
Change this line:
Code: Select all
CallFunction(lib,"cdtDraw",hdc,0,0,(i-1)*4+j-1,0,0)
Code: Select all
CallFunction(lib,"cdtDraw",hdc,0,0,(i-1)*4+j-1,2,0)
This occurs for me in Windows XP - can someone please try it on a different Windows version and let me know what happens?
Thanks,
Eric
This was written and posted back in 2003 (now updated for PB4.0)...
http://www.reelmedia.org/pureproject/ar ... kJack2.zip
It was made as an example to show how to use the Microsoft Card.dll to easily draw the cards. It's a simple BlackJack game.
http://www.reelmedia.org/pureproject/ar ... kJack2.zip
It was made as an example to show how to use the Microsoft Card.dll to easily draw the cards. It's a simple BlackJack game.