Introduction: Card Matching Game in Scratch
Watch the video tutorial here:
- How to make a Card Matching Game in Scratch | Memory skill game in Scratch – Part 1 – Kodex Academy
- How to make a Card Matching Game in Scratch | Memory skill game in Scratch – Part 2 – Kodex Academy
Want to build a fun, interactive game in Scratch that challenges memory and improves logic skills? You’re in the right place!
In this Scratch tutorial, we’ll walk you through how to make a card matching game in Scratch, also known as a memory game or skill game. This is a popular beginner project that introduces essential coding concepts like variables, lists, cloning, custom blocks, and conditional logic — all in a fun and visual way.
By the end of this Part 1, you’ll have:
- A grid of face-down cards displayed using clones
- A randomized set of matching card pairs
- A solid foundation to build the full game logic (which we’ll finish in Part 2)
Whether you’re a student, teacher, or hobbyist, this tutorial is perfect if you’re looking for an easy Scratch game tutorial that teaches real programming skills through a hands-on project.
Let’s get started building your own card matching game in Scratch!
Card Matching Game in Scratch: Step‑by‑Step Coding
Prerequisites: What you need in Scratch before coding
- One blank card costume (rectangle or square) — name sprite “Blank” (or “Card” base)
- A set of image sprites or costumes (e.g. Apple, Ball, Banana, Balloon, Beetle, Butterfly, Cake, Cat, etc.)
- These will become the faces of cards
- Backdrops: one for game play, plus “Game Over” and “Victory” backdrops
Variables & Lists needed
card counter
(global variable) — counts total cards/clonescard suits
(global variable) — how many different image types (pairs) you will usecard list
(global list) — holds the identity values for each card (each clone) in randomized ordercard identity
(sprite‑only / clone‑only variable) — for each clone, what image/type it corresponds to
Custom Blocks (My Blocks)
Make Cards
— responsible for creating the grid of cards (layout + clones)Make List
— responsible for building the list of card identities (pairs, randomized)
1. Setup Sprites & Costumes
- Blank card sprite: Create a blank card (painted rectangle / square), give it a border/outlines as desired. Name this sprite “Blank”.
- Image sprites: Choose your matching image sprites (apple, ball, banana, balloon, beetle, butterfly, cake, cat, etc.), for each one center the image, align it with the blank card (so when over the blank, they align visually), and make sure each has costumes that correspond: first costume blank, next are the images.
- Naming convention: Give each image (costume) a number or identifier (e.g. “1”, “2”, …). In Scratch you may assign costumes labels, or a variable “card identity” to each clone.
2. Backdrops: Stage Scenes
- Choose a plain background (for the game).
- Create additional backdrops for Victory and Game Over states. For example duplicate the blank stage backdrop, then edit it / add text or images to represent victory or game over.
3. Layout: Grid of Cards via Cloning
You want, say, 30 cards in a grid of 6 columns × 5 rows (or whatever layout fits screen). Clone the blank card sprite to make multiple cards instead of manually placing many sprites.
Logic code blocks (pseudocode / Scratch):
when green flag clicked
set [card counter v] to (0)
hide // the original sprite temporarily
set size to (50) % // sets size of cards
switch costume to [Blank v]
create custom block [Make Cards v] // your own block
Inside Make Cards:
define Make Cards
// initial position to top-left (or desired start) e.g.
go to x: (-200) y: (125)
repeat (number of cards) // e.g. 30 cards
change [card counter v] by (1)
create clone of [myself v]
change x by (80) // shift right per card
if x exceeds some threshold then
set x to initial X
change y by (–some vertical spacing) // go to next row
end
end
And for clones:
when I start as a clone
show
set size to (50)
switch costume to [Blank v]
// position as per clone (handled via the Make Cards logic)
This puts all cards face‐down (i.e. blank) in grid form.
4. Variables & Lists: Managing Card Identities & Randomization
You’ll need:
- Variable
card counter
(for all sprites): to count how many cards you have (clones + original). - List
card list
: holds the identity (numbers) of each card in the deck (length equals number of total cards). - Variable
card suits
(or better namedcard type / card identity
): to assign which image goes where.
Logic:
- At start (green flag), delete all entries in
card list
so it starts fresh. - Create the list: for each card type (e.g. 8 types), insert two of each type into the list (so pairs), then shuffle / insert at random positions so that the card types are scattered.
- For each clone (card sprite), assign a card identity variable based on the corresponding item in the shuffled list. This identity tells which image (costume) to show when flipped.
Pseudocode in Scratch terms:
when green flag clicked
delete all of [card list v]
set [card counter v] to (total cards) // e.g. 30
// card suits = number of image types (excluding blank costume), e.g. 8
set [card suits v] to (8)
// build the list
repeat (card suits)
repeat (2) // each image twice
insert (repeat index) at (random (1) to (length of card list) ) of [card list v]
end
end
// optionally continue until length of card list equals card counter
- Then each clone, when created, picks a position in list, retrieves item, and stores it in its own
card identity
variable. This ensures the image tied to that clone is fixed for that game.
5. Putting Together: Main Script Structure (Part‑1)
A high‑level script for the original blank card sprite might look like:
// In “Blank” sprite (which is cloned)
when green flag clicked
set [card counter v] to (0)
hide
set size to (50)
switch costume to [Blank v]
call [Make Cards v]
call [Make List v]
Custom blocks:
- Make Cards: handles layout, cloning, positioning.
- Make List: handles building
card list
, setting card suits, randomization.
In clone script:
when I start as a clone
show
set size to (50)
switch costume to [Blank v] // face down
// We’ll later add “when this clone clicked” to flip the card
6. Summary of What’s Built So Far
By end of Part 1 (Kodex Academy video and this write‑up) you have:
- Sprites & costumes ready (blank + image types).
- Backdrops for play, Game Over, Victory.
- Layout of cards via clones in grid.
- List of card identities built and assigned.
- Variables to keep track of card count, card suits / types.
What remains (for Part 2):
- Flipping the cards when clicked.
- Checking for matches.
- Handling lives / scoring.
- Game over and victory logic.
- Adding visual/sound effects.
Sample Scratch Code Blocks
(This covers Part 1; flipping etc. come in Part -2.)
Since I can’t share actual Scratch project here, I’m giving sample pseudo‑blocks you’d implement. You’ll adapt them in the Scratch editor.
// Variables (global)
card counter // for total clones / cards to display
card suits // number of different image types
card list // list of identities, length = card counter
// Sprite: Blank / Card Sprite
when green flag clicked
set [card counter v] to (30) // e.g. 30 cards = 2 × 15
hide
set size to (50)
switch costume to [Blank v]
call [Make Cards v]
call [Make List v]
define Make Cards
go to x: (-200) y: (125)
set [columns v] to (6) // for grid, e.g., 6 columns
set [rows v] to (5) // e.g., 5 rows
// optional: compute spacing based on size and screen size
repeat (rows)
repeat (columns)
change [card counter v] by (1)
create clone of [myself v]
change x by (80) // adjust
end
change y by (−75) // adjust vertical
set x to (initial X) // reset to leftmost column
end
define Make List
delete all of [card list v]
set [card suits v] to (8)
// for each card type
repeat (card suits)
repeat (2)
insert (repeat index) at (random (1) to (length of [card list v] + 1)) of [card list v]
end
end
// Clone behaviour
when I start as a clone
show
set size to (50)
switch costume to [Blank v]
// Later: when this clone clicked → flip → show appropriate image per card identity
Enhancement Ideas & Features: Code Snippets
Here are sample Scratch‑style pseudocode for a few of the enhancements above.
A) Lives & Score
when green flag clicked
set [Lives v] to (15)
set [Score v] to (0)
when this sprite (clone) clicked
// logic to flip, check for two cards selected
if (this clone’s card_identity = other selected card_identity) then
// match
change [Score v] by (1)
play sound [win v]
// leave both flipped up, or remove them
else
// mismatch
change [Lives v] by (−1)
play sound [fail v]
// flip them back after a short wait
end
if (Lives = 0) then
switch backdrop to [Game Over v]
stop [all v]
end
B) Timer
when green flag clicked
set [Timer v] to (60) // seconds
repeat until <Timer = 0> or <all pairs matched>
wait (1) secs
change [Timer v] by (−1)
end
if <Timer = 0> then
switch backdrop to [Game Over v]
stop [all v]
end
C) Difficulty Selector
// On the stage, have buttons “Easy”, “Medium”, “Hard”
when [Easy button v] clicked
set [card_suits v] to (4)
set [card_counter v] to (8) // 2 × 4
broadcast [New Game v]
when [Medium button v] clicked
set [card_suits v] to (8)
set [card_counter v] to (16) // 2 × 8
broadcast [New Game v]
when [Hard button v] clicked
set [card_suits v] to (12)
set [card_counter v] to (24)
broadcast [New Game v]
when I receive [New Game v]
// rebuild list, layout, etc using the variables above
Other enhancement ideas that can be implemented in the game:
Enhancement | Purpose / Benefit | Sample Implementation |
---|---|---|
Sound Effects | Feedback for correct/incorrect matches. More game‑feel. | Use sound blocks: play sound [pop v] until done on flip; play sound [win] on match; play sound [fail] on mismatch. |
Animations / Effects on Flip | Smoother transitions. Better UX. | Use glide or change size or ghost effects. E.g. when flipping, change size in two steps to simulate flip, or use change color effect . |
High Score Saving | Incentivizes improvement. | Use Scratch cloud variables (if available) to save highest score. On game end, compare current score to cloud high score; update if higher. |
Hints / Peek Feature | Helps users if stuck. Improves usability. | Add a button or broadcast message that when pressed briefly flips a few random pairs for 2 seconds as hint, then flips back. Use clones, show costumes, wait, then flip back to blank. |
Shuffle on Replay | Ensures new layout each time so game remains fresh. | On “Play Again” or on when green flag clicked , rebuild card list with random insertion, reassign card identities, and reposition clones. |
Responsive Layout / Scalable Grid | Supports different screen sizes or numbers of cards. | Compute grid columns & rows based on card counter or user selection; compute x/y positions accordingly. Variables like card_size , spacing_x , spacing_y . |
Common Errors & Troubleshooting Tips
- Make sure you align images and blank card costumes so when you flip, the image doesn’t look off‑centre.
- If the number of cards is odd, you’ll end up with a non‑paired card: always make
card counter
even,card suits
× 2 ≤card counter
. - Clones: be careful how you assign identity — you need a consistent way to map each clone to one item in the
card list
. - Delay timing: when two cards are flipped and they don’t match, include a small delay (
wait
) so player sees the second one before it flips back. - Avoid running duplicate scripts in clones that conflict; for example, a clone should only react to clicks when it’s face down and fewer than two cards are flipped.
Conclusion: Memory Skill Game in Scratch
Congratulations! 🎉 You’ve just built the entire foundation of a fun and interactive card matching game in Scratch.
In this first part, you learned how to:
- Set up a blank card and image sprites
- Use cloning to create a dynamic grid of cards
- Create and randomize a list of matching pairs
- Assign unique identities to each card
- Prepare variables and layout logic to power the full game
This is an excellent beginner project that introduces critical coding concepts in Scratch like variables, lists, loops, cloning, and custom blocks. You now have all the tools needed to take the next step: flipping cards, detecting matches, scoring points, and adding game-over/victory logic — which we’ll cover in Part 2.
What’s Next?
In Part 2 of this Scratch tutorial, we’ll cover:
- How to flip cards on click
- How to detect a match or mismatch
- Add score, lives, and win/loss conditions
- Add animations and sound effects to make it more engaging
- End game with Victory or Game Over screens
Call to Action
- Don’t forget to check out the full video tutorial: How to make a Card Matching Game in Scratch | Memory skill game in Scratch – Part 1 – Kodex Academy
- Like, comment & share the video
- Visit kodexacademy.com
- subscribe to the Kodex Academy YouTube channel for deeper Scratch content.
Happy coding with Kodex Academy! 🚀
Learn More with Kodex Academy
At Kodex Academy, we’re passionate about helping students learn coding in creative ways. This project teaches more than Scratch—it empowers young minds to build tools that work in the real world.
Explore more:
Stay updated with new content, free tutorials, and coding challenges!
- 🌐 Website: https://kodexacademy.com
- 🌐 Website: https://games.kodexacademy.com
- 💬 WhatsApp Channel: Join Now
- 💼 LinkedIn: Kodex Academy
- 📸 Instagram: @kodex_academy
- 𝕏 Twitter: @Kodex_Academy
- 📢 Telegram: Join Our Channel
- 🔗 Patreon: patreon.com/KodexAcademy
Further Reading & Links
- Scratch Wiki Motion Blocks: https://en.scratch-wiki.info/wiki/Motion_Blocks
- Scratch Programming for Beginners: https://scratch.mit.edu/projects/editor
- Scratch Animation Guide: https://en.scratch-wiki.info/wiki/Animating