/
trilirium
/
Pacman
Обзор
Документация
Войти
/
trilirium
/
Pacman
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
BlueGhost.cpp
90 строк
3 KB
Trilirium
first commit
19 июн 2026, 11:07
19 июн 2026, 11:07
d44591e
Код
Авторство
О чём код?
// BlueGhost.cpp // ///////////////////////////////////////////////////////////////////////////// #include "BlueGhost.h" #include "Pacman.h" #include "Path.h" #include "Game.h" #include "GameState.h" #include "GhostMoveAtHomeActions.h" #include "GhostMoveWhenKilledActions.h" using namespace Puckman; ///////////////////////////////////////////////////////////////////////////// // initialization and cleanup ///////////////////////////////////////////////////////////////////////////// BlueGhost::BlueGhost() : Ghost(BLUE) { resetState(); // fills the actions arrays moveAtHomeAction = new GhostAction*[4]; moveAtHomeAction[0] = new GhostMoveUpAndDownAction(); moveAtHomeAction[1] = new GhostNopAction(); moveAtHomeAction[2] = new GhostExitHomeAction(); moveAtHomeAction[3] = new GhostMoveFromLeftToCenterAction(); moveWhenKilledAction = new GhostAction*[4]; moveWhenKilledAction[0] = new GhostNopAction(); moveWhenKilledAction[1] = new GhostGoHomeAction(); moveWhenKilledAction[2] = new GhostGoHomeAndContinueAction(); moveWhenKilledAction[3] = new GhostMoveToLeftHomeSideAction(); } BlueGhost::~BlueGhost() { // deallocates the actions arrays for (int i = 0; i < 4; i++){ delete moveAtHomeAction[i]; delete moveWhenKilledAction[i]; } delete[] moveAtHomeAction; delete[] moveWhenKilledAction; } void BlueGhost::initState(bool special) { Ghost::initState(special); if (!special){ posX = 0x90; posY = 0x7c; tilePosX = actualTilePosX = 0x30; tilePosY = actualTilePosY = 0x2f; movOffsX = prevMovOffsX = 0; movOffsY = prevMovOffsY = -1; orientation = prevOrientation = UP; } } ///////////////////////////////////////////////////////////////////////////// // blue ghost AI ///////////////////////////////////////////////////////////////////////////// void BlueGhost::moveInNormalState() { // in odd orientation changes indexes, or if we are in demo mode, try to go to pacman position if (((theGame->indexOrientationChanges & 0x01) == 0x01) || (theGame->states[PLAYING]->substate != 3)){ // calculates new pacman position in 2 movements int newPacmanPosX = theGame->pacman->tilePosX + 2*theGame->pacman->movOffsX; int newPacmanPosY = theGame->pacman->tilePosY + 2*theGame->pacman->movOffsY; destTilePosX = 2*newPacmanPosX - theGame->ghost[RED]->tilePosX; destTilePosY = 2*newPacmanPosY - theGame->ghost[RED]->tilePosY; // tries to move where pacman will go if he goes away from red ghost Path::calcPath(tilePosX, tilePosY, orientation, destTilePosX, destTilePosY, movOffsX, movOffsY, orientation); } else { // searchs the best direction to choose to go to the lower right corner destTilePosX = 0x20; destTilePosY = 0x40; Path::calcPath(tilePosX, tilePosY, orientation, 0x20, 0x40, movOffsX, movOffsY, orientation); } }