Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    52 Card Pick Up

    General Discussion
    4
    8
    424
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • pianofire
      pianofire Fuze Team last edited by pianofire

      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
      
      1 Reply Last reply Reply Quote 3
      • K
        kendog400 F last edited by

        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 ?.....

        pianofire 1 Reply Last reply Reply Quote 1
        • M
          MikeDX last edited by

          I've copy pasted the code that was shared, so any typos should be gone now ;)

          1 Reply Last reply Reply Quote 1
          • pianofire
            pianofire Fuze Team @kendog400 last edited by

            @kendog400 Did you get it working? My friend code is SW-5218-2817-5887

            1 Reply Last reply Reply Quote 0
            • K
              kendog400 F last edited by

              OK, thanks !......

              1 Reply Last reply Reply Quote 2
              • R
                Richard F last edited by

                Shouldn't rnd(2) be random(2)?

                pianofire 1 Reply Last reply Reply Quote 0
                • pianofire
                  pianofire Fuze Team @Richard last edited by

                  @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

                  1 Reply Last reply Reply Quote 0
                  • K
                    kendog400 F last edited by

                    PGM work fine......

                    1 Reply Last reply Reply Quote 2
                    • First post
                      Last post