Card game
Blitz3D Forums/Blitz3D Programming/Card game
| ||
Hi all. As a side project, I'm working on a small fun card game to take my mind off of glitches from my charactercreator and stuff like that. now i have some problems. i cant center the 6 rects i also need it to be in the format of: X X X X X X where i can control how many rects go in 1 row. where it says: for x = 1 to 6 i need to be able to select ONE card and move it to the rect, where it will STAY IN the rect. and once a card is in the rect for that turn, it wont allow adding of more than 1 card per card slot rect. i also need there to be more than 1 rect, and that rect to be on the right of the screen also, because thats where the computer's card deck will go. code: Graphics3D 800,600,0,2 HidePointer Global mouseicon mouseicon = LoadImage("sword.png") ResizeImage mouseicon,64,64 HandleImage mouseicon,64,64 Global which Global origx# = 10 Global origy# = 10 Global rx# Global ry# Global rw# Global rh# Global spacing# Global spacing2# Global spacing3# Global spacing4# Global rx1# Global ry1# Global rw1# Global rh1# Global maxcardcount = 60 If maxcardcount > 60 Then maxcardcount=60 Global maxcards=10001 Dim card(maxcards) card(0) = LoadImage("cards\back\ygobacks.jpg") ResizeImage card(0),ImageWidth(card(0))/3,ImageHeight(card(0))/2.5 While Not KeyHit(1) Cls mx = MouseX() my = MouseY() For x = 1 To 4 For y = 1 To 4 rx# = origx#-spacing#*2 ry# = origy#-spacing#*2 rw# = ImageWidth(card(0))+(x*2)+2 rh# = (GraphicsHeight()) spacing# = 0.57 spacing2# = 0.57 spacing3# =0.57 spacing4# = 0.57 rx1# = (rx#+origx#*spacing#) ry1# = (ry#+origy#*spacing2#) rw1# = (rw#+origx#*+spacing3#) rh1# = (rh#+origy#*spacing4#) rx2# = (GraphicsWidth()+ImageWidth(card(0))+origx#+spacing#) Rect rx1#,ry1#,rw1#,rh1#,0 Rect rx2#,ry2#,rw2#,rh2#,0 Next Next For x=1 To maxcardcount DrawImage card(0),rx1#*1.5,ry1#+x*8 Next width = 400 height = 600 If MouseDown(1) If ImageRectOverlap(card(0), imx,imy,mx,my,1,1) For x = 1 To maxcardcount imx = origx#+rx1# imy = ry1#/4+x*8-1 Rect imx,imy,ImageWidth(card(0)),ImageHeight(card(0)),0 Next EndIf EndIf For x = 1 To 6 Rect (GraphicsWidth()/2-x*ImageWidth(card(0)))+(ImageWidth(card(0))+x),GraphicsHeight()/2,ImageWidth(card(0)),ImageHeight(card(0)),0 Next DrawImage mouseicon,mx,my UpdateWorld RenderWorld Flip Wend |
| ||
o also. when selecting a card from: for x = 1 to maxcardcount i need it so that when the mouse is over the card that u want to select, it draws a rect around that card. no matter where the card is on screen. also i need the cards to be placed at the very top of the insides of the rectangle and in middle of inside of rectangle in the loop: for x = 1 to 4 no matter WHERE the rect is at in screen. |
| ||
LOL! when the mouse mouses over the card |
| ||
o ha ha. ur not very helpful. -.- |
| ||
I'm helpful :(. Just not at the moment though. |
| ||
lol! true |
| ||
ok. whats wrong w/ this code?Type TRect Field x1 Field y1 Field x2 Field y2 End Type Global card_pos.TRect[6] Graphics3D 1024,768,0,2 Global maxcards=10001 Dim card(maxcards) card(0) = LoadImage("cards\back\ygobacks.jpg") ResizeImage card(0),ImageWidth(card(0))/3,ImageHeight(card(0))/2.5 setup_card_pos() HidePointer Global mouseicon mouseicon = LoadImage("sword.png") ResizeImage mouseicon,64,64 HandleImage mouseicon,64,64 Global which Global origx# = 200 Global origy# = 200 Global rx# Global ry# Global rw# Global rh# Global spacing# Global spacing2# Global spacing3# Global spacing4# Global rx1# Global ry1# Global rw1# Global rh1# Global maxcardcount = 60 If maxcardcount > 60 Then maxcardcount=60 While Not KeyHit(1) Cls mx = MouseX() my = MouseY() For x = 1 To 4 For y = 1 To 4 rx# = origx#-spacing#*2 ry# = origy#-spacing#*2 rw# = ImageWidth(card(0))+(x*2)+2 rh# = (GraphicsHeight()+ImageWidth(card(0)))/2 spacing# = 0.57 spacing2# = 0.57 spacing3# =0.57 spacing4# = 0.57 rx1# = (rx#+spacing#)/12-12 ry1# = (ry#+spacing2#)/12-24 rw1# = (rw#+spacing3#) rh1# = (rh#+spacing4#) rx2# = (GraphicsWidth()+ImageWidth(card(0))+origx#+spacing#) Rect rx1#,ry1#,rw1#,rh1#,0 Rect rx2#,ry2#,rw2#,rh2#,0 Next Next For x=1 To maxcardcount DrawImage card(0),rx1#*1.5,ry1#+x*8 Next For x = 1 To 6 Rect (GraphicsWidth()/2-x*ImageWidth(card(0)))+(ImageWidth(card(0))+x),GraphicsHeight()/2,ImageWidth(card(0)),ImageHeight(card(0)),0 Next DrawImage mouseicon,mx,my UpdateWorld RenderWorld Flip Wend Function setup_card_pos() N = 0 Y = 0 While Y < 2 X = 0 Y = 0 While X < 3 card_pos[n]\x1 = BASEX + (X * (CARDWIDTH+CARDSPACING)) card_pos[n]\y1 = BASEY + (Y * (CARDHEIGHT+CARDSPACING)) card_pos[n]\x2 = card_pos[n]\x1 + CARDWIDTH card_pos[n]\y2 = card_pos[n]\y1 + CARDHEIGHT X = X + 1 N = N + 1 Wend Y = Y + 1 Wend End Function |
| ||
its saying 'object does not exist' when i use: setup_card_pos() |
| ||
You haveGlobal card_pos.TRect[6] But you never make them into a type handle by doing For bla = 0 to 6 card_pos.TRect[bla] = new TRect Next or For bla = 1 to 6 card_pos.TRect[bla] = new TRect Next but that would leave the first card_pos open... I hate it when people do that. I don't literally "hate" it when people do that, it just mildly annoys me, so mildly that it's not really a problem. Using [6] means there's actually 7 handles starting from 0 to 6. But people keep thinking that it's only 1 to 6. |
| ||
um. i know its 7. lol |
| ||
I've done that enough times. but I try not to use arrays if I can help it. They smell. |
| ||
Global card_pos.TRect[6] For bla = 0 To 6 card_pos.TRect[bla] = New TRect Next doesnt work |
| ||
Type TRect Field x1 Field y1 Field x2 Field y2 End Type Dim card_pos.TRect(6) For bla = 0 To 6 card_pos.TRect(bla) = New TRect Next Graphics3D 1024,768,0,2 Global maxcards=10001 Dim card(maxcards) card(0) = LoadImage("cards\back\ygobacks.jpg") ResizeImage card(0),ImageWidth(card(0))/3,ImageHeight(card(0))/2.5 setup_card_pos() HidePointer Global mouseicon mouseicon = LoadImage("sword.png") ResizeImage mouseicon,64,64 HandleImage mouseicon,64,64 Global which Global origx# = 200 Global origy# = 200 Global rx# Global ry# Global rw# Global rh# Global spacing# Global spacing2# Global spacing3# Global spacing4# Global rx1# Global ry1# Global rw1# Global rh1# Global maxcardcount = 60 If maxcardcount > 60 Then maxcardcount=60 While Not KeyHit(1) Cls mx = MouseX() my = MouseY() For x = 1 To 4 For y = 1 To 4 rx# = origx#-spacing#*2 ry# = origy#-spacing#*2 rw# = ImageWidth(card(0))+(x*2)+2 rh# = (GraphicsHeight()+ImageWidth(card(0)))/2 spacing# = 0.57 spacing2# = 0.57 spacing3# =0.57 spacing4# = 0.57 rx1# = (rx#+spacing#)/12-12 ry1# = (ry#+spacing2#)/12-24 rw1# = (rw#+spacing3#) rh1# = (rh#+spacing4#) rx2# = (GraphicsWidth()+ImageWidth(card(0))+origx#+spacing#) Rect rx1#,ry1#,rw1#,rh1#,0 Rect rx2#,ry2#,rw2#,rh2#,0 Next Next For x=1 To maxcardcount DrawImage card(0),rx1#*1.5,ry1#+x*8 Next For x = 1 To 6 Rect (GraphicsWidth()/2-x*ImageWidth(card(0)))+(ImageWidth(card(0))+x),GraphicsHeight()/2,ImageWidth(card(0)),ImageHeight(card(0)),0 Next DrawImage mouseicon,mx,my UpdateWorld RenderWorld Flip Wend Function setup_card_pos() N = 0 Y = 0 While Y < 2 X = 0 Y = 0 While X < 3 card_pos(n)\x1 = BASEX + (X * (CARDWIDTH+CARDSPACING)) card_pos(n)\y1 = BASEY + (Y * (CARDHEIGHT+CARDSPACING)) card_pos(n)\x2 = card_pos(n)\x1 + CARDWIDTH card_pos(n)\y2 = card_pos(n)\y1 + CARDHEIGHT X = X + 1 N = N + 1 If N > 6 Then N = 6 Wend Y = Y + 1 If KeyHit(1) End Wend End Function ok fixed. now whats wrong w/ this? its all black. normally it would draw the images |
| ||
It is RenderWorld. That clears the screen. |
| ||
i tried. getting rid of it didnt work. |
| ||
Then it must be something else. Still, when you place RenderWorld before flip, you won't see anything you drew before. About that example: it is best to post examples that others can run. Usually not needing any dependencies is nice. Instead of this: im = LoadImage("square.bmp") use this: DrawRect 0, 0, 64, 64 im = CreateImage(64, 64) GrabImage im, 0, 0 That way people can just copy+paste+F5 your example and see where is goes wrong: |
| ||
k. heres what i have so far:Type TRect Field x1 Field y1 Field x2 Field y2 End Type Dim card_pos.TRect(6) For bla = 0 To 6 card_pos.TRect(bla) = New TRect Next Graphics 1024,768,0,2 Global maxcards=10001 Dim card(maxcards) card(0) = CreateImage(64,64) ResizeImage card(0),ImageWidth(card(0))/3,ImageHeight(card(0))/2.5 setup_card_pos() HidePointer Global mouseicon mouseicon = CreateImage(128,128) ResizeImage mouseicon,64,64 HandleImage mouseicon,64,64 Global which Global origx# = 200 Global origy# = 200 Global rx# Global ry# Global rw# Global rh# Global spacing# Global spacing2# Global spacing3# Global spacing4# Global rx1# Global ry1# Global rw1# Global rh1# Global maxcardcount = 60 If maxcardcount > 60 Then maxcardcount=60 While Not KeyHit(1) Cls mx = MouseX() my = MouseY() For x = 1 To 4 For y = 1 To 4 rx# = origx#-spacing#*2 ry# = origy#-spacing#*2 rw# = ImageWidth(card(0))+(x*2)+2 rh# = (GraphicsHeight()+ImageWidth(card(0)))/2 spacing# = 0.57 spacing2# = 0.57 spacing3# =0.57 spacing4# = 0.57 rx1# = (rx#+spacing#)/12-12 ry1# = (ry#+spacing2#)/12-24 rw1# = (rw#+spacing3#) rh1# = (rh#+spacing4#) rx2# = (GraphicsWidth()+ImageWidth(card(0))+origx#+spacing#) Rect rx1#,ry1#,rw1#,rh1#,0 Rect rx2#,ry2#,rw2#,rh2#,0 Next Next For x=1 To maxcardcount DrawImage card(0),rx1#*1.5,ry1#+x*8 Next For x = 1 To 6 Rect (GraphicsWidth()/2-x*ImageWidth(card(0)))+(ImageWidth(card(0))+x),GraphicsHeight()/2,ImageWidth(card(0)),ImageHeight(card(0)),0 Next DrawImage mouseicon,mx,my Flip Wend Function setup_card_pos() N = 0 Y = 0 While Y < 2 X = 0 Y = 0 While X < 3 card_pos(n)\x1 = BASEX + (X * (CARDWIDTH+CARDSPACING)) card_pos(n)\y1 = BASEY + (Y * (CARDHEIGHT+CARDSPACING)) card_pos(n)\x2 = card_pos(n)\x1 + CARDWIDTH card_pos(n)\y2 = card_pos(n)\y1 + CARDHEIGHT X = X + 1 N = N + 1 If N > 6 Then N = 6 Wend Y = Y + 1 If KeyHit(1) End Wend End Function |
| ||
Hey, that's nice. After testing the program, it seems like the program is not getting beyond setup_card_pos. The reason is this:While Y < 2 X = 0 Y = 0 It loops while y<2, but in the loop y is set to y=0, so y will never be bigger than 2. |
| ||
yes. i noticed that. but i have no idea how to turn it into a for loop. |
| ||
That is not needed, but you shouldn't reset Y to zero. Compare: while (x < 3) x = x + 1 wendand .restart if (x < 3) then x = x + 1 goto restart end ifThey are the same thing. Thus, the code you wrote is the same as this: .restart if (y < 2) then y = 0 goto restart endifIt results in an endless loop. |
| ||
thought id bring up this thread again. i still cant figure it out.. |
| ||
Well, you shouldn't reset y to zero. |
| ||
As a side project, I'm working on a small fun card game to take my mind off of glitches from my charactercreator and stuff like that. ...And so you started to develop this game. But then... Thought I'd bring up this thread again. I still can't figure it out... Are you sure this game is serving it's purpose? As for the For...Next loop, you can do this: For X = 0 To Max_X For Y = 0 to Max_Y [...] n=n+1 Next Next |
| ||
Dim card_pos.TRect(6) For bla = 0 To 6 card_pos.TRect(bla) = New TRect Next I thought when you dimmed an array that it was one less than you set it to. For example. Dim myarray(6) But in reality you can only access 0 through 5. That's why people do for n = 0 to numObjs-1 Blah next Change your dim to 7 and see if that works |
| ||
ok. new prob. this code ALMOST works. the prob is that when i try to mousedown, i need the card to move to mouse x and mouse y position, and if the card is in 1 of the 6 rectangles on either side, i need the card to STAY there, unless u rehold mousedown, and if u rehold mousedown and move it back to the deck position, it re-adds to the deck. ;yugioh Global cardx Global cardy Global Max_X = 2 Global Max_Y = 3 Global mx Global my Type TRect Field x1 Field y1 Field x2 Field y2 End Type Dim card_pos.TRect(6) For bla = 0 To 6 card_pos.TRect(bla) = New TRect Next Graphics 1024,768,0,2 Global maxcards=10001 Dim card(maxcards) card(0) = createimage(128,128) ResizeImage card(0),ImageWidth(card(0))/3,ImageHeight(card(0))/2.5 setup_card_pos() HidePointer Global mouseicon mouseicon = createimage(64,64) ResizeImage mouseicon,64,64 HandleImage mouseicon,64,64 Global which Global origx# = 200 Global origy# = 200 Global rx# Global ry# Global rw# Global rh# Global spacing# Global spacing2# Global spacing3# Global spacing4# Global rx1# Global ry1# Global rw1# Global rh1# Global maxcardcount = 60 If maxcardcount > 60 Then maxcardcount=60 While Not KeyHit(1) mx = MouseX() my = MouseY() Cls md = MouseDown(1) cardx = card_pos(n)\x1-ImageWidth(card(0)) cardy = card_pos(n)\y1-ImageHeight(card(0)) If md If ImageRectOverlap(card(0),cardx,cardy,mx,my,1,1) cardx = cardx+mx cardy = cardy+my EndIf Else cardx = card_pos(n)\x1 cardy = card_pos(n)\y1 EndIf For x = 1 To maxcardcount DrawImage card(0),cardx,cardy Next ;For x = 1 To 4 ;For y = 1 To 4 ;rx# = origx#-spacing#*2 ;ry# = origy#-spacing#*2 ;rw# = ImageWidth(card(0))+(x*2)+2 ;rh# = (GraphicsHeight()+ImageWidth(card(0)))/2 ;spacing# = 0.57 ;spacing2# = 0.57 ;spacing3# =0.57 ;spacing4# = 0.57 ;rx1# = (rx#+spacing#)/12-12 ;ry1# = (ry#+spacing2#)/12-24 ;rw1# = (rw#+spacing3#) ;rh1# = (rh#+spacing4#) ;rx2# = (GraphicsWidth()+ImageWidth(card(0))+origx#+spacing#) ;Rect rx1#,ry1#,rw1#,rh1#,0 ;Rect rx2#,ry2#,rw2#,rh2#,0 ;Next ;Next ;For x=1 To maxcardcount ;DrawImage card(0),rx1#*1.5,ry1#+x*8 ;Next ; ;For x = 1 To 6 ;For y = 0 To 1 ;If y = 0 Then cx# = 0.57+(GraphicsWidth()/2-x*ImageWidth(card(0)))+(ImageWidth(card(0))+x) : cy# = 0.57+GraphicsHeight()/2+GraphicsHeight()/2+20 ;If y = 1 Then cx# = 0.57+(GraphicsWidth()/2-x*ImageWidth(card(0)))+(ImageWidth(card(0))+x) : cy# = 0.57+GraphicsHeight()/2+GraphicsHeight()/4+100 ;Rect cx#,cy#-GraphicsHeight()/4,ImageWidth(card(0)),ImageHeight(card(0)),0 ;Next ;Next DrawImage mouseicon,mx,my Text GraphicsWidth()/2-StringWidth(cardx),GraphicsHeight()/2-StringHeight(cardy),cardx+":"+cardy Flip Wend Function setup_card_pos() N = 0 Y = 0 For X = 0 To Max_X-1 For Y = 0 To Max_Y-1 CARDWIDTH = ImageWidth(card(0)) CARDHEIGHT = ImageHeight(card(0)) CARDSPACING = 0.57 BASEX = 1 BASEY = 1 card_pos(n)\x1 = BASEX + (X * (CARDWIDTH+CARDSPACING)) card_pos(n)\y1 = BASEY + (Y * (CARDHEIGHT+CARDSPACING)) card_pos(n)\x2 = card_pos(n)\x1 + CARDWIDTH card_pos(n)\y2 = card_pos(n)\y1 + CARDHEIGHT n=n+1 Next Next End Function |
| ||
Ehm, why are you doing this: card(0) = CreateImage(128,128) ResizeImage card(0),ImageWidth(card(0))/3,ImageHeight(card(0))/2.5 Why don't you create the image already with 42 x 51 ?? |
| ||
because originally, i had a card image loaded using create image. i changed it so it would load for everyone |
| ||
I didn't get your line of thought. |
| ||
um. dude. i made it so instead of loading a card image and stuff, it creates an image. so that anybody can load it |
| ||
I thought when you dimmed an array that it was one less than you set it to. Not quite, no. It's actually one more than you set it to, because it starts from zero, not one. From the B3D docs: The contents of an array can be accessed using the index notation: 0 - indexn, giving indexn+1 number of elements for that particular index range. What you're thinking of is when people want, say, 100 elements in an array, and they dimension the array as dim arrayname[100] because it makes sense to people, and then need to access it from "zero to index-1" (ie 99) so that they only end up with 100 elements, and not the 101 available to them. Personally I just access my array from "one to index" to avoid confusing myself, but I appreciate that's not a very "programmery" way of thinking. :o) |
| ||
ok, so again, the prob is that when i try to mousedown, i need the card to move to mouse x and mouse y position, and if the card is in 1 of the 6 rectangles on either side, i need the card to STAY there, unless u rehold mousedown, and if u rehold mousedown and move it back to the deck position, it re-adds to the deck. the code is above |
| ||
ive tried everything and it wont work >< |
| ||
Well if you've tried everything I guess there's nothing left to do. |
| ||
hey! dont be a smartass. i take that as offensive, so u know what? if u have nothing but smartass comments to say, then dont say anything at all.. |
| ||
Relax, good sir. Put that energy into debugging your code. If you're gonna get offended every time someone posts something on the internet then perhaps politics is more your game. Good day to you. |
| ||
the way you said it IS offensive. and im sure anyone would agree that the way you said it was offensive. |
| ||
If you say so. Surely, anyone would agree. I am, clearly, in a world of my own. Speaking of which, while you're waiting for someone to come <ahem> 'teach you' about the code you can't get working, why don't you perhaps do some work on something you can do. Then, once the difficult code has been <ahem> 'taught' to you, you'll be that much closer to your goal. Wouldn't that be just swell? |
| ||
Have you tried my mouse control library? You can check for when the mouse has been clicked (variable timer), or if the mouse has just been held in, or the mouse is currently being held in. I find it rather handy. And DSW, stop getting so wound up. It's the internet remember? |
| ||
the problem is not the mouse itself. the problem is the coordinates of the card. |
| ||
I know, but i'm saying it may help you elsewhere. If you were to test if the mouse has just been hit, then you'd have to mess about with flags and if statements. |
| ||
i know. if u link me, ill try it :) |
| ||
Link with example: http://www.blitzbasic.com/Community/posts.php?topic=85112 |
| ||
out of curiosity, i dont remember seeing it when this thread was first started, what is the card game? is it one i could google the rules to or a 'made up' one, knowing the rules is half the battle, both for the programmer and player. |
| ||
ill flat out tell you, whether anyone laughs or not. its yugioh |
| ||
so not a 52 card deck normal jobbie personally i wouldnt know the rules to yugio beblades or pokemon, it doesnt stop them existing, just not in my playfield. but as i said, knowing the rules to the game is half the battle, id love to learn shogi (japanese chess) but i dont know anyone interested in chess chess let alone a variant, yet the online versions i have tried either assume prior knowledge or are just broken. same with texas hold em, its poker variant 101, but they assume everyone knows the rules, which i dont, so theyve just borked my experiance playing the game with s**ty insructions that seasoned players never look at |
| ||
well. my code isnt depending on rules just yet. plus. i told u above with example code what the problem is.i just need to place the chosen card in 1 of the 6 rectangles. and if i drag it back to the deck, it needs to readd itself to the deck |
| ||
Best off is to start very basic. First, create a game that uses text only. That way, it is much easier to build the data structure that should lie behind it. |
| ||
Here's another possible game to begin with:Graphics 800,600,0,2 Print "Please type a number greater than 3!" Print " " num$ = Input("->") Locate GraphicsWidth()/2-40,GraphicsHeight()/2 If Int(num) > 3 then Print "You Win!!1" Else Print "Too bad, you lose!!1" Endif Waitkey() End Good luck |
| ||
that doesnt show anything. use this code instead: ;yugioh Global cardx Global cardy Global Max_X = 2 Global Max_Y = 3 Global mx Global my Type TRect Field x1 Field y1 Field x2 Field y2 End Type Dim card_pos.TRect(6) For bla = 0 To 6 card_pos.TRect(bla) = New TRect Next Graphics 1024,768,0,2 Global maxcards=10001 Dim card(maxcards) card(0) = createimage(128,128) ResizeImage card(0),ImageWidth(card(0))/3,ImageHeight(card(0))/2.5 setup_card_pos() HidePointer Global mouseicon mouseicon = createimage(64,64) ResizeImage mouseicon,64,64 HandleImage mouseicon,64,64 Global which Global origx# = 200 Global origy# = 200 Global rx# Global ry# Global rw# Global rh# Global spacing# Global spacing2# Global spacing3# Global spacing4# Global rx1# Global ry1# Global rw1# Global rh1# Global maxcardcount = 60 If maxcardcount > 60 Then maxcardcount=60 While Not KeyHit(1) mx = MouseX() my = MouseY() Cls md = MouseDown(1) cardx = card_pos(n)\x1-ImageWidth(card(0)) cardy = card_pos(n)\y1-ImageHeight(card(0)) If md If ImageRectOverlap(card(0),cardx,cardy,mx,my,1,1) cardx = cardx+mx cardy = cardy+my EndIf Else cardx = card_pos(n)\x1 cardy = card_pos(n)\y1 EndIf For x = 1 To maxcardcount DrawImage card(0),cardx,cardy Next ;For x = 1 To 4 ;For y = 1 To 4 ;rx# = origx#-spacing#*2 ;ry# = origy#-spacing#*2 ;rw# = ImageWidth(card(0))+(x*2)+2 ;rh# = (GraphicsHeight()+ImageWidth(card(0)))/2 ;spacing# = 0.57 ;spacing2# = 0.57 ;spacing3# =0.57 ;spacing4# = 0.57 ;rx1# = (rx#+spacing#)/12-12 ;ry1# = (ry#+spacing2#)/12-24 ;rw1# = (rw#+spacing3#) ;rh1# = (rh#+spacing4#) ;rx2# = (GraphicsWidth()+ImageWidth(card(0))+origx#+spacing#) ;Rect rx1#,ry1#,rw1#,rh1#,0 ;Rect rx2#,ry2#,rw2#,rh2#,0 ;Next ;Next ;For x=1 To maxcardcount ;DrawImage card(0),rx1#*1.5,ry1#+x*8 ;Next ; ;For x = 1 To 6 ;For y = 0 To 1 ;If y = 0 Then cx# = 0.57+(GraphicsWidth()/2-x*ImageWidth(card(0)))+(ImageWidth(card(0))+x) : cy# = 0.57+GraphicsHeight()/2+GraphicsHeight()/2+20 ;If y = 1 Then cx# = 0.57+(GraphicsWidth()/2-x*ImageWidth(card(0)))+(ImageWidth(card(0))+x) : cy# = 0.57+GraphicsHeight()/2+GraphicsHeight()/4+100 ;Rect cx#,cy#-GraphicsHeight()/4,ImageWidth(card(0)),ImageHeight(card(0)),0 ;Next ;Next DrawImage mouseicon,mx,my Text GraphicsWidth()/2-StringWidth(cardx),GraphicsHeight()/2-StringHeight(cardy),cardx+":"+cardy Flip Wend Function setup_card_pos() N = 0 Y = 0 For X = 0 To Max_X-1 For Y = 0 To Max_Y-1 CARDWIDTH = ImageWidth(card(0)) CARDHEIGHT = ImageHeight(card(0)) CARDSPACING = 0.57 BASEX = 1 BASEY = 1 card_pos(n)\x1 = BASEX + (X * (CARDWIDTH+CARDSPACING)) card_pos(n)\y1 = BASEY + (Y * (CARDHEIGHT+CARDSPACING)) card_pos(n)\x2 = card_pos(n)\x1 + CARDWIDTH card_pos(n)\y2 = card_pos(n)\y1 + CARDHEIGHT n=n+1 Next Next End Function u already know whats not working. |
| ||
Just to clarify: Your specifications that you want this program to reach are, put simply: 1. Take card from deck (top card?) and place in 1 of 6 rectangles with the mouse. 2. Select a card from 1 of 6 rectangles and place back in deck (at bottom of deck I assume?) from Matt |
| ||
take card from bottom of deck. place in rectangle 1 of 6 UNLESS u drag it back, in which case, it would go back to the same position it was in. |
| ||
Here's something that may be of use, have a play around with it to get some ideas: |
| ||
here's what i have so far: ;Simple Deck of Cards Arrangement Program ; ;Not necessarily the best way, but simply one possible way of achieving this. Global width=1024 Global height=768 Graphics width,height,0,2 SetBuffer BackBuffer() HidePointer ;declare some variables and types Type TCardImage Field Image Field Name$ Field Description$ End Type Type TBaseDeck Field Name$ End Type Type TDeck Field CardName$ Field X,Y Field Selected End Type Global mousepointerimage Const numberofcardsindeck = 20 Global cardname$ Global carddesc$ Global cnum mousepointerimage = LoadImage("mousepointer.bmp") If mousepointerimage = 0 Then ;if mousepointerimage is not a valid image then create one instead of loading one mousepointerimage=CreateImage(64,64) SetBuffer ImageBuffer(mousepointerimage) Color 255,255,255 Line 0,0,16,0 Line 0,0,0,16 Line 0,0,48,48 SetBuffer BackBuffer() EndIf ;ideally you would have a more elegant and flexible load routine for your cards, ;but this is just something simple: For cardnumber = 1 To numberofcardsindeck CardImage.TCardImage=New TCardImage CardImage\Image=LoadImage("cards\back\ygobacks.jpg") ;CreateImage(100,150) ResizeImage CardImage\Image,ImageWidth(CardImage\Image)/3.5,ImageHeight(CardImage\Image)/3.5 SetBuffer ImageBuffer(CardImage\Image) cnum=cardnumber CardImage\Name = "Card" + Str(cnum) CardImage\Description = "Card No:" + Str(cnum) cardname$=CardImage\Name carddesc$=CardImage\Description ; Color Rand(4,8)*32,Rand(4,8)*32,Rand(4,8)*32 ; Rect 0,0,ImageWidth(CardImage\Image),ImageHeight(cardimage\image),1 SetBuffer BackBuffer() Next ;Now we will call a function called "shuffledeck" ;this function will do as the name says, shuffle the deck of 20 cards. shuffledeck() selected=0 Repeat Cls ;For x = 1 To 6 ;For Card.TCardImage=Each TCardImage ;Rect (GraphicsWidth()/2-ImageWidth(card\image))*x/3.5+4,(GraphicsHeight()-ImageHeight(card\image))-0.57,ImageWidth(card\image),ImageHeight(card\image),0 ;Next ;Next ;For x = 1 To 6 ;For Card.TCardImage=Each TCardImage ;Rect (GraphicsWidth()/2-ImageWidth(card\image))*x/3.5+4,(ImageHeight(card\image))-(ImageHeight(card\image)-4)-0.57,ImageWidth(card\image),ImageHeight(card\image),0 ;Next ;Next x = x+1 x2=GraphicsWidth()/2 speed# = 0.57 If x > x2 Then x = x2 Text x-(speed#/4)/4,GraphicsHeight()/2,"Your move",True,True If x = x2 : EndIf mx=MouseX() my=MouseY() lmb=MouseDown(1) If lmb=0 Then selected=0 For deck.tdeck=Each tdeck deck\selected = 0 Next EndIf For Deck.TDeck=Each TDeck For Card.TCardImage=Each TCardImage If Deck\CardName=Card\Name Then If deck\selected<>0 Then deck\x=mx deck\y=my Color 255,128,128 Rect deck\x,deck\y,ImageWidth(card\image)+20,ImageHeight(card\image)+20,0 Color 255,255,255 Text MouseX()+ImageWidth(card\image)/2,MouseY()+ImageHeight(card\image)/2,"x:"+deck\x+":"+"y:"+deck\y+":"+carddesc$,True,True Else If lmb<>0 And mx>deck\x And my>deck\y And mx<deck\x + ImageWidth(card\image) And my<deck\y+ImageHeight(card\image) And selected=0 Then deck\selected=1 selected=1 EndIf EndIf Exit EndIf Next Next Deck.TDeck=Last TDeck While Deck.TDeck<>Null For Card.TCardImage=Each TCardImage If Deck\CardName=Card\Name Then DrawBlock Card\Image,deck\x+(ImageWidth(Card\Image)/4+0.57),deck\y+(ImageHeight(Card\Image)/4+0.57) Exit EndIf Next Deck = Before Deck Wend DrawImage mousepointerimage,mx,my VWait Flip False Until KeyDown(1) End Function ShuffleDeck() Delete Each TDeck Delete Each TBaseDeck For Card.TCardImage=Each TCardImage BaseDeck.TBaseDeck=New TBaseDeck BaseDeck\Name=Card\Name Next For index = 1 To numberofcardsindeck Deck.TDeck=New TDeck cardcount=0 For basedeck.tbasedeck=Each tbasedeck cardcount = cardcount + 1 Next cardindex=Rand(1,cardcount) For basedeck.tbasedeck=Each tbasedeck cardindex=cardindex - 1 If cardindex = 0 deck\cardname = basedeck\name Delete basedeck Exit EndIf Next Next End Function forgive me for not changing loadimage. im tired x) |
| ||
DarkShadowWing, did you say that you work for Xylvan? |
| ||
why? |
| ||
Now now... For all his faults, Xylvan does actually release stuff, and stuff that seems to realise his vision. Credit where credit's due. |
| ||
ignoring that last comment, can someone tell me whats wrong in the code i posted above? |