Mario: add Goomba
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
#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], true, true) {
|
||||
#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.5, 0, 0.2, 0.15, NPC_TOP_DETECT ) );
|
||||
#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() || !g_visitor.canGoRight()) {
|
||||
setPos(g_visitor.getValidXPos(), getPos().getY());
|
||||
setMovement(-getMovement().getX(), getMovement().getY());
|
||||
}
|
||||
if(g_visitor.isDead()) {
|
||||
removeCollisions();
|
||||
pauseAnimation();
|
||||
setBaseRect(GOOMBA_DEATH_SRC);
|
||||
setMovement(0, 0);
|
||||
startDeath();
|
||||
//destroy();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void GoombaBlock::startDeath() {
|
||||
death_started = true;
|
||||
}
|
||||
Reference in New Issue
Block a user