Mario: add mushroom block

This commit is contained in:
2021-08-07 21:41:15 +02:00
parent a7aa86c8e3
commit 7b2adac922
9 changed files with 188 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
#include "mushroom_visitor.hpp"
#include "../../sdlpp/sdlpp_renderobject.hpp"
#include "../objectids.hpp"
#include "../sprites.hpp"
void MushroomVisitor::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 == MARIO_FLOOR_DETECT ) {
onGround = true;
groundY = obj.getPos().getY();
} else if ( from == MARIO_LEFT_SIDE_DETECT ) {
if(!left && !right) {
movement_blockage = obj.getPos();
}
left = true;
} else if (from == MARIO_RIGHT_SIDE_DETECT ) {
if(!left && !right) {
movement_blockage = obj.getPos();
}
right = true;
}
break;
case MARIO_ID:
std::cout << "MARIO" << std::endl;
death = true;
default:
break;
}
}
+56
View File
@@ -0,0 +1,56 @@
#ifndef MUSHROOM_VISITOR_H
#define MUSHROOM_VISITOR_H
#include "../../sdlpp/sdlpp_visitor.hpp"
#include "../../sdlpp/sdlpp_geometry.hpp"
#include "../../sdlpp/sdlpp_scene.hpp"
#include "../blocks.hpp"
class MushroomVisitor : public SDLPP::Visitor {
public:
MushroomVisitor() = default;
void visit( const SDLPP::RenderObject &obj ) override;
bool isOnGround() const {
return onGround;
}
void setFromId( uint64_t id ) override {
from = id;
}
uint64_t getFromId() const override {
return from;
}
void setVisitorType( uint64_t type ) override {
_type = type;
}
uint64_t getVisitorType() const override {
return _type;
}
bool canGoLeft() const {
return !left;
}
bool canGoRight() const {
return !right;
}
double getGroundY() const {
return groundY;
}
const SDLPP::Vec2D<double> &getMovementBlockage() {
return movement_blockage;
}
bool getDeath() {
return death;
}
private:
bool onGround = false;
double groundY = 0;
bool stop = false;
bool left = false;
bool right = false;
SDLPP::Vec2D<double> movement_blockage;
uint64_t from{};
uint64_t _type{};
bool death = false;
};
#endif