Skip to content

Commit

Permalink
Initialize screen in initializer list
Browse files Browse the repository at this point in the history
  • Loading branch information
albertvaka committed Mar 16, 2024
1 parent 8981609 commit f3f0522
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/enemies_by_screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void EnemiesByScreen::Add(int screen, Entity * e) {
void EnemiesByScreen::Remove(int screen, Entity* e) {
auto p = maperino.find(screen);
SDL_assert(p != maperino.end());

std::vector<Entity*>& list = p->second;
auto pp = std::find(list.begin(), list.end(), e);
SDL_assert(pp != list.end());
Expand Down
2 changes: 1 addition & 1 deletion src/fireslime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ constexpr const float kBigDt = Animation::TotalDurationForFrames(AnimLib::FIRESL
FireSlime::FireSlime(vec pos)
: CircleEntity(pos - vec(0, kSpriteOffsetY), 5*kSpriteScale)
, anim(AnimLib::FIRESLIME_WALK, false)
, screen(ScreenManager::FindScreenContaining(pos))
{
direction = Rand::OnceEvery(2) ? 1 : -1;
screen = ScreenManager::FindScreenContaining(pos);

this->pos = AlignWithGround(this->pos, kGroundCollision);
EnemiesByScreen::Add(screen, this);
Expand Down
4 changes: 2 additions & 2 deletions src/goomba.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ Goomba::Goomba(vec pos, Type type)
, anim(type == Type::CHARGER? AnimLib::GOOMBACHARGER : (type == Type::SHIELDER ? AnimLib::GOOMBASHIELDER : AnimLib::GOOMBA))
, type(type)
, state(type == Type::DUMMY? State::TEST_DUMMY : State::WALKING)
, screen(ScreenManager::FindScreenContaining(pos))
{
goingRight = Rand::OnceEvery(2);
screen = ScreenManager::FindScreenContaining(pos);


this->pos = AlignWithGround(this->pos, size);
EnemiesByScreen::Add(screen, this);
}
Expand Down
4 changes: 2 additions & 2 deletions src/mantis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ Mantis::Mantis(vec pos)
: CircleEntity(pos - vec(0, 8), kBoundingRadius)
, anim(AnimLib::MANTIS_WALK)
, walkingBackwards(false)
, screen(ScreenManager::FindScreenContaining(pos))
{
screen = ScreenManager::FindScreenContaining(pos);
initialPos = this->pos;
initialVelX = Rand::OnceEvery(2) ? -kSpeed : kSpeed;
Reset();
Expand Down Expand Up @@ -310,4 +310,4 @@ void Mantis::EnterWalkingState(float dt) {
vel.y = kGravityAcc*dt;
state = State::WALKING;
anim.Set(AnimLib::MANTIS_WALK);
}
}
3 changes: 1 addition & 2 deletions src/minotaur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ constexpr const float kHitTime = 0.3f;
Minotaur::Minotaur(vec pos)
: BoxEntity(pos-vec(0,kMinotaurSize.y/2), kMinotaurSize)
, anim(AnimLib::MINOTAUR_IDLE)
, screen(ScreenManager::FindScreenContaining(pos))
{
screen = ScreenManager::FindScreenContaining(pos);

this->pos = AlignWithGround(this->pos, size);
initialPos = this->pos;

Expand Down
4 changes: 2 additions & 2 deletions src/savestation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ SaveStation::SaveStation(int id, vec p)
: BoxEntity(p, vec(32, 32))
, id(id)
, hidden(false)
{
screen = ScreenManager::FindScreenContaining(pos);
, screen(ScreenManager::FindScreenContaining(pos))
{
SaveStation::ByScreen[screen].push_back(this);
}

Expand Down

0 comments on commit f3f0522

Please sign in to comment.