📄 difficulty.cpp
字号:
// Difficulty.cpp
//
/////////////////////////////////////////////////////////////////////////////
#include "Difficulty.h"
#include "Pacman.h"
#include "RedGhost.h"
#include "Game.h"
/////////////////////////////////////////////////////////////////////////////
// main difficulty table
/////////////////////////////////////////////////////////////////////////////
// 21 difficulty settings. Each entry has 6 settings:
// 0: (0..6) movement bit patterns and orientation changes entry #
// 1: not used
// 2: (0..3) ghost counter to exit home entry #
// 3: (0..7) remaining number of pills to set difficulty flags entry #
// 4: (0..8) panic state duration for the ghosts entry #
// 5: (0..2) number of units before a ghost goes out of home entry #
int Difficulty::difficultyTable[21][6] =
{
{ 3, 1, 1, 0, 2, 0 },
{ 4, 1, 2, 1, 3, 0 },
{ 4, 1, 3, 2, 4, 1 },
{ 4, 2, 3, 2, 5, 1 },
{ 5, 0, 3, 2, 6, 2 },
{ 5, 1, 3, 3, 3, 2 },
{ 5, 2, 3, 3, 6, 2 },
{ 5, 2, 3, 3, 6, 2 },
{ 5, 0, 3, 4, 7, 2 },
{ 5, 1, 3, 4, 3, 2 },
{ 5, 2, 3, 4, 6, 2 },
{ 5, 2, 3, 5, 7, 2 },
{ 5, 0, 3, 5, 7, 2 },
{ 5, 2, 3, 5, 5, 2 },
{ 5, 1, 3, 6 ,7, 2 },
{ 5, 2, 3, 6, 7, 2 },
{ 5, 2, 3, 6, 8, 2 },
{ 5, 2, 3, 6, 7, 2 },
{ 5, 2, 3, 7, 8, 2 },
{ 5, 2, 3, 7, 8, 2 },
{ 6, 2, 3, 7, 8, 2 }
};
/////////////////////////////////////////////////////////////////////////////
// difficulty subtables
/////////////////////////////////////////////////////////////////////////////
// movement bit patterns and orientation changes
Difficulty::patternsAndOrientationChanges Difficulty::movPatternsOrientationChanges[7] = {
{
{ 0x2a552a55, 0x55555555, 0x2a552a55, 0x4a5294a5, 0x25252525, 0x22222222, 0x01010101 },
{ 600, 1800, 2400, 3600, 4200, 6000, 6420 }
},
{
{ 0x4a5294a5, 0x2aaa5555, 0x2a552a55, 0x4a5294a5, 0x24924925, 0x24489122, 0x01010101 },
{ 0, 0, 0, 0, 0, 0, 0 }
},
{
{ 0x2a552a55, 0x55555555, 0x2aaa5555, 0x2a552a55, 0x4a5294a5, 0x24489122, 0x44210844 },
{ 600, 2100, 2520, 4020, 4440, 5640, 5940 }
},
{
{ 0x55555555, 0x6ad56ad5, 0x6aaad555, 0x55555555, 0x2aaa5555, 0x24922492, 0x22222222 },
{ 420, 1620, 2040, 3240, 3540, 4740, 5040 }
},
{
{ 0x6ad56ad5, 0x5ad6b5ad, 0x5ad6b5ad, 0x6ad56ad5, 0x6aaad555, 0x24924925, 0x24489122 },
{ 420, 1620, 2040, 3240, 3540, 65534, 65535 }
},
{
{ 0x6d6d6d6d, 0x6d6d6d6d, 0x6db6db6d, 0x6d6d6d6d, 0x5ad6b5ad, 0x25252525, 0x24922492 },
{ 300, 1500, 1800, 3000, 3300, 65534, 65535 }
},
{
{ 0x6ad56ad5, 0x6ad56ad5, 0x6db6db6d, 0x6d6d6d6d, 0x5ad6b5ad, 0x24489122, 0x24922492 },
{ 300, 1500, 1800, 3000, 3300, 65534, 65535 }
}
};
// Each entry has 3 settings
// 0: counter value to make pink ghost go out of home
// 1: counter value to make blue ghost go out of home
// 2: counter value to make orange ghost go out of home
int Difficulty::ghostCntExitHome[4][3] = {
{ 20, 30, 70 },
{ 0, 30, 60 },
{ 0, 0, 50 },
{ 0, 0, 0}
};
// remaining number of pills when difficulty flags are set
int Difficulty::remainingPillsDifFlags[8][2] = {
{ 20, 10 },
{ 30, 15 },
{ 40, 20 },
{ 50, 25 },
{ 60, 30 },
{ 80, 40 },
{ 100, 50 },
{ 120, 60 }
};
// panic state duration for the ghosts
int Difficulty::ghostTimeInPanicState[9] = { 960, 840, 720, 600, 480, 360, 240, 120, 1 };
// number of units before a ghost goes out of home (if pacman isn't eating pills)
int Difficulty::ghostUnitsExitHome[3] = { 240, 240, 180 };
/////////////////////////////////////////////////////////////////////////////
// difficulty settings
/////////////////////////////////////////////////////////////////////////////
// normal difficulty settings
int Difficulty::normalDifSettings[] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20
};
// hard difficulty settings
int Difficulty::hardDifSettings[] = {
1, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 20
};
/////////////////////////////////////////////////////////////////////////////
// difficulty related methods
/////////////////////////////////////////////////////////////////////////////
// update game vars with a difficulty setting
void Difficulty::setDifficultySettings(int entry)
{
if (entry == 0){
// get current difficulty setting
entry = theGame->settings.difficulty[theGame->levelState[0].diffEntry];
}
// set movement bit patterns and orientation changes
Difficulty::setMovementBitPatternsAndOrientationChanges(Difficulty::difficultyTable[entry][0]);
// set ghosts counters to exit home while pacman eats pills
Difficulty::setGhostsOutOfHomeCounters(Difficulty::difficultyTable[entry][2]);
// set number of pills to set difficulty flags
int difFlagEntry = Difficulty::difficultyTable[entry][3];
theGame->pillsFirstDiffFlag = Difficulty::remainingPillsDifFlags[difFlagEntry][0];
theGame->pillsSecondDiffFlag = Difficulty::remainingPillsDifFlags[difFlagEntry][1];
// set ghost time in panic state
theGame->timeInPanicState = Difficulty::ghostTimeInPanicState[Difficulty::difficultyTable[entry][4]];
// set counter time when a ghost goes out of home if pacman isn't eating pills
theGame->inactivityCounterLimit = Difficulty::ghostTimeInPanicState[Difficulty::difficultyTable[entry][5]];
}
/////////////////////////////////////////////////////////////////////////////
// helper methods
/////////////////////////////////////////////////////////////////////////////
void Difficulty::setMovementBitPatternsAndOrientationChanges(int entry)
{
// set movement bit patterns for pacman
Pacman *pac = theGame->pacman;
pac->movNormalPattern = Difficulty::movPatternsOrientationChanges[entry].movBitPatterns[0];
pac->movSuperPillPattern = Difficulty::movPatternsOrientationChanges[entry].movBitPatterns[1];
// set movement bit patterns for the ghosts
RedGhost *red = (RedGhost *)theGame->ghost[RED];
red->movDiffFlag1Pattern = Difficulty::movPatternsOrientationChanges[entry].movBitPatterns[3];
red->movDiffFlag2Pattern = Difficulty::movPatternsOrientationChanges[entry].movBitPatterns[2];
for (int i = 0; i < 4; i++){
Ghost *ghost = theGame->ghost[i];
ghost->movNormalPattern = Difficulty::movPatternsOrientationChanges[entry].movBitPatterns[4];
ghost->movPanicPattern = Difficulty::movPatternsOrientationChanges[entry].movBitPatterns[5];
ghost->movTunnelPattern = Difficulty::movPatternsOrientationChanges[entry].movBitPatterns[6];
}
// set orientation changes counters
for (int i = 0; i < 7; i++){
theGame->ghostsOrientationChanges[i] = Difficulty::movPatternsOrientationChanges[entry].orientationChanges[i];
}
}
void Difficulty::setGhostsOutOfHomeCounters(int entry)
{
theGame->pinkGhostExitHomeCounterLimit = Difficulty::ghostCntExitHome[entry][0];
theGame->blueGhostExitHomeCounterLimit = Difficulty::ghostCntExitHome[entry][1];
theGame->orangeGhostExitHomeCounterLimit = Difficulty::ghostCntExitHome[entry][2];
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -