Mario: add Goomba

This commit is contained in:
2021-08-08 21:45:05 +02:00
parent e31c4bb2db
commit edeeadb232
8 changed files with 231 additions and 0 deletions
+59
View File
@@ -0,0 +1,59 @@
#include "goomba_visitor.hpp"
#include "../../sdlpp/sdlpp_renderobject.hpp"
#include "../objectids.hpp"
#include "../sprites.hpp"
void GoombaVisitor::visit( const SDLPP::RenderObject &obj ) {
auto id = obj.getId();
switch ( id ) {
case FLOOR_ID:
case BRICK_ID:
case BRICK_TOP_ID:
case PIPE_LEFT_BOTTOM_ID:
case PIPE_RIGHT_BOTTOM_ID:
case PIPE_LEFT_TOP_ID:
case PIPE_RIGHT_TOP_ID:
case STEP_ID:
case SIDEWAY_PIPE_END_TOP_ID:
case SIDEWAY_PIPE_END_BOTTOM_ID:
case SIDEWAY_PIPE_MIDDLE_BOTTOM_ID:
case SIDEWAY_PIPE_MIDDLE_TOP_ID:
case SIDEWAY_PIPE_CONNECTOR_BOTTOM_ID:
case SIDEWAY_PIPE_CONNECTOR_TOP_ID:
case TREE_PLATFORM_TOP_LEFT_ID:
case TREE_PLATFORM_TOP_RIGHT_ID:
case MUSHROOM_PLATFORM_TOP_MIDDLE_ID:
case MUSHROOM_PLATFORM_TOP_LEFT_ID:
case MUSHROOM_PLATFORM_TOP_RIGHT_ID:
case CANNON_TOWER_ID:
case CANNON_PEDESTAL_ID:
case CANNON_ID:
if ( from == NPC_FLOOR_DETECT ) {
onGround = true;
groundY = obj.getPos().getY();
} else if ( from == NPC_LEFT_SIDE_DETECT ) {
if(!left && !right) {
movement_blockage = obj.getPos();
validXPos = movement_blockage.getX() + BLOCK_SIZE;
}
left = true;
} else if (from == NPC_RIGHT_SIDE_DETECT ) {
if(!left && !right) {
movement_blockage = obj.getPos();
validXPos = movement_blockage.getX() - BLOCK_SIZE;
}
right = true;
}
break;
case DEATH_ID:
death = true;
break;
case MARIO_ID:
if (from == NPC_TOP_DETECT) {
death = true;
}
break;
default:
break;
}
}
+64
View File
@@ -0,0 +1,64 @@
#ifndef GOOMBA_VISITOR_H
#define GOOMBA_VISITOR_H
#include "../../sdlpp/sdlpp_visitor.hpp"
#include "../../sdlpp/sdlpp_geometry.hpp"
#include "../../sdlpp/sdlpp_scene.hpp"
#include "../blocks.hpp"
class GoombaVisitor : public SDLPP::Visitor {
public:
GoombaVisitor() = default;
void visit( const SDLPP::RenderObject &obj ) override;
bool isOnGround() const {
return onGround;
}
bool isDead() const {
return death;
}
void setFromId( uint64_t id ) override {
from = id;
}
void setVisitorType( uint64_t type ) override {
_type = type;
}
uint64_t getVisitorType() const override {
return _type;
}
uint64_t getFromId() const override {
return from;
}
bool canGoLeft() const {
return !left;
}
bool canGoRight() const {
return !right;
}
double getGroundY() const {
return groundY;
}
bool topBlock() const {
return top_hit;
}
const SDLPP::Vec2D<double> &getMovementBlockage() {
return movement_blockage;
}
double getValidXPos() const {
return validXPos;
}
private:
bool onGround = false;
double groundY = 0;
uint64_t _type{};
bool death = false;
uint64_t from = -1;
bool left = false;
bool right = false;
bool top_hit = false;
SDLPP::Vec2D<double> movement_blockage;
double validXPos = 0;
};
#endif
+5
View File
@@ -2,6 +2,7 @@
#include "../objectids.hpp"
#include "mario_visitor.hpp"
#include "mushroom_visitor.hpp"
#include "goomba_visitor.hpp"
std::shared_ptr< SDLPP::Visitor >
getVisitor( const MarioBlock &block, SDLPP::Scene &scene, bool &quit,
@@ -14,6 +15,10 @@ getVisitor( const MarioBlock &block, SDLPP::Scene &scene, bool &quit,
break;
case MUSHROOM_ID:
result = std::static_pointer_cast<SDLPP::Visitor>(std::make_shared<MushroomVisitor>());
break;
case GOOMBA_ID:
result = std::static_pointer_cast<SDLPP::Visitor>(std::make_shared<GoombaVisitor>());
break;
default:
break;
}