Level Option – Win Criteria

The optional winCriteria level option defines what the game should consider to be a “win” for this level.

{
  "opts": {
    "winCriteria": {
      "type": <WinCriteriaType>
    }
  }
}

Regardless of the win criteria, a level will end when the player reaches the end (ie the final spawned object passes by the player) or they lose all of their lives,

By default, when this option is not specified, the game over modal will show no particular information once the level ends.

WinCriteriaType values #

options: collect-all-coins, reach-end, none

collect-all-coins #

After the level ends, a game over modal indicating how many coins the player has collect is shown with a message like “you collected 8 / 9 (88%) coins!”

reach-end #

If a level ends because the final spawnable object passes by the player, a “congratulations”-type modal is shown. If a level ends because the player lost all of their lives, the default game over modal is shown.

Use this win-criteria for levels focused on avoiding bombs rather than scoring points – a user “wins” if they simply make it past all obstacles without losing all of their lives.

none #

The default game over modal is always shown when the level ends.


Example Level JSON #

collect-all-coins #

{
  "items": [
    {
      "type": "chunk",
      "data": {
        "0" : [ {"key": "c", "gridY": 40} ],
        "10": [ {"key": "c", "gridY": 50} ],
        "20": [ {"key": "c", "gridY": 60} ]
      }
    }
  ],
  "opts": {
    "endPadding": 15,
    "repeat": 2,
    "winCriteria": {"type": "collect-all-coins"}
  }
}

reach-end #

{
  "items": [
    {
      "type": "chunk",
      "data": {
        "0": [
          {
            "key": "bc",
            "missing": [3, 7],
            "maxRandomXOffset": 30
          }
        ],
        "50": [
          {
            "key": "bc",
            "missing": [5, 8],
            "maxRandomXOffset": 30
          }
        ],
        "100": [
          {
            "key": "bc",
            "missing": [6, 10],
            "maxRandomXOffset": 30
          }
        ]
      }
    }
  ],
  "opts": {
    "endPadding": 50,
    "repeat": 2,
    "maxLives": 1,
    "winCriteria": {"type": "reach-end"}
  }
}