Overview
TheCard class represents an individual card in Elemental Battlecards. It extends Phaser.GameObjects.Sprite to provide both visual representation and game logic for card behavior, including attack states, leveling up, and face-up/face-down states.
Constructor
The scene to which the card belongs
The initial x position
The initial y position
The card data object containing:
id: Card identifier (e.g., ‘fuego-2’)type: Card type from CardTypeslevel: Card level (1-3)instanceId: Unique instance identifierowner: Player who owns the card
Whether the card starts face down
Card Data Structure
Every card is represented by a data object with the following properties:Unique card definition ID (format:
type-level, e.g., ‘sombra-2’, ‘agua-3’)The elemental type of the card. Valid values:
fuego(Fire)agua(Water)planta(Plant)luz(Light)sombra(Shadow)espiritu(Spirit)
The card’s level (1, 2, or 3). Level affects attack patterns and fusion capabilities.
A unique identifier for this specific card instance, generated using
Phaser.Math.RND.uuid(). This allows tracking the same card across different game zones (hand, field, graveyard).The player ID who owns this card (‘player1’ or ‘player2’)
Properties
Reference to the Phaser scene
Complete card data object
The card’s elemental type
Current level of the card (1-3)
Whether the card is currently face down
Whether the card can attack this turn
Number of turns the card must wait before attacking
Counter for consecutive attacks (used for level 2 cards)
Methods
reveal()
Reveals the card, changing its texture from the back to show the card’s type and level. Once revealed, a card cannot be hidden again.card-{type}-{level} (e.g., card-sombra-3)
levelUp()
Increases the card’s level by 1 (up to a maximum of 3). Updates the texture if the card is already revealed. Used during fusion operations.updateAttackState()
Called at the end of the owner’s turn to update attack counters and availability based on the card’s level and attack rules.- Level 1: Can attack every turn (no restrictions)
- Level 2: Attacks 2 consecutive turns, then rests 1 turn
- Level 3: Attacks 1 turn, then rests 1 turn
registerAttack()
Registers that the card has performed an attack and updates its state accordingly. Must be called after each attack action.- For level 2 cards: Increments
consecutiveAttackscounter - For level 3 cards: Sets
attackCooldownto 1 (must rest next turn) - Automatically calls
updateAttackState()after registering
Phaser GameObject Features
Since Card extendsPhaser.GameObjects.Sprite, it has access to all sprite methods:
Usage Example
Card Definitions
All card definitions are stored in theCardDefinitions object in card-definitions.js. Each card type has 3 levels: