From 98358bba057c78b7ae43efda2632916a1fb1f216 Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Mon, 10 Jan 2022 14:29:09 +0100 Subject: [PATCH] config def + true config file warning : cant lunch game --- config.yml | 178 +++++++++++++++++++++++++++++++++----- headers/game.h | 3 +- headers/utils.h | 2 +- src/configManagement.cpp | 26 +++--- src/game/display.cpp | 2 +- src/game/gameBasics.cpp | 2 +- src/game/gameManagers.cpp | 2 +- 7 files changed, 177 insertions(+), 38 deletions(-) diff --git a/config.yml b/config.yml index ce9638b..03c67c3 100644 --- a/config.yml +++ b/config.yml @@ -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" \ No newline at end of file + - "CAAA AAAAAA AAAC" + - "CBBBBB BBBBBC" + - "CCCCCCCCCCCCCCCC" + + + # God is not in configuration because you can't control a god \ No newline at end of file diff --git a/headers/game.h b/headers/game.h index 153081a..08e995c 100644 --- a/headers/game.h +++ b/headers/game.h @@ -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 diff --git a/headers/utils.h b/headers/utils.h index d194ff0..eaf54b6 100644 --- a/headers/utils.h +++ b/headers/utils.h @@ -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; diff --git a/src/configManagement.cpp b/src/configManagement.cpp index 22bf164..8a50c59 100644 --- a/src/configManagement.cpp +++ b/src/configManagement.cpp @@ -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); } diff --git a/src/game/display.cpp b/src/game/display.cpp index 88477d6..f2dce3d 100644 --- a/src/game/display.cpp +++ b/src/game/display.cpp @@ -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){ diff --git a/src/game/gameBasics.cpp b/src/game/gameBasics.cpp index bdcf93b..3b028d5 100644 --- a/src/game/gameBasics.cpp +++ b/src/game/gameBasics.cpp @@ -124,7 +124,7 @@ WinValue Game::enterGameLoop(){ // returns when game is finished if(arePlayersDead())return WinValue::INVADERS; - displayAll(); + displayAll(fps); pm.endFrame(); diff --git a/src/game/gameManagers.cpp b/src/game/gameManagers.cpp index 9dd17c4..dfeac86 100644 --- a/src/game/gameManagers.cpp +++ b/src/game/gameManagers.cpp @@ -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 !