Card game

Blitz3D Forums/Blitz3D Programming/Card game

Guy Fawkes(Posted 2009) [#1]
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



Guy Fawkes(Posted 2009) [#2]
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.


GIB3D(Posted 2009) [#3]
LOL!
when the mouse mouses over the card



Guy Fawkes(Posted 2009) [#4]
o ha ha.

ur not very helpful. -.-


GIB3D(Posted 2009) [#5]
I'm helpful :(. Just not at the moment though.


Guy Fawkes(Posted 2009) [#6]
lol!

true


Guy Fawkes(Posted 2009) [#7]
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



Guy Fawkes(Posted 2009) [#8]
its saying 'object does not
exist'

when i use:

setup_card_pos()


GIB3D(Posted 2009) [#9]
You have
Global 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.


Guy Fawkes(Posted 2009) [#10]
um. i know its 7.

lol


_PJ_(Posted 2009) [#11]
I've done that enough times.
but I try not to use arrays if I can help it. They smell.


Guy Fawkes(Posted 2009) [#12]
Global card_pos.TRect[6]
For bla = 0 To 6
card_pos.TRect[bla] = New TRect
Next

doesnt work


Guy Fawkes(Posted 2009) [#13]
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


Warner(Posted 2009) [#14]
It is RenderWorld. That clears the screen.


Guy Fawkes(Posted 2009) [#15]
i tried.

getting rid of

it didnt work.


Warner(Posted 2009) [#16]
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:



Guy Fawkes(Posted 2009) [#17]
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



Warner(Posted 2009) [#18]
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.


Guy Fawkes(Posted 2009) [#19]
yes. i noticed that.

but i have no idea how to turn it into a for loop.


Warner(Posted 2009) [#20]
That is not needed, but you shouldn't reset Y to zero.
Compare:
while (x < 3)
  x = x + 1
wend
and
.restart
if (x < 3) then
  x = x + 1
  goto restart
end if
They are the same thing.
Thus, the code you wrote is the same as this:
.restart
if (y < 2) then
    y = 0
    goto restart
endif
It results in an endless loop.


Guy Fawkes(Posted 2009) [#21]
thought id bring up this thread again.

i still cant figure it out..


Warner(Posted 2009) [#22]
Well, you shouldn't reset y to zero.


Kryzon(Posted 2009) [#23]
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



Chroma(Posted 2009) [#24]
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


Guy Fawkes(Posted 2009) [#25]
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



Kryzon(Posted 2009) [#26]
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 ??


Guy Fawkes(Posted 2009) [#27]
because originally, i had a card image loaded using create image.

i changed it so it would load for everyone


Kryzon(Posted 2009) [#28]
I didn't get your line of thought.


Guy Fawkes(Posted 2009) [#29]
um. dude. i made it so instead of loading a card image and stuff, it creates an image.

so that anybody can load it


LineOf7s(Posted 2009) [#30]
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)


Guy Fawkes(Posted 2009) [#31]
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


Guy Fawkes(Posted 2009) [#32]
ive tried everything and it wont work ><


LineOf7s(Posted 2009) [#33]
Well if you've tried everything I guess there's nothing left to do.


Guy Fawkes(Posted 2009) [#34]
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..


LineOf7s(Posted 2009) [#35]
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.


Guy Fawkes(Posted 2009) [#36]
the way you said it IS offensive. and im sure anyone would agree that the way you said it was offensive.


LineOf7s(Posted 2009) [#37]
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?


Ross C(Posted 2009) [#38]
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?


Guy Fawkes(Posted 2009) [#39]
the problem is not the mouse itself.

the problem is the coordinates of the card.


Ross C(Posted 2009) [#40]
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.


Guy Fawkes(Posted 2009) [#41]
i know.

if u link me, ill try it :)


Ross C(Posted 2009) [#42]
Link with example:

http://www.blitzbasic.com/Community/posts.php?topic=85112


Ginger Tea(Posted 2009) [#43]
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.


Guy Fawkes(Posted 2009) [#44]
ill flat out tell you, whether anyone laughs or not.

its yugioh


Ginger Tea(Posted 2009) [#45]
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


Guy Fawkes(Posted 2009) [#46]
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


Warner(Posted 2009) [#47]
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.



Kryzon(Posted 2009) [#48]
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


Guy Fawkes(Posted 2009) [#49]
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.


Matty(Posted 2009) [#50]
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


Guy Fawkes(Posted 2009) [#51]
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.


Matty(Posted 2009) [#52]
Here's something that may be of use, have a play around with it to get some ideas:




Guy Fawkes(Posted 2009) [#53]
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)


Chroma(Posted 2009) [#54]
DarkShadowWing, did you say that you work for Xylvan?


Guy Fawkes(Posted 2009) [#55]
why?


LineOf7s(Posted 2009) [#56]
Now now...

For all his faults, Xylvan does actually release stuff, and stuff that seems to realise his vision. Credit where credit's due.


Guy Fawkes(Posted 2009) [#57]
ignoring that last comment, can someone tell me whats wrong in the code i posted above?