Mario: only visit objects if they entered screen at least once

This commit is contained in:
zvon 2021-08-07 22:25:32 +02:00
parent f7002f0f38
commit 4f65dba2e0
3 changed files with 17 additions and 1 deletions

View File

@ -656,3 +656,12 @@ void MarioBlock::setBaseRect(SDL_Rect rect) {
_base_src = rect;
setType(getType());
}
void MarioBlock::checkVisibility(double rightmost_x) {
// we assume that object's X > 0 as otherwise it would be destroyed
if(!getHidden() && getAbsolutePos().getX() < rightmost_x) {
_was_visible = true;
}
}
bool MarioBlock::wasVisible() const {
return _was_visible;
}

View File

@ -42,6 +42,8 @@ public:
bool isBouncing() const;
bool isTraveling() const;
void setBaseRect(SDL_Rect rect);
void checkVisibility(double rightmost_x);
bool wasVisible() const;
protected:
double bounce_speed = 0.5;
@ -83,6 +85,7 @@ private:
int _base_gravity_ticks = 1000 / 60;
int _ticks_till_gravity = 0;
double _gravity_acceleration = 1.0/(64.0/7.0);
bool _was_visible = false;
};
extern const std::vector< uint64_t > possibleBlocks;

View File

@ -142,8 +142,12 @@ void doInput( std::shared_ptr< SDLPP::Scene > scene ) {
std::lock_guard< std::mutex > lock( render_mutex );
scene->updateScene();
auto prev_coin_count = coin_count;
// TODO only start doing visits once the object has been on screen at least once
auto rightmost_x = renderer->getDoubleDimensions().getX();
for(size_t i = 0; i < moving_objects.size(); i++) {
moving_objects[i]->checkVisibility(rightmost_x);
if(!moving_objects[i]->wasVisible()) {
continue;
}
auto visitor =
getVisitor( *moving_objects[i], *scene, quit, coin_count, moving_objects );
scene->visitCollisions( *moving_objects[i], *visitor );