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