Mario: only visit objects if they entered screen at least once
This commit is contained in:
parent
f7002f0f38
commit
4f65dba2e0
@ -656,3 +656,12 @@ void MarioBlock::setBaseRect(SDL_Rect rect) {
|
|||||||
_base_src = rect;
|
_base_src = rect;
|
||||||
setType(getType());
|
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;
|
||||||
|
}
|
||||||
|
@ -42,6 +42,8 @@ public:
|
|||||||
bool isBouncing() const;
|
bool isBouncing() const;
|
||||||
bool isTraveling() const;
|
bool isTraveling() const;
|
||||||
void setBaseRect(SDL_Rect rect);
|
void setBaseRect(SDL_Rect rect);
|
||||||
|
void checkVisibility(double rightmost_x);
|
||||||
|
bool wasVisible() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
double bounce_speed = 0.5;
|
double bounce_speed = 0.5;
|
||||||
@ -83,6 +85,7 @@ private:
|
|||||||
int _base_gravity_ticks = 1000 / 60;
|
int _base_gravity_ticks = 1000 / 60;
|
||||||
int _ticks_till_gravity = 0;
|
int _ticks_till_gravity = 0;
|
||||||
double _gravity_acceleration = 1.0/(64.0/7.0);
|
double _gravity_acceleration = 1.0/(64.0/7.0);
|
||||||
|
bool _was_visible = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const std::vector< uint64_t > possibleBlocks;
|
extern const std::vector< uint64_t > possibleBlocks;
|
||||||
|
@ -142,8 +142,12 @@ void doInput( std::shared_ptr< SDLPP::Scene > scene ) {
|
|||||||
std::lock_guard< std::mutex > lock( render_mutex );
|
std::lock_guard< std::mutex > lock( render_mutex );
|
||||||
scene->updateScene();
|
scene->updateScene();
|
||||||
auto prev_coin_count = coin_count;
|
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++) {
|
for(size_t i = 0; i < moving_objects.size(); i++) {
|
||||||
|
moving_objects[i]->checkVisibility(rightmost_x);
|
||||||
|
if(!moving_objects[i]->wasVisible()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
auto visitor =
|
auto visitor =
|
||||||
getVisitor( *moving_objects[i], *scene, quit, coin_count, moving_objects );
|
getVisitor( *moving_objects[i], *scene, quit, coin_count, moving_objects );
|
||||||
scene->visitCollisions( *moving_objects[i], *visitor );
|
scene->visitCollisions( *moving_objects[i], *visitor );
|
||||||
|
Loading…
Reference in New Issue
Block a user