Skip to content

Commit

Permalink
Timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
feresr committed May 24, 2020
1 parent 724f710 commit e5ba46c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
2 changes: 2 additions & 0 deletions include/Components.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ struct FrozenComponent : public Component {

struct DeadComponent : public Component {
};
struct GameOverComponent : public Component {
};

struct AnimationComponent : public Component {
explicit AnimationComponent(
Expand Down
2 changes: 1 addition & 1 deletion include/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ constexpr int SKY_BLUE = 254;
constexpr int EDITOR_CAMERA_PAN_SPEED = 3;

// Instantiate ${CAMERA_WORLD_OFFSET} tiles off camera from the left and right
constexpr int CAMERA_WORLD_OFFSET = 3 * TILE_SIZE;
constexpr int CAMERA_WORLD_OFFSET = 4 * TILE_SIZE;

constexpr float GRAVITY = .040;
constexpr float FRICTION = .94;
Expand Down
6 changes: 4 additions & 2 deletions src/systems/MapSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ void MapSystem::tick(World* world) {
);
}

if (!entity->has<TextComponent>()) world->destroy(entity);
if (entity->has<PlayerComponent>()) continue;
if (entity->has<TextComponent>()) continue;
world->destroy(entity);
}
}

Expand All @@ -46,7 +48,7 @@ void MapSystem::tick(World* world) {
if (tile->x > camera->right() + CAMERA_WORLD_OFFSET) break;
auto entity = world->create();
entity->assign<TransformComponent>(tile->x, tile->y, tile->w, tile->h);
if (tile->hasProperty(VISIBLE)) {
if (tile->hasProperty(VISIBLE)) {
entity->assign<TextureComponent>(tile->textureId);
}
if (tile->hasProperty(MASS)) entity->assign<GravityComponent>();
Expand Down
15 changes: 15 additions & 0 deletions src/systems/PlayerSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ void createDebris(World* world, TransformComponent* brickTransform) {
}

void onGameOver(World* world, Entity* player) {
if (player->has<SuperMarioComponent>()) {
//player time ran out while being Super Mario
player->remove<SuperMarioComponent>();
auto texture = player->get<TextureComponent>();
auto transform = player->get<TransformComponent>();
transform->h = SMALL_MARIO_COLLIDER_HEIGHT;
transform->y += SUPER_MARIO_COLLIDER_HEIGHT - SMALL_MARIO_COLLIDER_HEIGHT;
texture->h = TILE_SIZE;
texture->offSetY = -1;
}
player->assign<DeadComponent>();
world->create()->assign<SoundComponent>(Sound::Id::DEATH);
auto music = world->findFirst<MusicComponent>();
if (music) world->destroy(music);
Expand Down Expand Up @@ -177,6 +188,10 @@ void PlayerSystem::setAnimation(ANIMATION_STATE state) {
}

void PlayerSystem::tick(World* world) {
if (world->findFirst<GameOverComponent>()) {
world->findFirst<GameOverComponent>()->remove<GameOverComponent>();
onGameOver(world, player);
}
if (player->has<DeadComponent>()) return;

auto transform = player->get<TransformComponent>();
Expand Down
14 changes: 13 additions & 1 deletion src/systems/ScoreSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,19 @@ void ScoreSystem::tick(World* world) {
}

time--;
timeLeftEntity->assign<TextComponent>(std::to_string(time / 60));
if (time >= 0) {
auto final = std::string{};
auto timeString = std::to_string(time/60);
auto zeros = 3 - timeString.length();
while (zeros > 0) {
zeros--;
final += '0';
}
final += timeString;
timeLeftEntity->assign<TextComponent>(std::move(final));
if (time <= 0) timeLeftEntity->assign<GameOverComponent>();
}

}

void ScoreSystem::handleEvent(SDL_Event& event) {
Expand Down

0 comments on commit e5ba46c

Please sign in to comment.