|
Swadge ESP32-S2
2.0.0
APIs to develop for the Magfest Swadge
|
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. | |
| 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.
| successful | Whether the game was completed successfully or failed |
| 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.
| elapsedUs | The time elapsed since the last time this function was called. Use this value to determine when it's time to do things |
| timeRemainingUs | The time left until the game is failed |
| timeScale | The rate that time has been scaled by. elapsedUs and timeRemainingUs have already been scaled by this value. |
| state | The current game state |
| buttonEvts | Button events that have occurred since the last main loop call |
| buttonEvtCount | The number of button events in the buttonEvts array |
| 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.
| x | The x coordinate that should be updated |
| y | The y coordinate that should be updated |
| w | The width of the rectangle to be updated |
| h | The height of the rectangle to be updated |
| up | Update number |
| upNum | Update number denominator |
| 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.