/
trilirium
/
Pacman
Обзор
Документация
Войти
/
trilirium
/
Pacman
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
DemoSubstates.cpp
328 строк
8 KB
Trilirium
first commit
19 июн 2026, 11:07
19 июн 2026, 11:07
d44591e
Код
Авторство
О чём код?
// DemoSubstates.cpp // ///////////////////////////////////////////////////////////////////////////// #include "DemoSubstates.h" #include "Difficulty.h" #include "Game.h" #include "Ghost.h" #include "Pacman.h" #include "Video.h" #include "Writer.h" using namespace Puckman; void DemoInitSubstate::run() { // clear gameplay VRAM and init CRAM Video::clearVRAM(true); Video::initCRAM(0); // init pacman and ghosts positions, tile positions, orientation vars and sprite data theGame->initCharacterState(false); // reset pacman, fruit and ghost positions theGame->resetCharacterPositions(); // prints CHARACTER/NICKNAME Writer::printString(0x0c); // schedules a substate change in a second theScheduler->addScheduledTask(new Task(2, Task::TEN_HUNDREDTHS, 10)); // changes to the next substate theGame->states[DEMO]->substate++; } void DemoDrawRedGhostSubstate::run() { // draw red ghost Video::drawTileGhost(0x304, 1); // schedules a substate change in a second theScheduler->addScheduledTask(new Task(2, Task::TEN_HUNDREDTHS, 10)); // changes to the next substate theGame->states[DEMO]->substate++; } void DemoPrintRedGhostNameSubstate::run() { // print ghost name Writer::printString((theGame->settings.alternateGhostNames) ? 0x15 : 0x14); // schedules a substate change in half a second theScheduler->addScheduledTask(new Task(2, Task::TEN_HUNDREDTHS, 5)); // changes to the next substate theGame->states[DEMO]->substate++; } void DemoPrintRedGhostNicknameSubstate::run() { // print ghost nickname Writer::printString((theGame->settings.alternateGhostNames) ? 0x0e : 0x0d); // schedules a substate change in half a second theScheduler->addScheduledTask(new Task(2, Task::TEN_HUNDREDTHS, 5)); // changes to the next substate theGame->states[DEMO]->substate++; } void DemoDrawPinkGhostSubstate::run() { // draw pink ghost Video::drawTileGhost(0x307, 3); // schedules a substate change in a second theScheduler->addScheduledTask(new Task(2, Task::TEN_HUNDREDTHS, 10)); // changes to the next substate theGame->states[DEMO]->substate++; } void DemoPrintPinkGhostNameSubstate::run() { // print ghost name Writer::printString((theGame->settings.alternateGhostNames) ? 0x17 : 0x16); // schedules a substate change in half a second theScheduler->addScheduledTask(new Task(2, Task::TEN_HUNDREDTHS, 5)); // changes to the next substate theGame->states[DEMO]->substate++; } void DemoPrintPinkGhostNicknameSubstate::run() { // print ghost nickname Writer::printString((theGame->settings.alternateGhostNames) ? 0x10 : 0x0f); // schedules a substate change in half a second theScheduler->addScheduledTask(new Task(2, Task::TEN_HUNDREDTHS, 5)); // changes to the next substate theGame->states[DEMO]->substate++; } void DemoDrawBlueGhostSubstate::run() { // draw blue ghost Video::drawTileGhost(0x30a, 5); // schedules a substate change in a second theScheduler->addScheduledTask(new Task(2, Task::TEN_HUNDREDTHS, 10)); // changes to the next substate theGame->states[DEMO]->substate++; } void DemoPrintBlueGhostNameSubstate::run() { // print ghost name Writer::printString((theGame->settings.alternateGhostNames) ? 0x34 : 0x33); // schedules a substate change in half a second theScheduler->addScheduledTask(new Task(2, Task::TEN_HUNDREDTHS, 5)); // changes to the next substate theGame->states[DEMO]->substate++; } void DemoPrintBlueGhostNicknameSubstate::run() { // print ghost nickname Writer::printString((theGame->settings.alternateGhostNames) ? 0x30 : 0x2f); // schedules a substate change in half a second theScheduler->addScheduledTask(new Task(2, Task::TEN_HUNDREDTHS, 5)); // changes to the next substate theGame->states[DEMO]->substate++; } void DemoDrawOrangeGhostSubstate::run() { // draw red ghost Video::drawTileGhost(0x30d, 7); // schedules a substate change in a second theScheduler->addScheduledTask(new Task(2, Task::TEN_HUNDREDTHS, 10)); // changes to the next substate theGame->states[DEMO]->substate++; } void DemoPrintOrangeGhostNameSubstate::run() { // print ghost name Writer::printString((theGame->settings.alternateGhostNames) ? 0x36 : 0x35); // schedules a substate change in half a second theScheduler->addScheduledTask(new Task(2, Task::TEN_HUNDREDTHS, 5)); // changes to the next substate theGame->states[DEMO]->substate++; } void DemoPrintOrangeGhostNicknameSubstate::run() { // print ghost nickname Writer::printString((theGame->settings.alternateGhostNames) ? 0x32 : 0x31); // schedules a substate change in a second theScheduler->addScheduledTask(new Task(2, Task::TEN_HUNDREDTHS, 10)); // changes to the next substate theGame->states[DEMO]->substate++; } void DemoDrawPillPointsSubstate::run() { // prints small pill 10 pts Writer::printString(0x11); // prints big pill 50 pts Writer::printString(0x12); // schedules a substate change in a second theScheduler->addScheduledTask(new Task(2, Task::TEN_HUNDREDTHS, 10)); // changes to the next substate theGame->states[DEMO]->substate++; } static void demoMainLoop() { // handle collisions theGame->moveAndHandleCollisions(); theGame->moveAndHandleCollisions(); // update ghost and pill animations theGame->updateGhostAnimCounters(); theGame->updateSuperPillState(); // set dead ghosts colors theGame->setDeadGhostsColor(); // check if we have to change pacman's orientation theGame->pacman->checkOrientationChanges(); // check if we have to change ghosts orientation for (int i = 0; i < 4; i++){ theGame->ghost[i]->checkOrientationChanges(); } } void DemoInitSimulationSubstate::run() { // prints NAMCO Writer::printString(0x13); // schedules a substate change in a second theScheduler->addScheduledTask(new Task(2, Task::TEN_HUNDREDTHS, 10)); // changes to the next substate theGame->states[DEMO]->substate++; // inits players/level data theGame->initPlayersLevelData(); // clears game state theGame->initGameState(); theGame->cntGhostsMovHome = 0x55; // sets difficulty settings Difficulty::setDifficultySettings(20); // init pacman and ghosts positions, tile positions, orientation vars and sprite data theGame->initCharacterState(true); // sets number of lives lives and number of players theGame->levelState->lives = 1; theGame->levelState->displayedLives = 0; theGame->numberOfPlayers = 0; // draws a big pill theGame->VRAM[0x332] = 0x14; // creates a mini level composed of 2 invisible lines Video::drawInvisibleMiniLevel(); } void DemoAnim0Substate::run() { // when pacman reaches a position, set red ghost to go for pacman and change state if (theGame->pacman->tilePosX == 0x21){ theGame->ghost[RED]->substate = 1; // change to the next substate theGame->states[DEMO]->substate++; } else { // otherwise, keep animating demoMainLoop(); } } void DemoAnim1Substate::run() { // when red ghost reaches a position, set pink ghost to go for pacman and change state if (theGame->ghost[RED]->actualTilePosX == 0x20){ theGame->ghost[PINK]->substate = 1; // change to the next substate theGame->states[DEMO]->substate++; } else { // otherwise, keep animating demoMainLoop(); } } void DemoAnim2Substate::run() { // when red ghost reaches a position, set blue ghost to go for pacman and change state if (theGame->ghost[RED]->actualTilePosX == 0x22){ theGame->ghost[BLUE]->substate = 1; // change to the next substate theGame->states[DEMO]->substate++; } else { // otherwise, keep animating demoMainLoop(); } } void DemoAnim3Substate::run() { // when red ghost reaches a position, set orange ghost to go for pacman and change state if (theGame->ghost[RED]->actualTilePosX == 0x24){ theGame->ghost[ORANGE]->substate = 1; // change to the next substate theGame->states[DEMO]->substate++; } else { // otherwise, keep animating demoMainLoop(); } } void DemoAnim4Substate::run() { // if we've just finished killing the last ghost, advance substate if ((theGame->currentKills + theGame->ghostDeadAnimState) == 6){ theGame->states[DEMO]->substate++; } else { // otherwise, keep animating demoMainLoop(); } } void DemoPlayingSubstate::run() { // play demo game theGame->states[PLAYING]->run(); }