52 Card Pick Up
-
This used to be an hilarious card game when we were young
Seriously though I thought that it would be nice to have a set of card sprites. This makes animating card games much easier.
The code is below (I have rekeyed it so apologies for typos)
image = loadimage("Kenney/boardgames") suits = [ "Clubs", "Diamonds", "Hearts", "Spades" ] array cards[52] getPack() for i = 0 to 52 loop sprite = cards[i] setSpriteLocation(sprite, gWidth() / 2, gHeight() / 2) setSpriteVisibility(sprite, true) valueX = random(200) + 10 // random speed valueY = random(200) + 10 // random speed dirX = 1 if (random(2) == 1) then // random x direction dirX = -1 endif dirY = 1 if (random(2) == 1) then // random y direction dirY = -1 endif setSpriteRotationSpeed(sprite, valueX * dirX) setSpriteSpeed(sprite, { valueX * dirX, valueY * dirY } ) repeat for i = 0 to 500 loop clear() updateSprites() drawSprites() update() repeat function getPack() values = [ [ 0, "2" ], [ 1, "3" ], [ 2, "4" ], [ 3, "5" ], [ 4, "6" ], [ 5, "7" ], [ 6, "8" ], [ 7, "9" ], [ 8, "10" ], [ 12, "A" ], [ 9, "J" ], [ 11, "K" ], [ 10, "Q" ] ] // Sorted alphabetically imageNo = 0 for suitNo = 0 to 4 loop for valueNo = 0 to 13 loop cardNo = suitNo * 13 + values[valueNo][0] sprite = createSprite() cardImage = getImage(imageNo) setSpriteImage(sprite, cardImage) setSpriteVisibility(sprite, false) setSpriteDepth(sprite, cardNo) sprite.value = values[valueNo][1] sprite.suit = suits[suitNo] sprite.imageNo = imageNo cards[cardNo] = sprite imageNo += 1 if imageNo == 39 then // Joker is in middle of the pack imageNo += 1 endif repeat repeat return void function getImage(imageNo) cardImage = createImage(140, 190, false, image_rgb) setDrawTarget(cardImage) drawSheet(image, imageNo + 15, { 0, 0, 140, 190 } ) update() return cardImage
-
I tried to copy Pgm and re-write into Fuze but I got error msg : at line 14 v if (rnd(2) == 1) then....l must have went wrong somewhere...do you have a friend code, and Pgms to share ?.....
-
I've copy pasted the code that was shared, so any typos should be gone now ;)
-
@kendog400 Did you get it working? My friend code is SW-5218-2817-5887
-
OK, thanks !......
-
Shouldn't rnd(2) be random(2)?
-
@Richard Probably. Both versions of the function exist and do exactly the same thing. Random is certainly easier to understand. Rnd is there for historical reasons. I will change it
-
PGM work fine......