📄 ghostmoveathomeactions.cpp
字号:
// GhostMoveAtHomeActions.cpp
//
/////////////////////////////////////////////////////////////////////////////
#include "GhostMoveAtHomeActions.h"
#include "Ghost.h"
#include "Game.h"
void GhostExitHomeAction::run(Ghost *ghost)
{
// if the ghost is at home and it's not set to go for pacman yet
if (ghost->substate != 1) {
// moves up
ghost->posX += movementOffsets[UP][0];
ghost->posY += movementOffsets[UP][1];
// updates orientation
ghost->prevOrientation = ghost->orientation = UP;
// if it's out
if (ghost->posY == 0x64){
// set tile positions
ghost->tilePosX = 0x2e;
ghost->tilePosY = 0x2c;
// set last movement offsets to left
ghost->prevMovOffsX = ghost->movOffsX = movementOffsets[LEFT][0];
ghost->prevMovOffsY = ghost->movOffsY = movementOffsets[LEFT][1];
// updates orientation
ghost->prevOrientation = ghost->orientation = LEFT;
// changes substate to go for pacman
ghost->substate = 1;
}
}
}
void GhostMoveUpAndDownAction::run(Ghost *ghost)
{
// if the ghost is at home and it's not set to go for pacman yet
if (ghost->substate != 1) {
// if it has reached the top or the bottom, change it's orientation
if ((ghost->posY == 0x78) || (ghost->posY == 0x80)){
ghost->changeOrientation();
}
ghost->prevOrientation = ghost->orientation;
// moves
ghost->posX += ghost->movOffsX;
ghost->posY += ghost->movOffsY;
}
}
void GhostMoveFromLeftToCenterAction::run(Ghost *ghost)
{
// moves right
ghost->posX += movementOffsets[RIGHT][0];
ghost->posY += movementOffsets[RIGHT][1];
// updates orientation
ghost->prevOrientation = ghost->orientation = RIGHT;
// if the ghost has fully reached the center, change substate
if (ghost->posX == 0x80){
ghost->substate = 2;
}
}
void GhostMoveFromRightToCenterAction::run(Ghost *ghost)
{
// moves left
ghost->posX += movementOffsets[LEFT][0];
ghost->posY += movementOffsets[LEFT][1];
// updates orientation
ghost->prevOrientation = ghost->orientation = LEFT;
// if the ghost has fully reached the center, change substate
if (ghost->posX == 0x80){
ghost->substate = 2;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -