Skip to content

Commit

Permalink
Merge pull request #332 from AEFeinstein/sokobokobanaban
Browse files Browse the repository at this point in the history
Sokobokobanaban Instructions
  • Loading branch information
hunterdyar authored Dec 6, 2024
2 parents 8ebd8e1 + 5cf38b5 commit c0a1aa4
Show file tree
Hide file tree
Showing 13 changed files with 334 additions and 25 deletions.
23 changes: 12 additions & 11 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ idf_component_register(SRCS "asset_loaders/common/heatshrink_encoder.c"
"modes/games/bigbug/soundManager_bigbug.c"
"modes/games/bigbug/tilemap_bigbug.c"
"modes/games/bigbug/worldGen_bigbug.c"
"modes/games/cGrove/cg_Chowa.c"
"modes/games/cGrove/cg_Items.c"
"modes/games/cGrove/Garden/cg_GroveAI.c"
"modes/games/cGrove/Garden/cg_Grove.c"
"modes/games/cGrove/Garden/cg_GroveDraw.c"
"modes/games/cGrove/Garden/cg_GroveItems.c"
"modes/games/cGrove/mode_cGrove.c"
"modes/games/cGrove/Sparring/cg_Match.c"
"modes/games/cGrove/Sparring/cg_Spar.c"
"modes/games/cGrove/Sparring/cg_SparDraw.c"
"modes/games/pango/paEntity.c"
"modes/games/pango/paEntityManager.c"
"modes/games/pango/paGameData.c"
Expand All @@ -47,6 +57,7 @@ idf_component_register(SRCS "asset_loaders/common/heatshrink_encoder.c"
"modes/games/soko/soko.c"
"modes/games/soko/soko_game.c"
"modes/games/soko/soko_gamerules.c"
"modes/games/soko/sokoHelp.c"
"modes/games/soko/soko_input.c"
"modes/games/soko/soko_save.c"
"modes/games/soko/soko_undo.c"
Expand All @@ -61,21 +72,11 @@ idf_component_register(SRCS "asset_loaders/common/heatshrink_encoder.c"
"modes/games/ultimateTTT/ultimateTTTmarkerSelect.c"
"modes/games/ultimateTTT/ultimateTTTp2p.c"
"modes/games/ultimateTTT/ultimateTTTresult.c"
"modes/games/cGrove/mode_cGrove.c"
"modes/games/cGrove/cg_Chowa.c"
"modes/games/cGrove/cg_Items.c"
"modes/games/cGrove/Garden/cg_Grove.c"
"modes/games/cGrove/Garden/cg_GroveAI.c"
"modes/games/cGrove/Garden/cg_GroveDraw.c"
"modes/games/cGrove/Garden/cg_GroveItems.c"
"modes/games/cGrove/Sparring/cg_Match.c"
"modes/games/cGrove/Sparring/cg_Spar.c"
"modes/games/cGrove/Sparring/cg_SparDraw.c"
"modes/music/colorchord/colorchord.c"
"modes/music/jukebox/jukebox.c"
"modes/music/sequencer/sequencerGrid.c"
"modes/music/sequencer/sequencerHelp.c"
"modes/music/sequencer/sequencerMode.c"
"modes/music/sequencer/sequencerGrid.c"
"modes/music/tunernome/tunernome.c"
"modes/music/usbsynth/mode_synth.c"
"modes/system/credits/credits_utils.c"
Expand Down
27 changes: 21 additions & 6 deletions main/menu/menuManiaRenderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ menuManiaRenderer_t* initMenuManiaRenderer(font_t* titleFont, font_t* titleFontO
ringDir = (ringDir == 1) ? -1 : 1;
ring->color = ringColors[i];
}
renderer->drawRings = true;

// LEDs on by default
renderer->ledsOn = true;
Expand Down Expand Up @@ -476,13 +477,16 @@ void drawMenuMania(menu_t* menu, menuManiaRenderer_t* renderer, int64_t elapsedU
// Clear the background
fillDisplayArea(0, 0, TFT_WIDTH, TFT_HEIGHT, renderer->bgColor);

// Draw the rings
for (int16_t i = 0; i < ARRAY_SIZE(renderer->rings); i++)
if (renderer->drawRings)
{
maniaRing_t* ring = &renderer->rings[i];
int16_t ringRadius = (MIN_RING_RADIUS + MAX_RING_RADIUS) / 2
+ (((MAX_RING_RADIUS - MIN_RING_RADIUS) * getSin1024(ring->diameterAngle)) / 1024);
drawManiaRing(ringRadius, ring->orbitAngle, ring->color, renderer->bgColor);
// Draw the rings
for (int16_t i = 0; i < ARRAY_SIZE(renderer->rings); i++)
{
maniaRing_t* ring = &renderer->rings[i];
int16_t ringRadius = (MIN_RING_RADIUS + MAX_RING_RADIUS) / 2
+ (((MAX_RING_RADIUS - MIN_RING_RADIUS) * getSin1024(ring->diameterAngle)) / 1024);
drawManiaRing(ringRadius, ring->orbitAngle, ring->color, renderer->bgColor);
}
}

// Find the start of the 'page'
Expand Down Expand Up @@ -651,6 +655,17 @@ void setManiaLedsOn(menuManiaRenderer_t* renderer, bool ledsOn)
}
}

/**
* @brief Set if the rings should be drawn
*
* @param renderer The renderer to set
* @param ringsOn true to draw rings, false to not
*/
void setManiaDrawRings(menuManiaRenderer_t* renderer, bool ringsOn)
{
renderer->drawRings = ringsOn;
}

/**
* @brief Recolor a menu renderer
*
Expand Down
2 changes: 2 additions & 0 deletions main/menu/menuManiaRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ typedef struct
wsg_t batt[4]; ///< Images for the battery levels

maniaRing_t rings[2];
bool drawRings;

int32_t ledDecayTimer; ///< Timer to decay LEDs
int32_t ledExciteTimer; ///< Timer to excite LEDs
Expand Down Expand Up @@ -101,6 +102,7 @@ menuManiaRenderer_t* initMenuManiaRenderer(font_t* titleFont, font_t* titleFontO
void deinitMenuManiaRenderer(menuManiaRenderer_t* renderer);
void drawMenuMania(menu_t* menu, menuManiaRenderer_t* renderer, int64_t elapsedUs);
void setManiaLedsOn(menuManiaRenderer_t* renderer, bool ledsOn);
void setManiaDrawRings(menuManiaRenderer_t* renderer, bool ringsOn);
void recolorMenuManiaRenderer(menuManiaRenderer_t* renderer, paletteColor_t titleBgColor, paletteColor_t titleTextColor,
paletteColor_t textOutlineColor, paletteColor_t bgColor, paletteColor_t outerRingColor,
paletteColor_t innerRingColor, paletteColor_t rowColor, paletteColor_t rowTextColor,
Expand Down
77 changes: 73 additions & 4 deletions main/modes/games/soko/soko.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "soko_game.h"
#include "soko_gamerules.h"
#include "soko_save.h"
#include "sokoHelp.h"
#include "mainMenu.h"

static void sokoMainLoop(int64_t elapsedUs);
static void sokoEnterMode(void);
Expand All @@ -15,7 +17,10 @@ static void sokoExtractLevelNamesAndIndices(soko_abs_t* self);
// strings
const char sokoModeName[] = "Hunter's Puzzles";
static const char sokoPlayGameLabel[] = "Play";
const char SOKO_TAG[] = "SB";
static const char sokoHelpLabel[] = "Instructions";
static const char sokoExitLabel[] = "Exit";

const char SOKO_TAG[] = "SB";

extern const char key_sk_overworldPos[];

Expand Down Expand Up @@ -44,7 +49,13 @@ static void sokoEnterMode(void)
{
soko = heap_caps_calloc(1, sizeof(soko_abs_t), MALLOC_CAP_SPIRAM);
// Load a font
loadFont("ibm_vga8.font", &soko->ibm, false);
loadFont("ibm_vga8.font", &soko->ibm, true);
loadFont("rodin_eb.font", &soko->font_rodin, true);
makeOutlineFont(&soko->font_rodin, &soko->font_rodin_outline, true);
loadFont("righteous_150.font", &soko->font_righteous, true);
makeOutlineFont(&soko->font_righteous, &soko->font_righteous_outline, true);

soko->allSolved = false;

soko->allSolved = false;

Expand Down Expand Up @@ -106,15 +117,35 @@ static void sokoEnterMode(void)
soko->eulerTheme.altFloorColor = c433; // painted tiles color.

// Initialize the menu
soko->menu = initMenu(sokoModeName, sokoMenuCb);
soko->menuManiaRenderer = initMenuManiaRenderer(NULL, NULL, NULL);
soko->menu = initMenu(sokoModeName, sokoMenuCb);
soko->bgMenu = initMenu(sokoModeName, NULL);
soko->menuManiaRenderer
= initMenuManiaRenderer(&soko->font_righteous, &soko->font_righteous_outline, &soko->font_rodin);

// Color the menu
led_t menuColor = {
.r = 0xFF,
.g = 0xCC,
.b = 0x00,
};
static const paletteColor_t shadowColors[] = {c103, c213, c224, c334, c445, c555, c445, c334, c224, c213};
recolorMenuManiaRenderer(soko->menuManiaRenderer, //
c401, c554, c522, // titleBgColor, titleTextColor, textOutlineColor
c444, // bgColor
c433, c334, // outerRingColor, innerRingColor
c111, c555, // rowColor, rowTextColor
shadowColors, ARRAY_SIZE(shadowColors), menuColor);

// addSingleItemToMenu(soko->menu, sokoResumeGameLabel);
addSingleItemToMenu(soko->menu, sokoPlayGameLabel);
addSingleItemToMenu(soko->menu, sokoHelpLabel);
addSingleItemToMenu(soko->menu, sokoExitLabel);

// Set the mode to menu mode
soko->screen = SOKO_MENU;
soko->state = SKS_INIT;
setManiaLedsOn(soko->menuManiaRenderer, true);
setManiaDrawRings(soko->menuManiaRenderer, true);

// load up the level list.
soko->levelFileText = loadTxt("SK_LEVEL_LIST.txt", true);
Expand All @@ -135,10 +166,15 @@ static void sokoExitMode(void)
}
// Deinitialize the menu
deinitMenu(soko->menu);
deinitMenu(soko->bgMenu);
deinitMenuManiaRenderer(soko->menuManiaRenderer);

// Free the font
freeFont(&soko->ibm);
freeFont(&soko->font_rodin);
freeFont(&soko->font_rodin_outline);
freeFont(&soko->font_righteous);
freeFont(&soko->font_righteous_outline);

// free the level name file
freeTxt(soko->levelFileText);
Expand Down Expand Up @@ -193,6 +229,17 @@ static void sokoMenuCb(const char* label, bool selected, uint32_t settingVal)
sokoInitGameBin(soko);
soko->screen = SOKO_LEVELPLAY;
}
else if (sokoHelpLabel == label)
{
soko->helpIdx = 0;
soko->screen = SOKO_HELP;
setManiaLedsOn(soko->menuManiaRenderer, false);
setManiaDrawRings(soko->menuManiaRenderer, false);
}
else if (sokoExitLabel == label)
{
switchToSwadgeMode(&mainMenuMode);
}
}
}

Expand All @@ -217,6 +264,10 @@ static void sokoMainLoop(int64_t elapsedUs)
}
case SOKO_LEVELPLAY:
{
// Turn LEDs off
led_t offLeds[CONFIG_NUM_LEDS] = {0};
setLeds(offLeds, CONFIG_NUM_LEDS);

// pass along to other gameplay, in other file
// Always process button events, regardless of control scheme, so the main menu button can be captured
buttonEvt_t evt = {0};
Expand All @@ -236,11 +287,29 @@ static void sokoMainLoop(int64_t elapsedUs)
}
case SOKO_LOADNEWLEVEL:
{
// Turn LEDs off
led_t offLeds[CONFIG_NUM_LEDS] = {0};
setLeds(offLeds, CONFIG_NUM_LEDS);

sokoLoadGameplay(soko, soko->loadNewLevelIndex, soko->loadNewLevelFlag);
sokoInitNewLevel(soko, soko->currentLevel.gameMode);
ESP_LOGD(SOKO_TAG, "Go to gameplay");
soko->loadNewLevelFlag = false; // reset flag.
soko->screen = SOKO_LEVELPLAY;
break;
}
case SOKO_HELP:
{
// Turn LEDs off
led_t offLeds[CONFIG_NUM_LEDS] = {0};
setLeds(offLeds, CONFIG_NUM_LEDS);

buttonEvt_t evt = {0};
while (checkButtonQueueWrapper(&evt))
{
buttonSokoHelp(soko, &evt);
}
drawSokoHelp(soko, elapsedUs);
}
}
}
Expand Down
14 changes: 12 additions & 2 deletions main/modes/games/soko/soko.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ typedef enum
{
SOKO_MENU,
SOKO_LEVELPLAY,
SOKO_LOADNEWLEVEL
SOKO_LOADNEWLEVEL,
SOKO_HELP,
} sokoScreen_t;

typedef enum
Expand Down Expand Up @@ -181,9 +182,14 @@ typedef struct soko_abs_s
{
// meta
menu_t* menu; ///< The menu structure
menu_t* bgMenu; ///< The menu structure
menuManiaRenderer_t* menuManiaRenderer; ///< Renderer for the menu
font_t ibm; ///< The font used in the menu and game
sokoScreen_t screen; ///< The screen being displayed
font_t font_rodin;
font_t font_rodin_outline;
font_t font_righteous;
font_t font_righteous_outline;
sokoScreen_t screen; ///< The screen being displayed

char* levelFileText;
char* levelNames[SOKO_LEVEL_COUNT];
Expand Down Expand Up @@ -261,6 +267,10 @@ typedef struct soko_abs_s
soko_var_t loadNewLevelVariant;

int chosen_victory_message;

// Help page
uint32_t helpIdx;
uint32_t arrowBlinkTimer;
} soko_abs_t;

extern const char SOKO_TAG[];
Expand Down
Loading

0 comments on commit c0a1aa4

Please sign in to comment.