Overview
The Memorice main script (memorice.gd) manages a memory card matching game where players flip clam shells to find matching pairs. Features a point system with rewards for matches and penalties for mismatches, audio feedback, floating text effects, and pause functionality.
Script Path: minigames/memorice/scripts/memorice.gd
Extends: Node2D
Signals
Emitted when player wants to return to main menu.
Node References
UI Elements
Game Over Panel
Game Content
Audio
State Variables
Current points. Starts at 100, increases by 100 for matches, decreases by 50 for mismatches. Game ends at 0.
Reference to the first clam selected in a matching attempt.
Reference to the second clam selected in a matching attempt.
Whether the game is currently comparing two selected clams. Blocks further input.
Whether the game has started (intro completed).
Whether the game is currently paused.
Coins earned in current session for display on game over/victory.
Core Functions
Initialization
Sets up the game board and UI.Key Actions:
- Sets window to 480×800 portrait mode
- Shows intro panel
- Blocks all clams until game starts
- Connects button signals
- Configures pause-compatible process modes
- Generates and shuffles game board
- Connects clam signals
Generates the game board with paired clams.Board Composition:
- 10 unique clam types (camaron, zapatilla, lata, gusano, alga, plastico, botella, basura, salmon, perla)
- 2 of each type = 20 clams total
- Arranged in 4×5 grid (4 columns, 5 rows)
- 65px horizontal separation, 60px vertical separation
- Centered on screen with offset (+30, +100)
- Shuffled random positions
Connects the “almeja_abierta” signal from all clam children to _on_almeja_abierta handler.
Game Flow
Starts the game when intro button is pressed.Actions:
- Hides intro panel
- Sets juego_iniciado = true
- Calls mostrar_y_cerrar_inicialmente to preview all clams
Shows all clams briefly at game start so player can memorize positions.Parameters:
almejas(Array): Array of clam nodes
- Block all clams
- Open all clams (play “abrir” animation)
- Wait 5 seconds
- Close all clams
- Unblock all clams (game begins)
Selection & Matching
Called when a clam is opened by the player.Parameters:
almeja(Node): The clam node that was opened
- Ignores if game not started, paused, or comparing
- Plays opening sound
- If first selection: stores reference
- If second selection: stores reference, blocks all clams, calls _verificar_pareja
Checks if the two selected clams match.Match Logic: Compares
primera_seleccion.objeto_id with segunda_seleccion.objeto_idOn Match:- Play acierto sound
- Wait 0.6s, play mas_puntos sound
- Show “+100” green floating text
- Add 100 points
- Wait 0.8s
- Remove both clams from scene
- Check if board is empty (victory condition)
- Play error sound
- Wait 0.4s, play menos_puntos sound
- Show “-50” red floating text
- Subtract 50 points (minimum 0)
- Wait 1.0s
- Close both clams
- Wait 0.8s
- Check if points reached 0 (game over condition)
- Resets selection variables to null
- Sets comparando = false
- Unblocks all clams
Helper Functions
Blocks or unblocks all clams.Parameters:
bloquear(bool): True to block, false to unblockexcept(Array): Clams to exclude from blocking (default: empty)
almeja.bloqueada property for each clamUpdates the points display label.Format: “Puntos: ”
Spawns floating text effect.Parameters:
pos(Vector2): World position for texttexto(String): Text to display (e.g., “+100”, “-50”)color(Color): Text color
End Game Conditions
Displays victory screen when all pairs are matched.Actions:
- Processes coins (calls _procesar_monedas_finales)
- Sets panel title to “¡Ganaste!”
- Shows final score and coins earned
- Makes panel visible
Displays game over screen when points reach 0.Actions:
- Processes coins (calls _procesar_monedas_finales)
- Sets panel title to “¡Fin del Juego!”
- Shows final score and coins earned
- Makes panel visible
Saves score and awards coins via ScoreManager.Logic:
- Saves high score to “memorice” key
- Calculates coins: puntos × 0.5
- Adds coins to player account
- Stores in last_coins_gained for display
Pause System
Pauses the game.Actions:
- Pauses all audio streams
- Blocks all clams
- Sets comparando = true to prevent input
- Shows pause panel with current score
Resumes from pause.Actions:
- Resumes all audio streams
- Unblocks clams if board not empty
- Sets comparando = false
- Hides pause panel
Navigation
Returns to main menu.Actions:
- Resumes game if paused
- Resets screen to portrait orientation
- Changes to main menu scene
Reloads current scene to restart game.
Toggles pause state.
Handles escape key (ui_cancel) to toggle pause.
Clam Scene Requirements
Each clam instance must have:Unique identifier for the object inside the clam (e.g., “camaron”, “lata”).
Whether the clam is currently blocked from interaction.
Whether the clam is currently open.
Sprite that plays open/close animations.
Opens the clam and emits “almeja_abierta” signal.
Closes the clam.
Emitted when clam is opened, passes self as parameter.
Clam Types
The game includes 10 different clam types:almeja_camaron.tscn- Shrimp (food)almeja_zapatilla.tscn- Shoe (trash)almeja_lata.tscn- Can (trash)almeja_gusano.tscn- Worm (bait)almeja_alga.tscn- Seaweed (natural)almeja_plastico.tscn- Plastic (trash)almeja_botella.tscn- Bottle (trash)almeja_basura.tscn- Garbage (trash)almeja_salmon.tscn- Salmon (food)almeja_perla.tscn- Pearl (treasure)
ScoreManager Integration
"memorice"
Coin Conversion: Final puntos × 0.5
Common Patterns
Point System
- Starting Points: 100
- Match Reward: +100
- Mismatch Penalty: -50
- Minimum: 0 (triggers game over)
- Maximum: 1000 (if all matches without mistakes)
Board Layout Calculation
Sequential Audio Feedback
Matches and mismatches use staggered sound effects:Async Clam Operations
Clams close asynchronously to allow animation to complete:The 5-second preview at game start allows players to memorize clam positions, making this a true memory challenge.