config def + true config file warning : cant lunch game

This commit is contained in:
Djalim Simaila 2022-01-10 14:29:09 +01:00
parent 3dcdcadff3
commit 98358bba05
7 changed files with 177 additions and 38 deletions

View File

@ -1,13 +1,67 @@
# General configuration
#############################
# #
# General configuration #
# #
#############################
#
# The setting maxFPS deffines the maximum refresh rate at which the game will
# run for a pleasant experience it should be above 30
# maxFPS: 30
#
general:
maxFPS: 90
maxFPS: 30
#############################
# #
# Player configuration #
# #
#############################
#
# # General player configuration
# Thoses settings will affect all players
#
# The width setting sets how wide will the players be during the gameplay
# session
# width: 70
#
# The startXPostion setting sets where will the players spawn at the beginning
# of the gameplay session, its in pixel relative to the left side of the screen
# for the first player, and to the right side of the screen for the second
# player
# startXPosition: 600
#
# The fireCooldown setting sets how many frames the players will have to wait
# before they can shoot again
# fireCooldown: 10
#
# The speed setting sets how many pixel will the players move when they hit
# their movement keys
# speed: 10
#
# The lives settings sets how many life points will have all players durring
# gameplay session
# lives: 3
#
# Player specific configuration
# Those are the personal setting of each player
#
# The color setting will set the color of the player durring gameplay session
# the supported values are "black","white","red","lime","blue","yellow","cyan"
# "magenta","silver","gray","maroon","olive","green","purple","teal","navy"
# color : red
#
# The keys settings will define the key configuration of the player
# the keys must be non function keys (F1 -> F12)
# keys:
# left: q
# right: d
# shoot: s
# Players config
players:
width: 200
startXPosition: 50
fireCooldown: 40
speed: 6
width: 70
startXPosition: 600
fireCooldown: 10
speed: 10
lives: 3
user1:
color: red
@ -22,12 +76,53 @@ players:
right: 6
shoot: 5
# Enemies config
#############################
# #
# Invader configuration #
# #
#############################
#
# # Invader general configuration
# Thoses settings will affect all invaders
#
# The fireCooldown setting sets how many frames the invaders will have to wait
# before they can shoot again, be aware that this setting is not representative
# of how often the invaders will shoot as there is a part of random
# fireCooldown: 0
#
# The size setting sets the size of the radius of the invaders in pixel
# size: 30
#
# The speed setting sets how many pixel will the invaders move each frame
# speed : 7
#
# The distance settings sets the distance in pixel between invaders
# distance: 15
#
#
#
# # Invader specific configuration
# Those setting will affect a specific type of invader
#
# The point setting sets how many points will a player get by defeating this invader
# points: 100
#
# The color setting set what color this type of invader will be the supported
# colors are "black","white","red","lime","blue","yellow","cyan" "magenta",
# "silver","gray","maroon","olive","green","purple","teal","navy"
# color : green
#
# exemple:
# typeA:
# points: 100
# color: green
invaders:
fireCooldown: 20
fireCooldown: 0
size: 30
speed: 2
distance: 15 # distance in pixels between invaders
speed: 7
distance: 15
typeA:
points: 100
@ -40,22 +135,65 @@ invaders:
color: red
# Projectiles config
#############################
# #
# Projectiles configuration #
# #
#############################
#
# # Projectiles cofiguration
# The settings are the same between torpedoes and missiles
#
# The color setting sets which color the projectile will be the supported
# colors are "black","white","red","lime","blue","yellow","cyan" "magenta",
# "silver","gray","maroon","olive","green","purple","teal","navy"
# color: yellow
#
# The speed settings set how many pixel will the projectile will move in a
# frame
# speed: 10
#
# The width setting set how wide in pixel will the projectile be
# witdth : 10
#
projectiles:
missiles:
color: yellow
speed: 5
speed: 10
width: 10
torpedos:
color: green
speed: 5
speed: 10
width: 10
# God is not in configuration because you can't control a god
# Grid definition
# You can add more rows, make rows longer and add spaces
#############################
# #
# Grid configuration #
# #
#############################
#
# # Grid configuration
# The grid configuration deffines how and where the invaders will be placed
# during the gameplay session. Its a list of string where a charcarter in the
# string can be one of theses values :
# - ' ' : the space character for empty
# - 'A' : the 'A' character for a type A invader
# - 'B' : the 'B' character for a type B invader
# - 'C' : the 'C' character for a type C invader
#
# The grid can have an unlimited number of rows and each row can have an
# unlimited number of invaders
#
# Exemple
# - "CAAA AAAAAA AAAC"
# - "CBBBBB BBBBBC"
# - "CCCCCCCCCCCCCCCC"
#
grid:
- "CA AAAAAA AC"
- "CBBB BBBC"
- "CCCCCCCCCCCC"
- "CAAA AAAAAA AAAC"
- "CBBBBB BBBBBC"
- "CCCCCCCCCCCCCCCC"
# God is not in configuration because you can't control a god

