/
trilirium
/
Pacman
Обзор
Документация
Войти
/
trilirium
/
Pacman
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
PinkGhost.cpp
86 строк
3 KB
Trilirium
first commit
19 июн 2026, 11:07
19 июн 2026, 11:07
d44591e
Код
Авторство
О чём код?
// PinkGhost.cpp // ///////////////////////////////////////////////////////////////////////////// #include "PinkGhost.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 ///////////////////////////////////////////////////////////////////////////// PinkGhost::PinkGhost() : Ghost(PINK) { resetState(); // fills the actions arrays moveAtHomeAction = new GhostAction*[3]; moveAtHomeAction[0] = new GhostMoveUpAndDownAction(); moveAtHomeAction[1] = new GhostNopAction(); moveAtHomeAction[2] = new GhostExitHomeAction(); moveWhenKilledAction = new GhostAction*[3]; moveWhenKilledAction[0] = new GhostNopAction(); moveWhenKilledAction[1] = new GhostGoHomeAction(); moveWhenKilledAction[2] = new GhostEnterHomeAndEndAction(); } PinkGhost::~PinkGhost() { // deallocates the actions arrays for (int i = 0; i < 3; i++){ delete moveAtHomeAction[i]; delete moveWhenKilledAction[i]; } delete[] moveAtHomeAction; delete[] moveWhenKilledAction; } void PinkGhost::initState(bool special) { Ghost::initState(special); if (!special){ posX = 0x80; posY = 0x7c; tilePosX = actualTilePosX = 0x2e; tilePosY = actualTilePosY = 0x2f; movOffsX = prevMovOffsX = 0; movOffsY = prevMovOffsY = 1; orientation = prevOrientation = DOWN; } } ///////////////////////////////////////////////////////////////////////////// // pink ghost AI ///////////////////////////////////////////////////////////////////////////// void PinkGhost::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 4 movements destTilePosX = theGame->pacman->tilePosX + 4*theGame->pacman->movOffsX; destTilePosY = theGame->pacman->tilePosY + 4*theGame->pacman->movOffsY; // try to go there Path::calcPath(tilePosX, tilePosY, orientation, destTilePosX, destTilePosY, movOffsX, movOffsY, orientation); } else { // searchs the best direction to choose to go to the upper right corner destTilePosX = 0x3b; destTilePosY = 0x20; Path::calcPath(tilePosX, tilePosY, orientation, 0x39, 0x1d, movOffsX, movOffsY, orientation); } }