initial commit
This commit is contained in:
237
src/Core/GameParameters.cpp
Normal file
237
src/Core/GameParameters.cpp
Normal file
@@ -0,0 +1,237 @@
|
||||
#include "GameParameters.h"
|
||||
|
||||
#include "Gamemode.h"
|
||||
#include "Player.h"
|
||||
|
||||
|
||||
GameParameters::GameParameters(Gamemode gamemode, const Player& controls) : gamemode(gamemode), controls(controls) {
|
||||
// initialize lines and level
|
||||
this->clearedLines = 0;
|
||||
switch (this->gamemode) {
|
||||
// lowest gravity
|
||||
case SPRINT : {this->level = 1; break;}
|
||||
// lowest gravity
|
||||
case ULTRA : {this->level = 1; break;}
|
||||
// goes from level 1 to 20
|
||||
case MARATHON : {this->level = 1; break;}
|
||||
// goes from level 20 to 39
|
||||
case MASTER : {this->level = 20; break;}
|
||||
default : this->level = 1;
|
||||
}
|
||||
|
||||
// initialize stats
|
||||
this->updateStats();
|
||||
}
|
||||
|
||||
void GameParameters::clearLines(int lineNumber) {
|
||||
// update lines and level
|
||||
switch (this->gamemode) {
|
||||
// modes where level increases
|
||||
case MARATHON :
|
||||
case MASTER : {
|
||||
// update cleared lines
|
||||
int previousLines = this->clearedLines;
|
||||
this->clearedLines += lineNumber;
|
||||
|
||||
// level increments every 10 lines, stats only changes on level up
|
||||
if (previousLines / 10 < this->clearedLines / 10) {
|
||||
this->level = this->clearedLines / 10;
|
||||
this->updateStats();
|
||||
}
|
||||
break;
|
||||
}
|
||||
// other modes
|
||||
default : this->clearedLines += lineNumber;
|
||||
}
|
||||
}
|
||||
|
||||
bool GameParameters::hasWon(int framesPassed) {
|
||||
switch (this->gamemode) {
|
||||
// win once 40 lines have been cleared
|
||||
case SPRINT : return this->clearedLines >= 40;
|
||||
// win once 2mn have passed
|
||||
case ULTRA : return (framesPassed / 60) >= 120;
|
||||
// win once 200 lines have been cleared
|
||||
case MARATHON : return this->clearedLines >= 200;
|
||||
// win once 200 lines have been cleared
|
||||
case MASTER : return this->clearedLines >= 200;
|
||||
default : return false;
|
||||
}
|
||||
}
|
||||
|
||||
void GameParameters::updateStats() {
|
||||
/* NEXT QUEUE */
|
||||
switch (this->gamemode) {
|
||||
// 5 for rapidity gamemodes
|
||||
case SPRINT :
|
||||
case ULTRA : {
|
||||
this->nextQueueLength = 5;
|
||||
break;
|
||||
}
|
||||
// 3 for endurance gamemodes
|
||||
case MARATHON :
|
||||
case MASTER : {
|
||||
this->nextQueueLength = 3;
|
||||
break;
|
||||
}
|
||||
default : this->nextQueueLength = 1;
|
||||
}
|
||||
|
||||
/* BONE BLOCKS */
|
||||
switch (this->gamemode) {
|
||||
// blocks turns into bone blocks at level 30
|
||||
case MASTER : this->boneBlocks = (this->level >= 30);
|
||||
default : this->boneBlocks = false;
|
||||
}
|
||||
|
||||
/* GRAVITY */
|
||||
if (level >= 20) {
|
||||
// all levels above 20 are instant gravity
|
||||
this->gravity = 20 * 60;
|
||||
}
|
||||
else {
|
||||
// get gravity for an assumed 20-rows board
|
||||
switch (this->level) {
|
||||
case 1 : {this->gravity = 1; break;} // 60f/line, 20s total
|
||||
case 2 : {this->gravity = 2; break;} // 30f/line, 10s total
|
||||
case 3 : {this->gravity = 3; break;} // 20f/line, 6.66s total
|
||||
case 4 : {this->gravity = 4; break;} // 15f/line, 5s total
|
||||
case 5 : {this->gravity = 5; break;} // 12f/line, 4s total
|
||||
case 6 : {this->gravity = 6; break;} // 10f/line, 3.33 total
|
||||
case 7 : {this->gravity = 7; break;} // 8.57f/line, 2.85s total
|
||||
case 8 : {this->gravity = 8; break;} // 7.5f/line, 2.5s total
|
||||
case 9 : {this->gravity = 10; break;} // 6f/line, 2s total
|
||||
case 10 : {this->gravity = 12; break;} // 5f/line, 1.66s total
|
||||
case 11 : {this->gravity = 14; break;} // 4.28f/line, 1.42s total
|
||||
case 12 : {this->gravity = 17; break;} // 3.52f/line, 1.17s total
|
||||
case 13 : {this->gravity = 20; break;} // 3f/line, 60f total
|
||||
case 14 : {this->gravity = 24; break;} // 2.5f/line, 50f total
|
||||
case 15 : {this->gravity = 30; break;} // 2f/line, 40f total
|
||||
case 16 : {this->gravity = 40; break;} // 1.5f/line, 30f total
|
||||
case 17 : {this->gravity = 1 * 60; break;} // 1line/f, 20f total
|
||||
case 18 : {this->gravity = 2 * 60; break;} // 2line/f, 10f total
|
||||
case 19 : {this->gravity = 4 * 60; break;} // 4line/f, 5f total
|
||||
default : this->gravity = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* LOCK DELAY */
|
||||
switch (this->gamemode) {
|
||||
// starts at 500ms (30f) at lvl 20 and ends at 183ms (11f) at lvl 39
|
||||
case MASTER : {this->lockDelay = 30 - (this->level - 20); break;}
|
||||
// 1s by default
|
||||
default : this->lockDelay = 60;
|
||||
}
|
||||
|
||||
/* FORCED LOCK DELAY */
|
||||
this->forcedLockDelay = this->lockDelay * 10;
|
||||
|
||||
/* ARE */
|
||||
switch (this->gamemode) {
|
||||
// starts at 400ms (24f) at lvl 1 and ends at 083ms (5f) at lvl 20
|
||||
case MARATHON : {this->ARE = 24 - (this->level - 1); break;}
|
||||
// starts at 400ms (24f) at lvl 20 and ends at 083ms (5f) at lvl 39
|
||||
case MASTER : {this->ARE = 24 - (this->level - 20); break;}
|
||||
// no ARE by default
|
||||
default : this->ARE = 0;
|
||||
}
|
||||
|
||||
/* LINE ARE */
|
||||
this->lineARE = this->ARE * 2;
|
||||
|
||||
/* DAS */
|
||||
this->DAS = this->controls.getDAS();
|
||||
switch (this->gamemode) {
|
||||
// for modes with reduced lock delay, ensure DAS is lower than lock delay, but at least 1
|
||||
case MASTER : {
|
||||
if (this->lockDelay <= this->DAS) {
|
||||
this->DAS = this->lockDelay - 6; // give 6f (100ms) to change directions
|
||||
}
|
||||
if (this->DAS < 1) {
|
||||
this->DAS = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
// modes with no reduced lock delay
|
||||
default : break;
|
||||
}
|
||||
|
||||
/* ARR */
|
||||
this->ARR = this->controls.getARR();
|
||||
switch (this->gamemode) {
|
||||
// for modes with reduced lock delay, ensure ARR is lower than DAS, but not lower than 1
|
||||
case MASTER : {
|
||||
if (this->DAS <= this->ARR) {
|
||||
this->ARR = this->DAS - 1;
|
||||
}
|
||||
if (this->ARR < 1) {
|
||||
this->ARR = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
// modes with no reduced lock delay
|
||||
default : break;
|
||||
}
|
||||
|
||||
/* SDR */
|
||||
this->SDR = this->controls.getSDR();
|
||||
switch (this->gamemode) {
|
||||
// modes where we don't want instant soft drop to be possible
|
||||
case MARATHON : {
|
||||
if (this->SDR < 1) {
|
||||
this->SDR = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
// modes where we don't care
|
||||
default : break;
|
||||
}
|
||||
}
|
||||
|
||||
int GameParameters::getClearedLines() {
|
||||
return this->clearedLines;
|
||||
}
|
||||
|
||||
int GameParameters::getLevel() {
|
||||
return this->level;
|
||||
}
|
||||
|
||||
int GameParameters::getNextQueueLength() {
|
||||
return this->nextQueueLength;
|
||||
}
|
||||
|
||||
bool GameParameters::getBoneBlocks() {
|
||||
return this->boneBlocks;
|
||||
}
|
||||
|
||||
int GameParameters::getGravity() {
|
||||
return this->gravity;
|
||||
}
|
||||
|
||||
int GameParameters::getLockDelay() {
|
||||
return this->lockDelay;
|
||||
}
|
||||
|
||||
int GameParameters::getForcedLockDelay() {
|
||||
return this->forcedLockDelay;
|
||||
}
|
||||
|
||||
int GameParameters::getARE() {
|
||||
return this->ARE;
|
||||
}
|
||||
|
||||
int GameParameters::getLineARE() {
|
||||
return this->lineARE;
|
||||
}
|
||||
|
||||
int GameParameters::getDAS() {
|
||||
return this->DAS;
|
||||
}
|
||||
|
||||
int GameParameters::getARR() {
|
||||
return this->ARR;
|
||||
}
|
||||
|
||||
int GameParameters::getSDR() {
|
||||
return this->SDR;
|
||||
}
|
||||
Reference in New Issue
Block a user