It looks like you're new here. If you want to get involved, click one of these buttons!
Necessary spritesheet: https://opengameart.org/content/playing-cards-0
I've tried to code this decently well. I'm not totally happy: The Field.touched(touch) and Field.move functions took me over an hour.. but it went pretty well. It looks a lot better than the first time i did this, I actually commented a lot of everything, it was done in less than 3 hours, and it will fit in your scratchpad
Although, I forgot to program the score hahaha
Oh! Another thing that i forgot to put in is instructions. Basically, you select a card, and then you move it to the left one or three indexes. And if suit or rank matches, that makes a valid move! sorry for not animating it, but I suppose I can work on that. I just got so excited and posted this as soon as it was playable
-- Created by Tommy
-- Second version of this game (first version is messier code, and took me two weeks. This took two and a half hours to make)
-- Note that this requires you to download a single spritesheet for the cards to play the game. i do not rememer where i got it from originally (\_ツ_/) shrugs
-- I named it sheet, but you can rename it in the Field.draw() function, at line 63
displayMode( FULLSCREEN )
function setup()
Deck.setup()
Field.deal()
print(Field[1], "suit "..Field[1]/4, "rank ".. Field[1]/13)
end
function draw()
background(40,40,50,1)
Deck.draw()
Field.draw()
end
function touched(touch)
Deck.touched(touch)
Field.touched(touch)
end
-- Timezone GMT-10 Hawaii Time, Date format follows MM/DD/YYYY
-- Started 4:34 PM 09-02-2017 Saturday
-- Last Modified 7:16 PM 09-02-2017
Deck = {} --52 length array, holds cards in deck
Field = {} --16 length array, holds cards in play
Score = {0,0,0,0,0} --ten thousands, thousands, hundreds, tens, ones places
local numberOfRanks = 13
local numberOfSuits = 4
--[[ ^Cards are represented by number values of 1-52. Rank and suit are determined with modulus 13 and modulus 4, if you change the spritesheet, make sure to change these variables.
]]--
local width, height = 80,112 -- Card Width and Card Height. Note they use a 5:7 ratio, in real cards this would be 2.5" x 3.5"
-- used in Deck.draw, Deck.touched, Field.draw, Field.touched
--[[ If your device screen is too small or you simply don't like the way cards are draw, change the lookup table for positioning cards, has two rows. Feel free to modify
]]--
local position = {
vec2(50,668), vec2(150,668), vec2(250,668), vec2(350,668),
vec2(450,668), vec2(550,668), vec2(650,668), vec2(750,668),
vec2(50,338), vec2(150,338), vec2(250,338), vec2(350,338),
vec2(450,338), vec2(550,338), vec2(650,338), vec2(750,338) }
--positions the deck of cards
local deckposition = vec2(WIDTH-100, 168)
function Deck.setup() --called in setup()
for i = 1, 52 do
Deck[i] = i
end
local j
for i = 52, 2, -1 do
j = math.random(52)
Deck[i], Deck[j] = Deck[j], Deck[i]
end
end
function Field.draw() --called in draw()
local mesh=mesh()
for i,v in ipairs(Field) do --index determines position
local rank = (1/numberOfRanks)*(v % numberOfRanks)
local suit = (1/numberOfSuits)*(v % numberOfSuits)
mesh.texture = "Project:sheet"
mesh:addRect(position[i].x, position[i].y, width, height)
mesh:setRectTex(i, rank, suit, 1/numberOfRanks, 1/numberOfSuits)
end
mesh:draw()
end
function Field.deal() --called in Deck.touched(touch)
if #Field < 16 and #Deck > 0 then
Deck[#Deck], Field[#Field + 1] = nil, Deck[#Deck]
end
end
function Deck.draw() --called in draw()
local mesh = mesh()
mesh:addRect(deckposition.x, deckposition.y, 80, 112)
if #Deck > 0 then
mesh:setColors(0,168,0)
else
mesh:setColors(0)
end
mesh:draw()
end
function Deck.touched(touch) --called in touched(touch)
if touch.x > deckposition.x - width*.5 and touch.x < deckposition.x + width*.5
and touch.y > deckposition.y - height*.5 and touch.y < deckposition.y + height*.5
and touch.state == ENDED then
Field.deal() -- is this bad practice to handle field.deal inside deck.touched?
end
end
--[[ Field.move is the game rules, index1 must be 1 or 3 higher than ind2, and either ranks or suits must be equal. During a move, the card originally at index 2 is elimnated from the game
all other cards will move up
Here's a gamemode idea: Rank up, where cards change ranks based on your moves
]]--
function Field.move(index1, index2) --called in Field.touched(touch)
print "Starting move"
if index1 - index2 ~= 3 and index1 - index2 ~= 1 then
print "Illegal Move: difference between indexes must be equal to 1 or 3"
else
local rank1, suit1 = Field[index1]%numberOfRanks, Field[index1]%numberOfSuits
local rank2, suit2 = Field[index2]%numberOfRanks, Field[index2]%numberOfSuits
if rank1 ~= rank2 and suit1 ~= suit2 then
print "Illegal Move. Either the card suits or the card ranks must match."
else
Field[index2] = Field[index1]
table.remove(Field, index1)
end
end
end
function Field.touched(touch) --called in touched(touch)
-- This function took an hour. Once I threw out this code and started over, it was done in ten minutes
for i,v in ipairs(position) do
if touch.x > v.x - width*.5 and touch.x < v.x + width*.5
and touch.y > v.y - height*.5 and touch.y < v.y + height*.5 then
if touch.state == BEGAN then
index1 = i
break
elseif touch.state == ENDED then
index2 = i
if index1 and index2 and index1 ~= index2 then
Field.move(index1, index2)
end
print(index1, index2)
index1, index2 = nil, nil
break
end
end
end
end
Could someone give me sdvice on making an instructions ofr this game? I've never had to do that before.
Comments
Can you post the entire Sprite sheet as an image instead of a .zip file?
Downloading, extracting, and importing an image from a .zip file is non-trivial for most of us, and involves multiple apps.
On the other hand, an image on a webpage can be imported into the camera roll and then into a Codea project without ever leaving the Codea app.
@UberGoober
Thanks!
I didn't realize what game this was!
This is a solitaire game my uncle taught me and that, in my experience, very few people know. One of the reasons he liked it is that it's a solitaire game you can play without taking up much space--you can actually play the whole game while just holding all the drawn cards in one hand.
Anyway, a nice blast from the past to see this. Nice job. And yeah, you should animate it!
https://github.com/ThomasofHilo/solitare/tree/master/tabs
my ipad was refusing to charge, so i recoded this from scratch on my dads ipad, without the spritesheet, thinking my ipad would die forever (spoiler: it didnt, dirty battery port)
there's no working installer, so its not easy to download and run....I can't figure out how to make a working installer. apparently, its not as simple as just taking the soda installer and putting my url
if you have any knowledge on making a raw downloadable folder in ios, would be nice.
@UberGoober
also: [quote]On the other hand, an image on a webpage can be imported into the camera roll and then into a Codea project without ever leaving the Codea app.[/quote]
are you browsing from inside Codea? lol
@xThomas, yes I'm browsing from inside Codea. Why the lol?
found it funny, I didnt think of doing that.
anyway... Hmm, did you look at the second version (without sprite)? It has implemented dx and dy, but I did it without the sprite so cards are just colors and numbers
I tried the game, all I see is blank white rectangles(16). I loaded the "sheet", but still nothing...I changed line #63 (Documents:sheet).. Two rows of 8 rectangles only come on the screen, with one green rectangle in the lower right corner(the deck)....Please Help ! I'm only interested in card games, and the fourm has very little in this area..
@kendog400 Did you put it in quotes? Try readImage('Documents:sheet')
I have modified this code to not need a spritesheet, and also to have deltaX and deltaY.
I dont think i put the quotes in, I'll try that....
I beleive I found the name of this game. It's Accordion Solitaire
Made some changes to original code incorporating some features of suggested code, used a separate mesh for the deck and added some scoring
I added the three ~~~
PGM says : Card file is read in the Field.draw()....(png file)
--*******************************
mesh.texture = "Documents:sheet" -- The sprite sheet
--*******************************
I tried to make changes but I can't seem to get the sprite sheet to load..
Is this the correct way ?.....
img=readImage(asset.documents.Deck)
I know PGM was written long ago and their may have been changes and updates to codea since then....But looks like a gud PGM, and I would like to get it to work..
I also like the idea of putting in lots of comments, and making it easier to break the PGM down....Any help is greatly appreicated.....
You should be able to tap in the () of img=readImage() and select what you want to read. It will put the correct name format in the ().
pic 01....I got the results of pic4
In the feild draw & Deck draw fx's, pics 3 & 4, shows changes I made...
I see ::mesh.texture = "Documents:CardBack", so I put a
mesh.texture = img....and I got the whole sprite sheet not a card...pic4
I took some freeze frames to show...
I uploaded 2 sprite sheets..if needed...
I found the game interesting and thought I’d try writing another version. The difference with this game is the first card selected replaces the second card selected by tapping the first card, then tapping the second. Another difference is you can go 1 or 3 cards to the left or right. The original only let you go to the left. By going either way, you get a little more strategy on your selection. I also added a score. The game starts with the sum of all the cards, 1-13 for each suit. Ace is 1 and King is 13. As you replace a card, that card value is subtracted from the score. Try to get a low score. I was able to get to 7. The lowest score is 1, but you might never get there. Best played in landscape orientation. To select a card, tap on it. If you make a mistake, tap the same card again.
PS. I was able to get down to a score of 3. The cards, Ace of spades and 2 of hearts were left. If it would have been a 2 of spades, I could have gotten a 1.
Here’s an updated version of the code I wrote earlier. I removed it to save space here. In this version, I added an option using a parameter slider that allows left only moves or the default left and right 1 or 3 position moves. I also added code to enter your name or initials for a high score, in this game, a low score. It will show the lowest 10 scores with name/initials. When the game ends (you can’t make any more moves), tap the Save score button. I leave it up to you to determine when you can’t move anymore. Tap the New game button to enter a new name/initials or continue with the current name. I’ve managed to get a low score of 1, the lowest, but most of the time I’m well above 10. See my farther above post for more instructions.