game/mario/visitors/mario_visitor.hpp
zv0n 3437aa6b47
All checks were successful
continuous-integration/drone/push Build is passing
Mario: end of level logic
2022-09-23 16:46:50 +02:00

146 lines
3.3 KiB
C++

#ifndef MARIO_VISITOR_H
#define MARIO_VISITOR_H
#include "../../sdlpp/sdlpp_visitor.hpp"
#include "../../sdlpp/sdlpp_geometry.hpp"
#include "../../sdlpp/sdlpp_scene.hpp"
#include "../blocks.hpp"
class MarioVisitor : public SDLPP::Visitor {
public:
MarioVisitor(bool is_jumping, SDLPP::Scene &scene, bool &death,
int &coin_count,
std::vector<std::shared_ptr<MarioBlock>> &moving_objects)
: jumping(is_jumping), _scene(scene), _death(death),
_coin_count(coin_count), _moving_objects(moving_objects) {}
void visit(const SDLPP::RenderObject &obj) override;
bool isOnGround() const {
return onGround;
}
bool isDead() const {
return _death;
}
bool isStopped() const {
return stop;
}
double newXPos() const {
return newX;
}
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;
}
bool topBlock() const {
return top_hit;
}
bool moveTop() const {
return top_left_right && !top_hit;
}
const SDLPP::Vec2D<double> &getRightLeftPos() {
return rightleftpos;
}
bool canDestroy() const {
return jumping && !top_hit;
}
const SDLPP::Vec2D<double> &getMovementBlockage() {
return movement_blockage;
}
double getStopX() const {
return newX;
}
void setCoin() {
// TODO remove coin?
coin = true;
_coin_count++;
}
bool hasCoin() const {
return coin;
}
void setCoinBlock(std::shared_ptr<MarioBlock> &coin) {
// TODO remove coin_block?
coin_block = coin;
_scene.addObject(coin);
_scene.moveZJustAboveBackground(coin);
}
bool hasCoinBlock() {
return coin_block != nullptr;
}
std::shared_ptr<MarioBlock> &getCoinBlock() {
return coin_block;
}
bool hasMushroom() const {
return mushroom;
}
void setMushroomBlock(std::shared_ptr<MarioBlock> &mushroom) {
_scene.addObject(mushroom);
_scene.moveZJustAboveBackground(mushroom);
_moving_objects.push_back(mushroom);
}
bool shouldBounce() {
return _bounce;
}
bool levelEnd() {
return _end;
}
const SDLPP::Vec2D<double> &getEndPos() {
return endPos;
}
private:
bool onGround = false;
double groundY = 0;
bool stop = false;
double newX{};
uint64_t from = -1;
bool left = false;
bool right = false;
uint64_t _type = 0;
bool top_hit = false;
SDLPP::Vec2D<double> rightleftpos;
bool top_left_right = false;
bool jumping;
bool coin = false;
SDLPP::Vec2D<double> movement_blockage;
std::shared_ptr<MarioBlock> coin_block = nullptr;
SDLPP::Scene &_scene;
bool &_death;
int &_coin_count;
bool mushroom = false;
std::vector<std::shared_ptr<MarioBlock>> &_moving_objects;
bool _bounce = false;
bool _end = false;
SDLPP::Vec2D<double> endPos;
};
#endif