-- Random Card
displayMode(FULLSCREEN)
supportedOrientations(LANDSCAPE_ANY)
function setup()
rectMode(CENTER)
t=ElapsedTime+.7
suit={"??","??","??","??"}
u={" 2"," 3"," 4"," 5"," 6"," 7"," 8"," 9","10"," J"," Q"," K"," A"}
deck={} -- Table for the cards
createDeck() -- Goto createDeck
getCard=true -- Show the first card
cc = 52 -- Keep count of the Cards
end
function draw()
-- Background color
background(31, 34, 97, 255)
if getCard then --card is showing
getCard=false
randomCard() --Goto the random card fx
c=v%13+1 --The card value
s=math.ceil(v/13)
end
-- This is the white card background
fill(255)
rect(WIDTH/2,HEIGHT/2,350,500) --This is the WHT rectangle, location & Size
-- Font & font size of the suit & value
font("AmericanTypewriter-Bold")
fontSize(160) --size of suit font
--This is the card suit being printed to the screen
text(suit[s],WIDTH/2,HEIGHT/2) --Smack dab in the middle
-- This is the different colors of the suits
if s==1 then --spades
fill(0, 0, 0, 255)
elseif
s==2 then --clubs
fill(0, 0, 0, 255)
elseif
s==3 then --hearts
fill(255, 0, 0, 255)
elseif
s==4 then --cdia onds
fill(255, 0, 31, 255)
end
-- This is the card value
text(u[c],WIDTH/2-85,HEIGHT/2+170)
rotate(180) --The next number will be rotated 180 degrees
text(u[c],WIDTH/2-1110,HEIGHT/2-600) --When rotating the number has to be adjusted
rotate(180) --Aftre the rtation, rotate back 180
-- Plain text
font("Baskerville-BoldItalic")
fontSize(60)
fill(255, 255, 255, 255)
text(str, WIDTH/2,HEIGHT-60)
-- Card count, this is being constantly updated
font("Baskerville-BoldItalic")
fontSize(50)
fill(255, 255, 255, 255)
text(cc, WIDTH-875,HEIGHT/2)
-- Plain text
font("Copperplate-Bold")
fontSize(50)
fill(255, 255, 255, 255)
text("Cards left\
in Deck :", WIDTH-855,HEIGHT/2+80)
if ElapsedTime>t then
sound("Game Sounds One:Bell 2")
getCard=true
t=ElapsedTime+.7
if cc==1 then
setup()
end
end
end
function createDeck()
str = "Cards"
for z=1,52 do
deck[z]=z
end
end
function randomCard()
-- This plucks a random card then subtracts it from the Main deck
if #deck>0 then --if there are any cards left in the deck, then pluck
d=math.random(#deck) --pluck at random
v=deck[d]
table.remove(deck,d) --after being plucked, remove it from the deck
else
str = "End of Deck"
end
-- This keeps track of the amount of cards left in the deck
if cc <= 52 then --cc means card-count
cc = cc - 1
end
end
Remove this code to stop picking a new card every second. You didn’t say how you want to select the next card or what you wanted to do by creating the loop of selecting cards. Just a suggestion, programs run exactly as you code them to run, not exactly as you want them to run.
if ElapsedTime>t then
sound("Game Sounds One:Bell 2")
getCard=true
t=ElapsedTime+.7
if cc==1 then
setup()
end
end
…
There’s no delay because draw runs at 60 FPS. You delay things in draw by executing something every so many draw cycles. In the ElapsedTime if statement, increase the .7 to a larger value to slow the deal speed.
…
Just a quick question ; what does the ‘%’ sign stand for ? What does the ‘//’ double slash stand for ?..table.insert(deck,v[z%13+1]…s[z//13+1])…
@kendog400 See if this fits any better. If it doesn’t, then in the draw function change the values in the text statement. Change the 120, 80, 40, or 30 values to different values and see how they alter the display on your phone. As for the % and //, the % is a mod division. It give you just the remainder of a divide. The // is an integer division. It gives you the whole number of a division, dropping anything after the decimal point.
--Deck to Screen
displayMode(FULLSCREEN)
function setup()
s={" ??"," ??"," ??"," ??"}
v={" 2"," 3"," 4"," 5"," 6"," 7"," 8"," 9","10"," J"," Q"," K"," A"}
deck={}
for z=0,51 do
table.insert(deck,v[z%13+1]..s[z//13+1])
end
end
function draw()
background(10, 26, 223)
fontSize(30)
fill(255, 255, 255)
text("Tap screen to shuffle",WIDTH/2,HEIGHT-50)
for z=0,51 do
text(deck[z+1],WIDTH/2-120+(z//13)*80,40+(z%13)*30)
end
end
function shuffle()
for q=1,100 do
a,b=math.random(52),math.random(52)
deck[a],deck[b]=deck[b],deck[a]
end
end
function touched(t)
if t.state==BEGAN then
shuffle()
end
end
…
The draw function runs at 60 frames per second. You’re not supposed to stop it. If you do, then nothing is drawn on the screen.
Is there a pause fx() ? Or some tutorial / dusscion on pauseing ?
You don’t pause the code. The only thing you should do is to write code so you don’t execute the code that update something. Here’s a simple example of pausing the count and sprite movement.
displayMode(FULLSCREEN)
function setup()
fill(255)
count=0
xx=0
x,y=200,200
end
function draw()
background(0)
text("tap screen to pause / unpause",WIDTH/2,HEIGHT-100)
text("count = "..count,WIDTH/2,HEIGHT/2)
sprite(asset.builtin.Planet_Cute.Character_Horn_Girl,x,y)
-- this increments the count value and the sprites x,y position.
-- when you want to pause the count and sprite position,
-- you just dont update their values.
if xx==0 then
count=count+1
x=(x+3)%WIDTH
y=(y+3)%HEIGHT
end
end
function touched(t)
if t.state==BEGAN then
if xx==1 then
xx=0 -- set to 0 to update values
else
xx=1 -- set to 1 to skip the update code
end
end
end
A…
Comment out the code I show below starting with if cc==1 then
if ElapsedTime>t then
sound("Game Sounds One:Bell 2")
getCard=true
t=ElapsedTime+.7
--if cc==1 then
--setup()
--end
end
end
Then change the code I show below starting with if cc> 0 then
function randomCard()
-- This plucks a random card then subtracts it from the Main deck
if #deck>0 then --if there are any cards left in the deck, then pluck
d=math.random(#deck) --pluck at random
v=deck[d]
table.remove(deck,d) --after being plucked, remove it from the deck
else
str = "End of Deck"
end
-- This keeps track of the amount of cards left in the deck
if cc>0 then
--if cc <= 52 then --cc means card-count
cc = cc - 1
end
end
Thanks…
…
Make this change. Add cc>0 to the if statement.
if ElapsedTime>t and cc>0 then
sound("Game Sounds One:Bell 2")
getCard=true
t=ElapsedTime+.7
end
end
…
It looks like I goofed somewhere, I was trying to deal 4 cards, 2 to each player by way of the for loops, but I made a mess…