summaryrefslogtreecommitdiff
path: root/src/game_state.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game_state.cpp')
-rw-r--r--src/game_state.cpp122
1 files changed, 61 insertions, 61 deletions
diff --git a/src/game_state.cpp b/src/game_state.cpp
index 29bd75b..952c2f3 100644
--- a/src/game_state.cpp
+++ b/src/game_state.cpp
@@ -61,17 +61,17 @@ int GameState::addEntity(int x, int y, char type)
_shields.push_back(Shield(x,y));
return 1;
case Spaceship::ENEMY_MAP_CHAR:
- _enemySpaceship = std::unique_ptr<Spaceship>(new Spaceship(x+1, y));
- return 3;
+ _enemySpaceship = std::unique_ptr<Spaceship>(new Spaceship(x+1, y));
+ return 3;
case Spaceship::PLAYER_MAP_CHAR:
- _playerSpaceship = std::unique_ptr<Spaceship>(new Spaceship(x+1, y));
+ _playerSpaceship = std::unique_ptr<Spaceship>(new Spaceship(x+1, y));
return 3;
case Building::MISSILE_CONTROLLER_CHAR:
- _missileControllers.push_back(Building(x+1, y));
- return 3;
+ _missileControllers.push_back(Building(x+1, y));
+ return 3;
case Building::ALIEN_FACTORY_CHAR:
- _alienFactories.push_back(Building(x+1, y));
- return 3;
+ _alienFactories.push_back(Building(x+1, y));
+ return 3;
}
return 1;
}
@@ -96,11 +96,11 @@ void GameState::logState() const
}
if (_playerSpaceship)
{
- std::cout << "Player Spaceship" << _playerSpaceship->coords() << std::endl;
+ std::cout << "Player Spaceship" << _playerSpaceship->coords() << std::endl;
}
if (_enemySpaceship)
{
- std::cout << "Enemy Spaceship" << _enemySpaceship->coords() << std::endl;
+ std::cout << "Enemy Spaceship" << _enemySpaceship->coords() << std::endl;
}
}
@@ -110,25 +110,25 @@ int getPyramidOffset(int bottomWidth, int maxWidth, int x, int y, int resultIfLe
int currentRowOffset = 0;
for (int i=0; i<y; ++i)
{
- currentRowOffset += currentRowWidth;
- currentRowWidth += 2;
- if (currentRowWidth > maxWidth)
- {
- currentRowWidth = maxWidth;
- }
+ currentRowOffset += currentRowWidth;
+ currentRowWidth += 2;
+ if (currentRowWidth > maxWidth)
+ {
+ currentRowWidth = maxWidth;
+ }
}
if (x > currentRowWidth/2)
{
- return resultIfRight;
+ return resultIfRight;
}
else if (x < -currentRowWidth/2)
{
- return resultIfLeft;
+ return resultIfLeft;
}
else
{
- return currentRowOffset + currentRowWidth/2 + x;
+ return currentRowOffset + currentRowWidth/2 + x;
}
}
@@ -154,80 +154,80 @@ std::vector<bool> GameState::toBitArray() const
int playerY = GAME_AREA_LINES-3;
if (_playerSpaceship)
{
- playerX = _playerSpaceship->x();
+ playerX = _playerSpaceship->x();
}
for (auto const& alien : _aliens)
{
- if (alien.y() > playerY-4 || alien.y() < playerY-7 || alien.x() > playerX+4 || alien.x() < playerX-4)
- {
- continue;
- }
+ if (alien.y() > playerY-4 || alien.y() < playerY-7 || alien.x() > playerX+4 || alien.x() < playerX-4)
+ {
+ continue;
+ }
- result.at(alienOffset + getRectangularOffset(9, alien.x()-playerX, playerY-4-alien.y())) = true;
+ result.at(alienOffset + getRectangularOffset(9, alien.x()-playerX, playerY-4-alien.y())) = true;
}
for (auto const& bullet : _bullets)
{
- if (bullet.y() >= playerY || bullet.y() < playerY-3 || bullet.x() > playerX+2 || bullet.x() < playerX-2)
- {
- continue;
- }
+ if (bullet.y() >= playerY || bullet.y() < playerY-3 || bullet.x() > playerX+2 || bullet.x() < playerX-2)
+ {
+ continue;
+ }
- result.at(bulletOffset + getRectangularOffset(5, bullet.x()-playerX, playerY-1-bullet.y())) = true;
+ result.at(bulletOffset + getRectangularOffset(5, bullet.x()-playerX, playerY-1-bullet.y())) = true;
}
for (auto const& shield : _shields)
{
- if (shield.y() < playerY-3 || shield.x() < playerX-1 || shield.x() > playerX+1)
- {
- continue;
- }
+ if (shield.y() < playerY-3 || shield.x() < playerX-1 || shield.x() > playerX+1)
+ {
+ continue;
+ }
- result.at(shieldOffset + shield.x()-playerX+1) = true;
+ result.at(shieldOffset + shield.x()-playerX+1) = true;
}
if (_missiles.size() > 0)
{
- result.at(missileOffset) = true;
+ result.at(missileOffset) = true;
}
if (_missiles.size() < 1)
{
- result.at(missileOffset + 1) = true;
+ result.at(missileOffset + 1) = true;
}
if (_playerSpaceship)
{
- if (playerX <= GAME_WIDTH/3)
- {
- result.at(positionOffset) = true;
- }
- else if (playerX >= GAME_WIDTH*2/3)
- {
- result.at(positionOffset+2) = true;
- }
- else
- {
- result.at(positionOffset+1) = true;
- }
+ if (playerX <= GAME_WIDTH/3)
+ {
+ result.at(positionOffset) = true;
+ }
+ else if (playerX >= GAME_WIDTH*2/3)
+ {
+ result.at(positionOffset+2) = true;
+ }
+ else
+ {
+ result.at(positionOffset+1) = true;
+ }
}
result.at(canBuildOffset) = true;
for (auto const& missileController : _missileControllers)
{
- if (missileController.y() < playerY)
- {
- continue;
- }
- result.at(existingBuildingsOffset + 0) = true;
- if (_missiles.size() < 2)
- {
- result.at(missileOffset+1) = true;
- }
- if (abs(missileController.x() - playerX) < 3)
- {
- result.at(canBuildOffset) = false;
- }
+ if (missileController.y() < playerY)
+ {
+ continue;
+ }
+ result.at(existingBuildingsOffset + 0) = true;
+ if (_missiles.size() < 2)
+ {
+ result.at(missileOffset+1) = true;
+ }
+ if (abs(missileController.x() - playerX) < 3)
+ {
+ result.at(canBuildOffset) = false;
+ }
}
return result;