📄 orangeghost.cpp
字号:
// OrangeGhost.cpp
//
/////////////////////////////////////////////////////////////////////////////
#include "OrangeGhost.h"
#include "Pacman.h"
#include "Path.h"
#include "Game.h"
#include "GameState.h"
#include "GhostMoveAtHomeActions.h"
#include "GhostMoveWhenKilledActions.h"
/////////////////////////////////////////////////////////////////////////////
// initialization and cleanup
/////////////////////////////////////////////////////////////////////////////
OrangeGhost::OrangeGhost() : Ghost(ORANGE)
{
resetState();
// fills the actions arrays
moveAtHomeAction = new GhostAction*[4];
moveAtHomeAction[0] = new GhostMoveUpAndDownAction();
moveAtHomeAction[1] = new GhostNopAction();
moveAtHomeAction[2] = new GhostExitHomeAction();
moveAtHomeAction[3] = new GhostMoveFromRightToCenterAction();
moveWhenKilledAction = new GhostAction*[4];
moveWhenKilledAction[0] = new GhostNopAction();
moveWhenKilledAction[1] = new GhostGoHomeAction();
moveWhenKilledAction[2] = new GhostGoHomeAndContinueAction();
moveWhenKilledAction[3] = new GhostMoveToRightHomeSideAction();
}
OrangeGhost::~OrangeGhost()
{
// deallocates the actions arrays
for (int i = 0; i < 4; i++){
delete moveAtHomeAction[i];
delete moveWhenKilledAction[i];
}
delete[] moveAtHomeAction;
delete[] moveWhenKilledAction;
}
void OrangeGhost::initState(bool special)
{
Ghost::initState(special);
if (!special){
posX = 0x70;
posY = 0x7c;
tilePosX = actualTilePosX = 0x2c;
tilePosY = actualTilePosY = 0x2f;
movOffsX = prevMovOffsX = 0;
movOffsY = prevMovOffsY = -1;
orientation = prevOrientation = UP;
}
}
/////////////////////////////////////////////////////////////////////////////
// orange ghost AI
/////////////////////////////////////////////////////////////////////////////
void OrangeGhost::moveInNormalState()
{
// calculates current distance to pacman
int distance2 = Path::distance2(tilePosX, tilePosY,
theGame->pacman->tilePosX, theGame->pacman->tilePosY);
// in odd orientation changes indexes, if distance >= 8 tiles,
// or if we are in demo mode, try to go to pacman position
if (((theGame->indexOrientationChanges & 0x01) == 0x01) || (theGame->states[PLAYING]->substate != 3)){
if ((distance2 >= 8*8)){
// tries to go for pacman
destTilePosX = theGame->pacman->tilePosX;
destTilePosY = theGame->pacman->tilePosY;
Path::calcPath(tilePosX, tilePosY, orientation,
destTilePosX, destTilePosY,
movOffsX, movOffsY, orientation);
} else {
// goes to the lower left corner
destTilePosX = 0x3b;
destTilePosY = 0x40;
Path::calcPath(tilePosX, tilePosY, orientation, 0x3b, 0x40, movOffsX, movOffsY, orientation);
}
} else {
// searchs the best direction to choose to go to the lower left corner
destTilePosX = 0x3b;
destTilePosY = 0x40;
Path::calcPath(tilePosX, tilePosY, orientation, 0x3b, 0x40, movOffsX, movOffsY, orientation);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -