Mario: enable death from bounce for Goomba

This commit is contained in:
zv0n 2023-04-08 19:43:36 +02:00
parent b175e58714
commit d41c77ab96
3 changed files with 14 additions and 1 deletions

View File

@ -64,11 +64,14 @@ void GoombaBlock::handleVisitor(SDLPP::Visitor &visitor) {
setPos(g_visitor.getValidXPos(), getPos().getY()); setPos(g_visitor.getValidXPos(), getPos().getY());
setMovement(-getMovement().getX(), getMovement().getY()); setMovement(-getMovement().getX(), getMovement().getY());
} }
if (g_visitor.shouldBounce()) {
setMovement(getMovement().getX(), -0.5);
}
if (g_visitor.isDead()) { if (g_visitor.isDead()) {
removeCollisions(); removeCollisions();
pauseAnimation(); pauseAnimation();
setBaseRect(GOOMBA_DEATH_SRC); setBaseRect(GOOMBA_DEATH_SRC);
setMovement(0, 0); setMovement(0, getMovement().getY());
startDeath(); startDeath();
// destroy(); // destroy();
} }

View File

@ -7,10 +7,16 @@
void GoombaVisitor::visit(const SDLPP::RenderObject &obj) { void GoombaVisitor::visit(const SDLPP::RenderObject &obj) {
auto id = obj.getId(); auto id = obj.getId();
auto marioBlock = reinterpret_cast<const MarioBlock&>(obj);
switch (id) { switch (id) {
case FLOOR_ID: case FLOOR_ID:
case BRICK_ID: case BRICK_ID:
case BRICK_TOP_ID: case BRICK_TOP_ID:
if(marioBlock.isBouncing()) {
bounce = true;
death = true;
return;
}
case PIPE_LEFT_BOTTOM_ID: case PIPE_LEFT_BOTTOM_ID:
case PIPE_RIGHT_BOTTOM_ID: case PIPE_RIGHT_BOTTOM_ID:
case PIPE_LEFT_TOP_ID: case PIPE_LEFT_TOP_ID:

View File

@ -51,6 +51,9 @@ public:
double getValidXPos() const { double getValidXPos() const {
return validXPos; return validXPos;
} }
bool shouldBounce() {
return bounce;
}
private: private:
bool onGround = false; bool onGround = false;
@ -58,6 +61,7 @@ private:
uint64_t _type{}; uint64_t _type{};
bool death = false; bool death = false;
bool instant_death = false; bool instant_death = false;
bool bounce = false;
uint64_t from = -1; uint64_t from = -1;
bool left = false; bool left = false;
bool right = false; bool right = false;