Update pokitto

This commit is contained in:
Miloslav Číž 2020-11-13 15:10:22 +01:00
parent a8ec7e2ce2
commit e80ec3f2f8
4 changed files with 46 additions and 18 deletions

View File

@ -1,6 +1,6 @@
// Pokitto config required by PokittoLib // Pokitto config required by PokittoLib
#define PROJ_SHOW_FPS_COUNTER //#define PROJ_SHOW_FPS_COUNTER
#define PROJ_SCREENMODE 13 #define PROJ_SCREENMODE 13
#define PROJ_MODE13 1 #define PROJ_MODE13 1
#define PROJ_ENABLE_SOUND 1 #define PROJ_ENABLE_SOUND 1

View File

@ -208,6 +208,11 @@
*/ */
#define SFG_BASE_SPRITE_SIZE RCL_UNITS_PER_SQUARE #define SFG_BASE_SPRITE_SIZE RCL_UNITS_PER_SQUARE
/**
Default value of the settings byte.
*/
#define SFG_DEFAULT_SETTINGS 0x03
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// derived constants // derived constants

24
game.h
View File

@ -391,7 +391,7 @@ struct
saved position. The format is as follows: saved position. The format is as follows:
0 4b (less signif.) highest level that has been reached 0 4b (less signif.) highest level that has been reached
0 4b (more signif.) level number of the saved position (15: no save) 0 4b (more signif.) level number of the saved position (0: no save)
1 8b game settings (SFG_game.settings) 1 8b game settings (SFG_game.settings)
2 8b health at saved position 2 8b health at saved position
3 8b bullet ammo at saved position 3 8b bullet ammo at saved position
@ -1641,6 +1641,14 @@ void SFG_setAndInitLevel(uint8_t levelNumber)
SFG_processEvent(SFG_EVENT_LEVEL_STARTS,levelNumber); SFG_processEvent(SFG_EVENT_LEVEL_STARTS,levelNumber);
} }
void SFG_createDefaultSaveData(uint8_t *memory)
{
for (uint16_t i = 0; i < SFG_SAVE_SIZE; ++i)
SFG_game.save[i] = 0;
SFG_game.save[1] = SFG_DEFAULT_SETTINGS;
}
void SFG_init() void SFG_init()
{ {
SFG_LOG("initializing game") SFG_LOG("initializing game")
@ -1708,16 +1716,10 @@ void SFG_init()
SFG_currentLevel.levelPointer = 0; SFG_currentLevel.levelPointer = 0;
SFG_game.selectedMenuItem = 0; SFG_game.selectedMenuItem = 0;
SFG_game.selectedLevel = 0; SFG_game.selectedLevel = 0;
SFG_game.settings = 0x03; SFG_game.settings = SFG_DEFAULT_SETTINGS;
SFG_game.saved = 0; SFG_game.saved = 0;
// create a default save data: SFG_createDefaultSaveData(SFG_game.save);
for (uint16_t i = 0; i < SFG_SAVE_SIZE; ++i)
SFG_game.save[i] = 0;
SFG_game.save[0] = 0xf0;
SFG_game.save[1] = SFG_game.settings;
SFG_gameLoad(); // attempt to load settings SFG_gameLoad(); // attempt to load settings
@ -1729,7 +1731,7 @@ void SFG_init()
else else
{ {
SFG_LOG("saving/loading not possible"); SFG_LOG("saving/loading not possible");
SFG_game.save[0] = (SFG_NUMBER_OF_LEVELS - 1) | 0xf0; // revealed all levels SFG_game.save[0] = SFG_NUMBER_OF_LEVELS - 1; // revealed all levels
} }
SFG_setMusic((SFG_game.settings & 0x02) ? SFG_setMusic((SFG_game.settings & 0x02) ?
@ -3692,7 +3694,7 @@ uint8_t SFG_getMenuItem(uint8_t index)
{ {
if ( // skip non-legitimate items if ( // skip non-legitimate items
((current <= SFG_MENU_ITEM_MAP) && (SFG_currentLevel.levelPointer == 0)) ((current <= SFG_MENU_ITEM_MAP) && (SFG_currentLevel.levelPointer == 0))
|| ((current == SFG_MENU_ITEM_LOAD) && ((SFG_game.save[0] >> 4) == 0x0f))) || ((current == SFG_MENU_ITEM_LOAD) && ((SFG_game.save[0] >> 4) == 0)))
{ {
current++; current++;
continue; continue;

View File

@ -81,12 +81,7 @@ void SFG_setPixel(uint16_t x, uint16_t y, uint8_t colorIndex)
uint32_t SFG_getTimeMs() uint32_t SFG_getTimeMs()
{ {
return return pokitto.getTime();
#if _OSCT == 2
// overclock
(3 * pokitto.getTime()) / 2;
#endif
pokitto.getTime();
} }
void SFG_sleepMs(uint16_t timeMs) void SFG_sleepMs(uint16_t timeMs)
@ -220,6 +215,21 @@ int main()
timerInit(8000); timerInit(8000);
uint8_t allZeros = 1;
for (uint8_t i = 0; i < SFG_SAVE_SIZE; ++i)
if (save.data[i] != 0)
{
allZeros = 0;
break;
}
if (allZeros) // 1st time save
{
SFG_createDefaultSaveData(save.data);
save.saveCookie();
}
for (uint16_t i = 0; i < SFG_SFX_SAMPLE_COUNT; ++i) for (uint16_t i = 0; i < SFG_SFX_SAMPLE_COUNT; ++i)
audioBuff[i] = 127; audioBuff[i] = 127;
@ -238,6 +248,17 @@ int main()
if (pokitto.update()) if (pokitto.update())
SFG_mainLoopBody(); SFG_mainLoopBody();
if (SFG_game.state == SFG_GAME_STATE_MENU &&
SFG_game.keyStates[SFG_KEY_LEFT] == 255 &&
SFG_game.keyStates[SFG_KEY_RIGHT] == 255 &&
SFG_game.keyStates[SFG_KEY_B] == 255)
{
// holding L+R+B in menu will erase all saved data
save.deleteCookie();
pokitto.quit();
}
#if 0 #if 0
pokitto.display.setCursor(0,0); pokitto.display.setCursor(0,0);
pokitto.display.print(pokitto.fps_counter); pokitto.display.print(pokitto.fps_counter);