|
Post by Rod on Feb 16, 2023 9:44:56 GMT -5
This is a link to a set of card sprites. Back to basics. I hope to see a post or two using these sprites. I will post a couple of short demos on how to use them. EDIT now includes Solitaire game. Its click and play, drag and drop components are there but just click on the card you want to play and it will automatically move to a valid location, click on it again if it is in the wrong position. Animate.bas shows how to animate and drag and drop the cards with the mouse. Edit the down load contains three demo programs using the card engine/functions. Animate.bas, Solitaire.bas and a rudimentary Blackjack.bas 'version8 9/3/23 'increased verticle gapping 'fixed refusal to move, reserve pile flipping 'fixed logic error allowing face down column moves 'added back in placeholder and reserve circle marker 'fixed reserve pile flipping for less than three cards remaining 'fixed column refusal to move issue again thanks Anatoly 'fixed zero cards remaining flip issue gamebin.webs.com/CardSprites.zip
|
|
|
Post by Rod on Feb 17, 2023 11:01:31 GMT -5
This code is first steps in mouse handling. You can pick, move (left click and drag) and turn a card (right click). The loading sequence is changed, sprites are now just c1 - c52 So the card images and info are still in card() but we have a new deck() to separate shuffling and dealing from the card() resource. Next will be some animations. If this is your first try then download the folder in the first post, extract it to wherever you normally keep your projects then load up the following code and save it into the directory containing the mages. Now it will run.
nomainwin dim card(52,5) suit=1 'card's suit 1=hearts 2=diamonds 3=spades 4=clubs face=2 'face value a=1 2-10 j=11 q=12 k=13 xpos=3 'current x position of card ypos=4 'current y position of card stat=5 'face up face down 1/0
deckpointer=1 'where we are in dealing from the deck
'open a window and graphicbox WindowHeight = 756 WindowWidth = 1024 graphicbox #w.g, 0, 0, 1024, 756 open "sprite" for window_nf as #w #w "trapclose quit"
'set up background #w.g "down ; fill darkgreen ; getbmp bgd 0 0 1024 756 ; background bgd"
'load card images gosub [loadcardimages]
'create pack dim deck(52,2) for c=1 to 52 deck(c,1)=c deck(c,2)=rnd(0) next
'draw in a diagonal across board for c= 1 to 52 cc=deck(c,1) #w.g "spritetofront c";cc card(cc,xpos)=c*15 card(cc,ypos)=c*10 #w.g "spritexy c";cc;" ";card(cc,xpos);" ";card(cc,ypos) call pause 16 #w.g "drawsprites" next
'shuffle and display anew sort deck(,1,52,2 for c= 1 to 52 cc=deck(c,1) #w.g "spritetofront c";cc card(cc,xpos)=c*15 card(cc,ypos)=c*10 #w.g "spritexy c";cc;" ";card(cc,xpos);" ";card(cc,ypos) call pause 16 #w.g "drawsprites" next
'put face down and move pack to centre position for c= 1 to 52 cc=deck(c,1) #w.g "spriteimage c";cc;" back" card(cc,xpos)=446+c/3 card(cc,ypos)=233-c/3 card(cc,stat)=0 'face down #w.g "spritexy c";cc;" ";card(cc,xpos);" ";card(cc,ypos) call pause 16 #w.g "drawsprites" next
'deal 2 off the top for d= 1 to 2 cc=deck(deckpointer,1) deckpointer=deckpointer+(deckpointer<52) card(cc,xpos)=400+30*d card(cc,ypos)=500 #w.g "spritexy c";cc;" ";card(cc,xpos);" ";card(cc,ypos) call pause 16 #w.g "drawsprites" next
'set up a handler to pick a card #w.g "when leftButtonDown [pick]" 'set up a handler to turn a card #w.g "when rightButtonUp [turn]" wait
[turn] 'if we hit a card turn it over #w.g "when rightButtonUp" #w.g "spritexy point ";MouseX;" ";MouseY #w.g "drawsprites ; spritecollides point card$" card$=right$(card$,2) if left$(card$,1)="c" then c=val(right$(card$,1)) else c=val(card$) if c then if card(c,stat)=1 then #w.g "spriteimage c";c;" back" card(c,stat)=0 else #w.g "spriteimage c";c;" c";c card(c,stat)=1 end if end if #w.g "drawsprites" #w.g "when rightButtonUp [turn]" wait
[pick] 'turn off event handling and see what mouse 'pointer collided with. #w.g "when leftButtonDown" #w.g "spritexy point ";MouseX;" ";MouseY #w.g "drawsprites ; spritecollides point card$" card$=right$(card$,2) if left$(card$,1)="c" then c=val(right$(card$,1)) else c=val(card$)
'if we collided get the offset and set 'up for tracking and dropping if c then xoff=card(c,xpos)-MouseX yoff=card(c,ypos)-MouseY '#w.g "spritetofront c";c #w.g "when leftButtonMove [trackit]" #w.g "when leftButtonUp [dropit]" else 'we hit nothing, set up picking again #w.g "when leftButtonDown [pick]" #w.g "spritexy point -10 -10" end if wait
[trackit] 'track and draw the card movement #w.g "spritexy c";c;" ";MouseX+xoff;" ";MouseY+yoff #w.g "drawsprites" wait
[dropit] 'drop the card and set up for picking again #w.g "when leftButtonUp" #w.g "when leftButtonMove" card(c,xpos)=MouseX+xoff card(c,ypos)=MouseY+yoff #w.g "when leftButtonDown [pick]" #w.g "spritexy point -10 -10" wait
wait
[loadcardimages] loadbmp "back", "bac.bmp" f=1 s$="h" for c=1 to 52 card(c,0)=c card(c,1)=f card(c,2)=s card(c,3)=-200 card(c,4)=-100 card(c,5)=1 loadbmp "c";c ,s$;f;".bmp" #w.g "addsprite c";c;" c";c;" back" #w.g "spritexy c";c;" -200 -100" 'off board f=f+1 if c=13 then f=1 : s$="d" if c=26 then f=1 : s$="s" if c=39 then f=1 : s$="c" next loadbmp "point","point.bmp" #w.g "addsprite point point" #w.g "spritexy point -10 -10" return
sub pause n timer n,[done] wait [done] timer 0 end sub
sub quit h$ timer 0 close #w end end sub
|
|
|
Post by Rod on Feb 21, 2023 6:45:32 GMT -5
The link in the first post now has animate.bas and the point.bmp needed for mouse handling. I have created a bunch of functions to animate the cards. Still more to do but making good progress. Animate.bas will demo some of the animation techniques and deal and move the cards.
This is an extract that show the functions I have coded at this point.
'load card images call loadcardimages
call scaledeck 100 'scales entire deck call sortdeck 2 'orders all undealt cards in deck 1=ordered 2=random call showdeck 10,100,up 'undealt cards in a line starting at x,y,face up or down(for testing) call pause 2000 call movedeck 446,273,down 'undealt cards placed at x,y,face up or down call dealcard 1,5,up 'deal player n,x cards face up or down call dealcard 2,5,up 'dealcard also sorts the hand on value and displays the hand with drawhand call dealcard 3,5,up call dealcard 4,5,up call pause 2000 call dealcard 1,2,down call dealcard 4,2,down call pause 2000 call fliphand 1,up 'flip player n's hand face up or down call fliphand 4,up call sorthand 1,card 'sort player n's hand by value or card call drawhand 1 'redraws the players hand call pause 2000 call movecard 1,400,200 'move card cc to x,y call flipcard 1,up 'flip card cc face up or down call setblock 1,1 'block or unblock card cc 1=blocked 0=clear print getsuit(1) 'query suit print getvalue(1) 'query value print getcolor(1) 'query color print getface(1) 'query face up or down print isblock(1) 'query blocked or unblocked
|
|
|
Post by Rod on Mar 9, 2023 5:09:57 GMT -5
Some bug fixes in the download.
|
|