Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

A deck of standard playing cards.

2»

Comments

  • Posts: 61

    Thanks again Ignatz but you have taken quite a big step for my simple mind. #:-S
    Not sure what you mean by 'hard coding' and I need to take a look at sprite(TableOfSprites[n],x,y) before moving any further. My game 'Kings High' will require the use of Sprites if I am to use 'Proper Cards'

  • IgnatzIgnatz Mod
    Posts: 5,396

    I mean, don't include specific pixel positions when drawing sprites in draw, ie don't write sprite(someCard, 50+x*75,10+y*60)

    Rather define all those numbers as variables in setup, and use the variables to draw the sprites. Then it's easy to change the code.

  • Posts: 61

    Message received and understood. L-)

  • dave1707dave1707 Mod
    edited March 2015 Posts: 9,731

    @Steep I know you're not to this point yet, but I thought I would give you a peek of where you're headed. You can look this over in more detail whenever you want to see what you might need in your code.


    displayMode(FULLSCREEN) supportedOrientations(PORTRAIT_ANY) function setup() rectMode(CENTER) img={} msg="Tap screen to deal a card." card=0 tab = {} -- numbers for random cards for no = 1,52 do table.insert(tab,no) end tab2={} -- card on screen x1 = 120 y1 = 900 fontSize(48) end function draw() background(0) fill(255,0,0) rect(WIDTH/2,100,60,80) -- draw back of card for draw fill(255) text(msg,WIDTH/2,200) -- draw deal message for a,b in pairs(tab2) do -- draw cards on the screen sprite(img[a],b.y,b.z) end if card>0 then sprite(str,c.x,c.y) -- draw moving card end end function touched(t) if t.state==BEGAN and #tab>0 and card==0 then n=math.random(#tab) -- random number from 1 to table size card=tab[n] -- get card number from table table.remove(tab,n) -- remove that number from the table str=string.format("Documents:card%02d",card) -- format card table.insert(img,str) -- insert card image in table x1=x1+100 -- calculate x,y position for card if x1>520 then y1=y1-50 x1=220 end moveCard() -- call the tween routine to move card end end function moveCard() c={x=WIDTH/2,y=100} -- starting card position tween(1,c,{x=x1,y=y1},tween.easing.linear,moveDone) -- start tween msg="" -- card moving, clear message string end function moveDone() table.insert(tab2,vec3(card,c.x,c.y)) -- put card in position table card=0 -- set card number to 0 msg="Tap screen to deal a card." -- card stopped, set message string if #tab==0 then msg="End of deck." end end
  • Posts: 61

    Dave, that's brilliant. It will greatly speed up my learning curve. I see that you, like Ignatz, move on to vectors for locating the cards, no doubt to give that smooth movement from Deck to Stack. We now have a shuffled deck displayed to show the complete shuffled Deck. In my game the deal has to be 4 cards, one to each column, when necessary and the game will require 4 tables, one for each column to record the location of cards throughout the game. My next move would be to limit the 'Touch to deal' area to the red rectangle that represents the Deck.

Sign In or Register to comment.