game/mario/visitors/mario_visitor.hpp

116 lines
2.6 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 &quit, int &coin_count) : jumping(is_jumping), _scene(scene), _quit(quit), _coin_count(coin_count) {}
virtual void visit( const SDLPP::RenderObject &obj ) override;
bool isOnGround() {
return onGround;
}
bool isDead() {
return death;
}
bool isStopped() {
return stop;
}
double newXPos() {
return newX;
}
virtual void setFromId( uint64_t id ) override {
from = id;
}
virtual uint64_t getFromId() override {
return from;
}
virtual void setVisitorType( uint64_t type ) override {
_type = type;
}
virtual uint64_t getVisitorType() override {
return _type;
}
bool canGoLeft() {
return !left;
}
bool canGoRight() {
return !right;
}
double getGroundY() {
return groundY;
}
bool topBlock() {
return top_hit;
}
bool moveTop() {
return top_left_right && !top_hit;
}
const SDLPP::Vec2D<double> &getRightLeftPos() {
return rightleftpos;
}
bool canDestroy() {
return jumping && !top_hit;
}
const SDLPP::Vec2D<double> &getMovementBlockage() {
return movement_blockage;
}
double getStopX() {
return newX;
}
void setCoin() {
// TODO remove coin?
coin = true;
_coin_count++;
}
bool hasCoin() {
return coin;
}
void setCoinBlock(std::shared_ptr<MarioBlock> &coin) {
// TODO remove coin_block?
coin_block = coin;
_scene.addObject(coin);
_scene.setZIndex(coin, 1);
}
bool hasCoinBlock() {
return coin_block != nullptr;
}
std::shared_ptr<MarioBlock> &getCoinBlock() {
return coin_block;
}
private:
bool onGround = false;
double groundY = 0;
bool death = false;
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 &_quit;
int &_coin_count;
};
#endif