Swadge ESP32-S2  2.0.0
APIs to develop for the Magfest Swadge
Loading...
Searching...
No Matches
cosCrunchMicrogame_t Struct Reference

Detailed Description

The definition for a Cosplay Crunch microgame. Once your microgame is built, add this struct to the microgames[] array in cosCrunch.c to include it in the randomized rotation. While developing a microgame, you can set the DEV_MODE_MICROGAME define to your microgame to play only yours on repeat.

#include <cosCrunch.h>

Data Fields

const char * verb
 The phrase that is flashed on the screen before the microgame runs. Should be an action: "Sew", "Glue", "Try not to cry", etc.
const char * successMsg
 The phrase that is flashed on the screen after the microgame if the game was succeeded. This can be NULL if you'd rather congratulate the player in a different manner.
const char * failureMsg
 The phrase that is flashed on the screen after the microgame if the game was failed. This can be NULL if you'd rather taunt the player in a different manner.
uint64_t timeoutUs
 How long the player has until they fail the microgame, in microseconds.
uint64_t resultDisplayTimeUs
 How long the celebrating and despairing screens are displayed, in microseconds. Defaults to MICROGAME_RESULT_DISPLAY_TIME_US defined in cosCrunch.c if unspecified.
void(* fnInitMicrogame )(void)
 This function is called when this microgame is about to be started. It should initialize variables and load assets.
void(* fnDestroyMicrogame )(bool successful)
 This function is called when the microgame is exited. It should free any allocated memory.
void(* fnMainLoop )(int64_t elapsedUs, uint64_t timeRemainingUs, float timeScale, cosCrunchMicrogameState state, buttonEvt_t buttonEvts[], uint8_t buttonEvtCount)
 This function is called from the main loop. The microgame should run its game logic and render like a mode would. This function should NOT call checkButtonQueueWrapper() like a mode would: it will receive all button events as an argument.
void(* fnBackgroundDrawCallback )(int16_t x, int16_t y, int16_t w, int16_t h, int16_t up, int16_t upNum)
 This function is called when the display driver wishes to update a section of the display. Implementing this function in your microgame is optional and will cause the Cosplay Crunch UI to render over it in the foreground. If you do not implement this function, your game will render on top of the cutting mat background.
bool(* fnMicrogameTimeout )(void)
 This function is called when the microgame timer expires. It is optional and intended for microgames that need to determine their success condition at the end of the game. If you implement this function, you can still call cosCrunchMicrogameResult() at any time to complete the game early.

Field Documentation

◆ verb

const char* verb

The phrase that is flashed on the screen before the microgame runs. Should be an action: "Sew", "Glue", "Try not to cry", etc.

◆ successMsg

const char* successMsg

The phrase that is flashed on the screen after the microgame if the game was succeeded. This can be NULL if you'd rather congratulate the player in a different manner.

◆ failureMsg

const char* failureMsg

The phrase that is flashed on the screen after the microgame if the game was failed. This can be NULL if you'd rather taunt the player in a different manner.

◆ timeoutUs

uint64_t timeoutUs

How long the player has until they fail the microgame, in microseconds.

◆ resultDisplayTimeUs

uint64_t resultDisplayTimeUs

How long the celebrating and despairing screens are displayed, in microseconds. Defaults to MICROGAME_RESULT_DISPLAY_TIME_US defined in cosCrunch.c if unspecified.

◆ fnInitMicrogame

void(* fnInitMicrogame) (void)

This function is called when this microgame is about to be started. It should initialize variables and load assets.

◆ fnDestroyMicrogame

void(* fnDestroyMicrogame) (bool successful)

This function is called when the microgame is exited. It should free any allocated memory.

Parameters
successfulWhether the game was completed successfully or failed

◆ fnMainLoop

void(* fnMainLoop) (int64_t elapsedUs, uint64_t timeRemainingUs, float timeScale, cosCrunchMicrogameState state, buttonEvt_t buttonEvts[], uint8_t buttonEvtCount)

This function is called from the main loop. The microgame should run its game logic and render like a mode would. This function should NOT call checkButtonQueueWrapper() like a mode would: it will receive all button events as an argument.

Parameters
elapsedUsThe time elapsed since the last time this function was called. Use this value to determine when it's time to do things
timeRemainingUsThe time left until the game is failed
timeScaleThe rate that time has been scaled by. elapsedUs and timeRemainingUs have already been scaled by this value.
stateThe current game state
buttonEvtsButton events that have occurred since the last main loop call
buttonEvtCountThe number of button events in the buttonEvts array

◆ fnBackgroundDrawCallback

void(* fnBackgroundDrawCallback) (int16_t x, int16_t y, int16_t w, int16_t h, int16_t up, int16_t upNum)

This function is called when the display driver wishes to update a section of the display. Implementing this function in your microgame is optional and will cause the Cosplay Crunch UI to render over it in the foreground. If you do not implement this function, your game will render on top of the cutting mat background.

Note that your microgame will not receive this callback for the entire screen: any pixels at the bottom of the display that are covered up by the Cosplay Crunch UI will be skipped.

Parameters
xThe x coordinate that should be updated
yThe y coordinate that should be updated
wThe width of the rectangle to be updated
hThe height of the rectangle to be updated
upUpdate number
upNumUpdate number denominator

◆ fnMicrogameTimeout

bool(* fnMicrogameTimeout) (void)

This function is called when the microgame timer expires. It is optional and intended for microgames that need to determine their success condition at the end of the game. If you implement this function, you can still call cosCrunchMicrogameResult() at any time to complete the game early.

Returns
true if the microgame was completed successfully, false if it was failed

The documentation for this struct was generated from the following file: