News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

How do I load playing card images into my game?

Started by jsoares, March 28, 2008, 07:15:50 PM

Previous topic - Next topic

jsoares

I have finished the logic to a card game I used to play when I was little. I now want to load images of playing cards and connect each card to numbers in my program: for example, the ace of spades would be 1, the ace of hearts 14, the ace of diamonds 28 and the ace of clubs 31.

I have seen an example program that tried to load sprites(each card was a sprite) into the program and then it gave a command "LoadAllSprites". The program itself did not run; there were syntax errors in it.

Can anyone point me to a simple tutorial on how to load these card images and use them in my card game?  Also, a tutorial on how to mouse click on a card, how to move cards around, etc. If there is one sample program that teaches these things, I'd appreciate knowing about it.

Thanks.

John Soares

Draco9898

#1
I can give a ripping function that does alot of images at once, a batch if you will

You'll need the x,y,offset, the numbers of images by x,y, etc.

or you can just load your big image into a temp image number and use GetImage over and over again on it

for mouse over, look at your mouse pos using MouseX(), MouseY() and see IF this position is within the cards area of X (let's say your card is 35 pixels wide +Xposition of card (let's say your card is at screen position 300), samething for Y, your card is 60 pixels high it's y position. You check these inside a nested loop when the user clicks.
DualCore Intel Core 2 processor @ 2.3 ghz, Geforce 8600 GT (latest forceware drivers), 2 gigs of ram, WIN XP home edition sp2, FireFox 2.

"You'll no doubt be horrified to discover that PlayBasic is a Programming Language." -Kevin

kevin

QuoteCan anyone point me to a simple tutorial on how to load these card images and use them in my card game?

  If you want to load an image into memory to be displayed...  See..   LoadImage


QuoteAlso, a tutorial on how to mouse click on a card, how to move cards around, etc. If there is one sample program that teaches these things, I'd appreciate knowing about it.

  See Drag Sprites


Big C.

#3
Hi John,

here is another way to load some cards based on a routine that i have written in 2006... Its on you to merge it with Kevins Solution...


; PROJECT : TilesLoader
; AUTHOR  : Big C.
; CREATED : 08.07.2006
; EDITED  : 29.03.2008
; ---------------------------------------------------------------------


;Used screen: 1024x768, 16 Bit, windowed
OpenScreen 1024, 768, 16, 1

SetFps 60

; ****************************************************************************
; * Global Definitions
; ****************************************************************************

; we need an array to store our Card Images as Tiles.
Dim MyTiles(-1)

;MyImage with space around the Tiles of 1 Pixel
MyImage$ = "cards.jpg"

TileWidth = 72
TileHeight = 96

; Set TileSpacer to the Width of your Spacer in Pixel
; For our Image I use 1 Pixel
TileSpacer = 1

; TileScaleFlag scales your Tiles down or up or not - its a feature
; -2 = 50%
; -1 = 70%
;  0 = Original Size = no scaling
;  1 = 125%
;  2 = 150%
TileScaleFlag = 0

; Colour of Transparency
TransparentColour = RGB(255,0,255)


; ****************************************************************************
; * Subroutine: LoadTiles
; ****************************************************************************

Psub LoadTiles(TArray(), ImageFile$, TWidth, THeight, TSpacer, TScaleFlag, TColour)

If TScaleFlag < -2 Or TScaleFlag > 2 Or TScaleFlag = 0
Scale = False
Else
TScaleFactor# = 1 + (0.25*TScaleFlag)
Scale = True
EndIf

Temp_Image = LoadNewImage(ImageFile$)

TColumns = GetImageWidth(Temp_Image)/(TWidth + TSpacer)
TRows = GetImageHeight(Temp_Image)/(THeight + TSpacer)

ReDim TArray(TColumns*TRows)

PosX = TSpacer
PosY = TSpacer

ImageNumber = 1

RenderToImage Temp_Image

For Rows = 0 To TRows-1
For Columns = 0 To TColumns-1
TArray(ImageNumber) = GetFreeImage()
GetImage TArray(ImageNumber), PosX, PosY, PosX + TWidth, PosY + THeight
If Scale
ScaleImage TArray(ImageNumber), TScaleFactor#, TScaleFactor#, 0
EndIf
ImageMaskColour TArray(ImageNumber), TColour
PosX = PosX + TWidth + TSpacer
Inc ImageNumber
Next Columns
PosX = TSpacer
PosY = PosY + THeight + TSpacer
Next Rows

RenderToScreen

DeleteImage Temp_Image

TotalTiles = ImageNumber

EndPsub

; ****************************************************************************
; * Initialize
; ****************************************************************************

LoadTiles(MyTiles(), MyImage$, TileWidth, TileHeight, TileSpacer, TileScaleFlag, TransparentColour)

; ****************************************************************************
; * Main Loop
; ****************************************************************************

Repeat

Cls RGB(0,0,0)

For rows = 0 To 3
For columns = 0 To 12
; Show the grabbed Card Images in transparency mode and their Image Numbers ...
WhichImage = (rows*13)+columns+1
Text (columns*(TileWidth+5))+30, (rows*(TileHeight+30))+80, Str$(WhichImage)
DrawImage MyTiles(WhichImage), (columns*(TileWidth+5))+10, (rows*(TileHeight+30))+100, 1
Next
Next

Text 50,600,"Press Space Bar for moving a random Tile... :)"

Sync
Until SpaceKey()

;****************************************************************************
;* Moving Example to show that every Image is stand alone
;****************************************************************************

;we got 52 Images... so we randomize one to move
ImageToMove = RNDRange(1,52)

;Steps to move
MovingSteps = 3

;Our starting position
Xpos = 100
Ypos = 100

Repeat

Cls RGB(0,0,0)

DrawImage MyTiles(ImageToMove), Xpos, Ypos, 1

If Xpos > 950 then MovingSteps = MovingSteps * -1
If Xpos < 100 then MovingSteps = MovingSteps * -1

Xpos = Xpos + MovingSteps

Text 50,600,"Press ESC Key for Quit... "

Sync

Until EscKey()

;Make a clean gone away ;)
DeleteAllImages

UnDimALL

CloseScreen

End


Cheers Big C.  :)

jsoares

I have now succeeded in loading a playing card into my program. I'll now work on manipulating it on screen via the mouse.  Thanks to all who took the time to read my question and reply.

Best,

John Soares
jsoares@safe-mail.net