View File

@ -133,9 +133,10 @@ private:
/*!
* @brief main display function, clear the window and calls sub display functions
* @param[in] fps : current screen refresh rate
* @fn void displayAll() const;
*/
void displayAll() const;
void displayAll(unsigned fps) const;
/*!
* @brief display God related objets

View File

@ -25,7 +25,7 @@
// Syntax : DEBUG(cout << "hey" << endl)
// The debug flag defintion has been set here, but normally we would add it to the MakeFile
//#define DEBUG_FLAG
#define DEBUG_FLAG
#ifdef DEBUG_FLAG
#define DEBUG_MSG(X) cerr << "DEBUG: " << X << endl;

View File

@ -158,11 +158,11 @@ void ConfigBuilder::readConfig() {
readGrid("grid");
// players
collectedData.playersWidth = getInt("players.width", 200, 100, 500);
collectedData.startXPosition = getInt("players.startXPosition");
collectedData.playersSpeed = getInt("players.speed");
collectedData.playersFireCooldown = getInt("players.fireCooldown");
collectedData.playersLives = getInt("players.lives");
collectedData.playersWidth = getInt("players.width", 100, 0, 500);
collectedData.startXPosition = getInt("players.startXPosition",600 ,0 ,1200);
collectedData.playersSpeed = getInt("players.speed",1,0,100);
collectedData.playersFireCooldown = getInt("players.fireCooldown",10,1,10000);
collectedData.playersLives = getInt("players.lives",3,1,1000);
// the scalability behind the vector of players is only an illusion, because we force player count to be 1 or 2
// It was done so the 2+ players implementation could be easier in the future, if wanted
@ -171,24 +171,24 @@ void ConfigBuilder::readConfig() {
readPlayer("players.user2", collectedData.playerDefs[1]);
// invaders
collectedData.invadersSize = getInt("invaders.size");
collectedData.invadersSpeed = getInt("invaders.speed");
collectedData.invadersDistance = getInt("invaders.distance");
collectedData.invadersFireCooldown = getInt("invaders.fireCooldown");
collectedData.invadersSize = getInt("invaders.size",30,10,1000);
collectedData.invadersSpeed = getInt("invaders.speed",7,1,1000);
collectedData.invadersDistance = getInt("invaders.distance",15,5,1000);
collectedData.invadersFireCooldown = getInt("invaders.fireCooldown",0,0,1000);
readInvaderType("invaders.typeA", collectedData.invadersDef[InvaderType::TYPEA]);
readInvaderType("invaders.typeB", collectedData.invadersDef[InvaderType::TYPEB]);
readInvaderType("invaders.typeC", collectedData.invadersDef[InvaderType::TYPEC]);
// projectiles
collectedData.missilesWidth = getInt("projectiles.missiles.width");
collectedData.missilesWidth = getInt("projectiles.missiles.width",10,5,1000);
collectedData.missilesLength = collectedData.missilesWidth*PROJ_LENGTH_FACTOR;
collectedData.missilesSpeed = getInt("projectiles.missiles.speed");
collectedData.missilesSpeed = getInt("projectiles.missiles.speed",10,5,1000);
getColor("projectiles.missiles.color", collectedData.missilesColor);
collectedData.torpedosWidth = getInt("projectiles.torpedos.width");
collectedData.torpedosWidth = getInt("projectiles.torpedos.width",10,1,1000);
collectedData.torpedosLength = collectedData.torpedosWidth*PROJ_LENGTH_FACTOR;
collectedData.torpedosSpeed = getInt("projectiles.torpedos.speed");
collectedData.torpedosSpeed = getInt("projectiles.torpedos.speed",10,1,1000);
getColor("projectiles.torpedos.color", collectedData.torpedosColor);
}

View File

@ -15,7 +15,7 @@
/** Displays the screen once, and returns
* The more important stuff must be drawn last
*/
void Game::displayAll() const {
void Game::displayAll(unsigned fps) const {
pm.drawSprite(pm.gameBackground);
for (unsigned i = 0; i < this->grid.size(); ++i){
for (unsigned j = 0; j < this->grid[i].size(); ++j){

View File

@ -124,7 +124,7 @@ WinValue Game::enterGameLoop(){ // returns when game is finished
if(arePlayersDead())return WinValue::INVADERS;
displayAll();
displayAll(fps);
pm.endFrame();

View File

@ -51,7 +51,7 @@ bool Game::manageInvaders(){
// shoot
if(fireCooldown==0) {
fireCooldown = confData.invadersFireCooldown + rand() % 60;
fireCooldown = confData.invadersFireCooldown + rand() % 25;
unsigned rdCol = grid.randomValidCol();
// fire !