Voxel Game Maker

Docs Quick code

Card battles

Start a card fight from code in any game, read how it ended, change the player's deck and gold, and hear the run's events.

Game Settings ▸ Cards holds a game's cards, foes and fights (see the manual's settings page). With The game is a card run on, the whole game is a deckbuilder run and needs no code. Code can start a fight in any game, and change the deck:

Function Gives
battle(foes, place = "") Starts a card fight against a foe or a list of foes, staged on the object called place (empty = where the player stands). false if one is on.
battle_on() true while a card fight is on.
battle_result() How the last fight ended: "won", "lost" or "".
deck() The player's deck: a list of card names (upgraded ones end in +).
deck_add(card, upgraded = false) Adds a card to the deck.
deck_remove(card) Takes one copy of a card out of the deck.
gold() The player's gold.
give_gold(n) Gives gold (negative takes it).
run_floor() The run map's floor the player is on (1 = the first).
energy() The player's energy left this turn in a fight.

Events for on(event, fn): battle_start (the foes' names), battle_won and battle_lost (the fight's kind: fight, hard, elite or boss), card_played (the card's name) and room (the kind of room picked on the run map). HUDs show {card_gold}, {card_floor}, {card_deck} and {card_energy}.

#A duel with a skeleton

-- On a skeleton's Script (When used): a card duel on the arena's circle.
popup("Draw your cards, stranger!")
battle({"Skeleton", "Skeleton"}, "Arena circle")
wait_until(function() return not battle_on() end)
if battle_result() == "won" then
  give_gold(30)
  deck_add("Bone shield")
  popup("You won a new card: Bone shield!")
end

#A bonus after elites

on("battle_won", function(kind)
  if kind == "elite" then
    give_gold(25)
    popup("25 extra gold!")
  end
end)