scores + config
This commit is contained in:
parent
ff258e6aeb
commit
c6d3b022bc
22
config.yml
22
config.yml
@ -24,6 +24,17 @@ invaders:
|
|||||||
speed: 0
|
speed: 0
|
||||||
distance: 10 # distance in pixels between invaders
|
distance: 10 # distance in pixels between invaders
|
||||||
|
|
||||||
|
typeA:
|
||||||
|
points: 100
|
||||||
|
color: green
|
||||||
|
typeB:
|
||||||
|
points: 250
|
||||||
|
color: blue
|
||||||
|
typeC:
|
||||||
|
points: 600
|
||||||
|
color: red
|
||||||
|
|
||||||
|
|
||||||
# Projectiles config
|
# Projectiles config
|
||||||
projectiles:
|
projectiles:
|
||||||
missiles:
|
missiles:
|
||||||
@ -35,12 +46,7 @@ projectiles:
|
|||||||
speed: 10
|
speed: 10
|
||||||
width: 10
|
width: 10
|
||||||
|
|
||||||
points:
|
|
||||||
invader3: 100
|
|
||||||
invader2: 250
|
|
||||||
invader1: 600
|
|
||||||
|
|
||||||
grid:
|
grid:
|
||||||
- "AAAAAAAAAA"
|
- " AAAAAAAA"
|
||||||
- " BBB BBB "
|
- "B BBBBBBBB"
|
||||||
- "CCCCCCCCCC"
|
- " CCCCCCCC"
|
@ -4,6 +4,7 @@
|
|||||||
#include<string>
|
#include<string>
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "playerDef.h"
|
#include "playerDef.h"
|
||||||
|
#include "invaderDef.h"
|
||||||
|
|
||||||
typedef string configKey;
|
typedef string configKey;
|
||||||
|
|
||||||
@ -24,6 +25,8 @@ struct ConfigData {
|
|||||||
unsigned invadersDistance;
|
unsigned invadersDistance;
|
||||||
unsigned invadersFireCooldown;
|
unsigned invadersFireCooldown;
|
||||||
|
|
||||||
|
map<InvaderType, InvaderTypeDef> invadersDef;
|
||||||
|
|
||||||
unsigned missilesWidth;
|
unsigned missilesWidth;
|
||||||
unsigned missilesLength; // auto defined from width
|
unsigned missilesLength; // auto defined from width
|
||||||
unsigned missilesSpeed;
|
unsigned missilesSpeed;
|
||||||
|
12
headers/invaderDef.h
Normal file
12
headers/invaderDef.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#ifndef GUARD_INVADERDEF_H
|
||||||
|
#define GUARD_INVADERDEF_H
|
||||||
|
|
||||||
|
#include "mingl/graphics/rgbacolor.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
struct InvaderTypeDef {
|
||||||
|
nsGraphics::RGBAcolor color;
|
||||||
|
unsigned points;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -16,13 +16,13 @@ enum class WinValue{
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
enum class Invader {
|
enum class InvaderType {
|
||||||
TYPEA,
|
TYPEA,
|
||||||
TYPEB,
|
TYPEB,
|
||||||
TYPEC,
|
TYPEC,
|
||||||
NONE,
|
NONE,
|
||||||
};
|
};
|
||||||
typedef vector<Invader> InvadersColumn;
|
typedef vector<InvaderType> InvadersColumn;
|
||||||
typedef vector<InvadersColumn> InvadersGrid;
|
typedef vector<InvadersColumn> InvadersGrid;
|
||||||
typedef nsGraphics::Vec2D Position;
|
typedef nsGraphics::Vec2D Position;
|
||||||
typedef unsigned playerID;
|
typedef unsigned playerID;
|
||||||
|
@ -14,6 +14,10 @@ private:
|
|||||||
int getInt(const configKey& key);
|
int getInt(const configKey& key);
|
||||||
nsGraphics::RGBAcolor getColor(const configKey& key);
|
nsGraphics::RGBAcolor getColor(const configKey& key);
|
||||||
void getList(const configKey& key, vector<string>&);
|
void getList(const configKey& key, vector<string>&);
|
||||||
|
|
||||||
|
void readGrid(const configKey& key);
|
||||||
|
void readPlayer(const configKey& baseKey, PlayerDef&);
|
||||||
|
void readInvaderType(const configKey& baseKey, InvaderTypeDef&);
|
||||||
};
|
};
|
||||||
|
|
||||||
void ConfigBuilder::dumpInternalValues(){
|
void ConfigBuilder::dumpInternalValues(){
|
||||||
@ -98,8 +102,7 @@ void ConfigBuilder::parseFile(const string& fname) {
|
|||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigBuilder::readConfig() {
|
void ConfigBuilder::readGrid(const configKey& key){
|
||||||
|
|
||||||
vector<string> tmp;
|
vector<string> tmp;
|
||||||
getList("grid", tmp);
|
getList("grid", tmp);
|
||||||
|
|
||||||
@ -116,19 +119,19 @@ void ConfigBuilder::readConfig() {
|
|||||||
for(;i<s.size();++i){
|
for(;i<s.size();++i){
|
||||||
switch(toupper(s[i])){
|
switch(toupper(s[i])){
|
||||||
case 'A':{
|
case 'A':{
|
||||||
collectedData.grid[i].push_back(Invader::TYPEA);
|
collectedData.grid[i].push_back(InvaderType::TYPEA);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'B':{
|
case 'B':{
|
||||||
collectedData.grid[i].push_back(Invader::TYPEB);
|
collectedData.grid[i].push_back(InvaderType::TYPEB);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'C':{
|
case 'C':{
|
||||||
collectedData.grid[i].push_back(Invader::TYPEC);
|
collectedData.grid[i].push_back(InvaderType::TYPEC);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ' ':{
|
case ' ':{
|
||||||
collectedData.grid[i].push_back(Invader::NONE);
|
collectedData.grid[i].push_back(InvaderType::NONE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:{
|
default:{
|
||||||
@ -137,10 +140,27 @@ void ConfigBuilder::readConfig() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
while(i<maxSize){
|
while(i<maxSize){
|
||||||
collectedData.grid[i].push_back(Invader::NONE);
|
collectedData.grid[i].push_back(InvaderType::NONE);
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigBuilder::readPlayer(const configKey& baseKey, PlayerDef& pdef){
|
||||||
|
pdef.color = getColor(baseKey+".color");
|
||||||
|
pdef.keys.left = getChar(baseKey+".keys.left");
|
||||||
|
pdef.keys.right = getChar(baseKey+".keys.right");
|
||||||
|
pdef.keys.shoot = getChar(baseKey+".keys.shoot");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigBuilder::readInvaderType(const configKey& baseKey, InvaderTypeDef& invDef){
|
||||||
|
invDef.points = getInt(baseKey+".points");
|
||||||
|
invDef.color = getColor(baseKey+".color");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigBuilder::readConfig() {
|
||||||
|
|
||||||
|
readGrid("grid");
|
||||||
|
|
||||||
// players
|
// players
|
||||||
collectedData.playersWidth = getInt("players.width");
|
collectedData.playersWidth = getInt("players.width");
|
||||||
@ -151,15 +171,8 @@ void ConfigBuilder::readConfig() {
|
|||||||
// the scalability behind the vector of players is only an illusion, because we force player count to be 1 or 2
|
// 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
|
// It was done so the 2+ players implementation could be easier in the future, if wanted
|
||||||
collectedData.playerDefs.resize(2);
|
collectedData.playerDefs.resize(2);
|
||||||
collectedData.playerDefs[0].color = getColor("players.user1.color");
|
readPlayer("players.user1", collectedData.playerDefs[0]);
|
||||||
collectedData.playerDefs[0].keys.left = getChar("players.user1.keys.left");
|
readPlayer("players.user2", collectedData.playerDefs[1]);
|
||||||
collectedData.playerDefs[0].keys.right = getChar("players.user1.keys.right");
|
|
||||||
collectedData.playerDefs[0].keys.shoot = getChar("players.user1.keys.shoot");
|
|
||||||
|
|
||||||
collectedData.playerDefs[1].color = getColor("players.user2.color");
|
|
||||||
collectedData.playerDefs[1].keys.left = getChar("players.user2.keys.left");
|
|
||||||
collectedData.playerDefs[1].keys.right = getChar("players.user2.keys.right");
|
|
||||||
collectedData.playerDefs[1].keys.shoot = getChar("players.user2.keys.shoot");
|
|
||||||
|
|
||||||
// invaders
|
// invaders
|
||||||
collectedData.invadersSize = getInt("invaders.size");
|
collectedData.invadersSize = getInt("invaders.size");
|
||||||
@ -167,6 +180,10 @@ void ConfigBuilder::readConfig() {
|
|||||||
collectedData.invadersDistance = getInt("invaders.distance");
|
collectedData.invadersDistance = getInt("invaders.distance");
|
||||||
collectedData.invadersFireCooldown = getInt("invaders.fireCooldown");
|
collectedData.invadersFireCooldown = getInt("invaders.fireCooldown");
|
||||||
|
|
||||||
|
readInvaderType("invaders.typeA", collectedData.invadersDef[InvaderType::TYPEA]);
|
||||||
|
readInvaderType("invaders.typeB", collectedData.invadersDef[InvaderType::TYPEB]);
|
||||||
|
readInvaderType("invaders.typeC", collectedData.invadersDef[InvaderType::TYPEC]);
|
||||||
|
|
||||||
// projectiles
|
// projectiles
|
||||||
collectedData.missilesWidth = getInt("projectiles.missiles.width");
|
collectedData.missilesWidth = getInt("projectiles.missiles.width");
|
||||||
collectedData.missilesLength = collectedData.missilesWidth*PROJ_LENGTH_FACTOR;
|
collectedData.missilesLength = collectedData.missilesWidth*PROJ_LENGTH_FACTOR;
|
||||||
|
@ -119,15 +119,15 @@ void Game::display() {
|
|||||||
basePos.getY() + j * confData.invadersSize + j * confData.invadersDistance
|
basePos.getY() + j * confData.invadersSize + j * confData.invadersDistance
|
||||||
);
|
);
|
||||||
switch(grid[i][j]){
|
switch(grid[i][j]){
|
||||||
case Invader::TYPEA:{
|
case InvaderType::TYPEA:{
|
||||||
pm.drawInvader1(vec, confData.invadersSize);
|
pm.drawInvader1(vec, confData.invadersSize);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Invader::TYPEB:{
|
case InvaderType::TYPEB:{
|
||||||
pm.drawInvader2(vec, confData.invadersSize);
|
pm.drawInvader2(vec, confData.invadersSize);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Invader::TYPEC:{
|
case InvaderType::TYPEC:{
|
||||||
pm.drawInvader3(vec, confData.invadersSize);
|
pm.drawInvader3(vec, confData.invadersSize);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -188,7 +188,9 @@ bool Game::checkTorpedosAndInvaders() {
|
|||||||
}
|
}
|
||||||
if(i==grid.size()) ++tor_ite;
|
if(i==grid.size()) ++tor_ite;
|
||||||
else{
|
else{
|
||||||
players[tor_ite->owner].score += 100;
|
// compute points associated with invaders
|
||||||
|
InvaderType invType = grid[i][grid[i].size()];
|
||||||
|
players[tor_ite->owner].score += confData.invadersDef[invType].points;
|
||||||
torpedos.erase(tor_ite);
|
torpedos.erase(tor_ite);
|
||||||
grid[i].pop_back();
|
grid[i].pop_back();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user