📄 gamesettings.cpp
字号:
// GameSettings.cpp
//
/////////////////////////////////////////////////////////////////////////////
#include "GameSettings.h"
#include "Difficulty.h"
#include "../InputHandler.h"
#include "../Types.h"
/////////////////////////////////////////////////////////////////////////////
// initialization and cleanup
/////////////////////////////////////////////////////////////////////////////
GameSettings::GameSettings()
{
resetState();
}
GameSettings::~GameSettings()
{
}
void GameSettings::resetState()
{
accumulatedCoins = coinsInserted = 0;
lastServices = lastCoins1 = lastCoins2 = 0;
credits = coinsPerCredit[0] = coinsPerCredit[1] = 0;
lives = bonusLife = 0;
alternateGhostNames = false;
difficulty = 0;
}
/////////////////////////////////////////////////////////////////////////////
// methods
/////////////////////////////////////////////////////////////////////////////
// read DISPW and store game settings
void GameSettings::getSettings()
{
UINT32 dipsw1 = theInputHandler->getDIPSW(0);
if ((dipsw1 & 0x03) == 00){
// free play
credits = 0xff;
}
int coins[4] = { 0, 1, 1, 2 };
int credits[4] = { 0, 1, 2, 1 };
// process credits per coin
coinsPerCredit[COINS] = coins[dipsw1 & 0x03];
coinsPerCredit[CREDITS] = credits[dipsw1 & 0x03];
int numberOfLives[4] = { 1, 2, 3, 5 };
// lives
lives = numberOfLives[(dipsw1 >> 2) & 0x03];
int bonusLifePts[4] = { 10000, 15000, 20000, MAX_INT };
// bonus life
bonusLife = bonusLifePts[(dipsw1 >> 4) & 0x03];
// ghosts name
alternateGhostNames = (dipsw1 & 0x80) == 0;
// difficulty
difficulty = ((dipsw1 & 0x40) == 0x40) ? Difficulty::normalDifSettings : Difficulty::hardDifSettings;
}
// check for a new coin and update credits if necessary
void GameSettings::checkForCoinInserted()
{
// if we can't accept more credits, exit
if (credits >= 99) return;
// keep 4 last service values
lastServices = ((lastServices << 1) | ((theInputHandler->getInput(0) >> 7) & 0x01)) & 0x0f;
// if there's a 1->0 transition for at least 2 frames, try to get a credit
if (lastServices == 0x0c){
checkForCredit();
}
// keep 4 last coin 2 values
lastCoins2 = ((lastCoins2 << 1) | ((theInputHandler->getInput(0) >> 6) & 0x01)) & 0x0f;
// if there's a 1->0 transition for at least 2 frames, update coins
if (lastCoins2 == 0x0c){
coinsInserted++;
}
// keep 4 last coin 1 values
lastCoins1 = ((lastCoins1 << 1) | ((theInputHandler->getInput(0) >> 5) & 0x01)) & 0x0f;
// if there's a 1->0 transition for at least 2 frames, update coins
if (lastCoins1 == 0x0c){
coinsInserted++;
}
}
void GameSettings::checkForNewCredit()
{
if (coinsInserted > 0){
checkForCredit();
coinsInserted--;
}
}
/////////////////////////////////////////////////////////////////////////////
// helper methods
/////////////////////////////////////////////////////////////////////////////
void GameSettings::checkForCredit()
{
accumulatedCoins++;
// if we've reached the number of coins needed, update credits
if (accumulatedCoins == coinsPerCredit[COINS]){
accumulatedCoins = 0;
credits += coinsPerCredit[CREDITS];
if (credits > 99) credits = 99;
// TODOSOUND: play new credit sound
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -