2021-08-08 19:45:05 +00:00
|
|
|
#include "goombablock.hpp"
|
|
|
|
#include "../sprites.hpp"
|
|
|
|
#include "../global_vars.hpp"
|
|
|
|
#include "../objectids.hpp"
|
|
|
|
#include "../visitors/goomba_visitor.hpp"
|
|
|
|
|
2021-10-18 08:10:43 +00:00
|
|
|
GoombaBlock::GoombaBlock(int x, int y,
|
|
|
|
std::shared_ptr<SDLPP::Renderer> &renderer)
|
|
|
|
: MarioBlock(x, y, renderer, g_enemies_texture, GOOMBA_WALK_ANIM[0],
|
2022-09-25 17:44:28 +00:00
|
|
|
false, false) {
|
2021-08-08 19:45:05 +00:00
|
|
|
#ifndef EDITOR
|
|
|
|
setAnimationFrames(GOOMBA_WALK_ANIM);
|
|
|
|
setAnimationSpeed(12.5);
|
|
|
|
resumeAnimation();
|
|
|
|
#endif
|
|
|
|
setId(GOOMBA_ID);
|
2021-10-18 08:10:43 +00:00
|
|
|
auto bottom_detect = SDLPP::RectColider(0.2, 1, 0.6, 0, NPC_FLOOR_DETECT);
|
2021-08-08 19:45:05 +00:00
|
|
|
bottom_detect.setMinHeight(1);
|
|
|
|
addCollision(bottom_detect);
|
2021-10-18 08:10:43 +00:00
|
|
|
addCollision(SDLPP::RectColider(0, 0.25, 0.1, 0.6, NPC_LEFT_SIDE_DETECT));
|
2021-08-08 19:45:05 +00:00
|
|
|
addCollision(
|
2021-10-18 08:10:43 +00:00
|
|
|
SDLPP::RectColider(0.9, 0.25, 0.1, 0.6, NPC_RIGHT_SIDE_DETECT));
|
2022-06-21 06:52:21 +00:00
|
|
|
addCollision(std::make_shared<SDLPP::RectColider>(0.35, 0, 0.3, 0.15,
|
2021-10-18 08:10:43 +00:00
|
|
|
NPC_TOP_DETECT));
|
2022-09-25 17:44:28 +00:00
|
|
|
setBouncable(false);
|
2021-08-08 19:45:05 +00:00
|
|
|
#ifndef EDITOR
|
|
|
|
setMovement(-0.19, 0);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void GoombaBlock::move(int ticks) {
|
|
|
|
#ifndef EDITOR
|
2021-10-18 08:10:43 +00:00
|
|
|
if (wasVisible()) {
|
2021-08-08 19:45:05 +00:00
|
|
|
MarioBlock::move(ticks);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
MarioBlock::move(ticks);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void GoombaBlock::custom_move(int ticks) {
|
|
|
|
#ifndef EDITOR
|
2021-10-18 08:10:43 +00:00
|
|
|
if (death_started) {
|
2021-08-08 19:45:05 +00:00
|
|
|
death_countdown -= ticks;
|
2021-10-18 08:10:43 +00:00
|
|
|
if (death_countdown <= 0) {
|
2021-08-08 19:45:05 +00:00
|
|
|
destroy();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
gravity(ticks);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
MarioBlock::custom_move(ticks);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GoombaBlock::handleVisitor(SDLPP::Visitor &visitor) {
|
|
|
|
#ifndef EDITOR
|
2021-10-18 08:10:43 +00:00
|
|
|
auto &g_visitor = dynamic_cast<GoombaVisitor &>(visitor);
|
2021-08-08 19:45:05 +00:00
|
|
|
setOnGround(g_visitor.isOnGround());
|
2021-10-18 08:10:43 +00:00
|
|
|
if (isOnGround()) {
|
2021-08-08 19:45:05 +00:00
|
|
|
setPos(getPos().getX(), g_visitor.getGroundY() - BLOCK_SIZE);
|
|
|
|
}
|
2022-09-25 17:44:28 +00:00
|
|
|
if ((!g_visitor.canGoLeft() && getMovement().getX() < 0) ||
|
2022-06-21 06:50:43 +00:00
|
|
|
(!g_visitor.canGoRight() && getMovement().getX() > 0)) {
|
2021-08-08 19:45:05 +00:00
|
|
|
setPos(g_visitor.getValidXPos(), getPos().getY());
|
|
|
|
setMovement(-getMovement().getX(), getMovement().getY());
|
|
|
|
}
|
2021-10-18 08:10:43 +00:00
|
|
|
if (g_visitor.isDead()) {
|
2021-08-08 19:45:05 +00:00
|
|
|
removeCollisions();
|
|
|
|
pauseAnimation();
|
|
|
|
setBaseRect(GOOMBA_DEATH_SRC);
|
|
|
|
setMovement(0, 0);
|
|
|
|
startDeath();
|
2021-10-18 08:10:43 +00:00
|
|
|
// destroy();
|
2021-08-08 19:45:05 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void GoombaBlock::startDeath() {
|
|
|
|
death_started = true;
|
|
|
|
}
|