Mario: formatting
This commit is contained in:
@@ -2,13 +2,13 @@
|
||||
#include "../../sdlpp/sdlpp_renderobject.hpp"
|
||||
#include "../objectids.hpp"
|
||||
|
||||
void BounceVisitor::visit( const SDLPP::RenderObject &obj ) {
|
||||
void BounceVisitor::visit(const SDLPP::RenderObject &obj) {
|
||||
auto id = obj.getId();
|
||||
switch ( id ) {
|
||||
switch (id) {
|
||||
case FLOOR_ID:
|
||||
case BRICK_ID:
|
||||
case BRICK_TOP_ID:
|
||||
if(from == BOUNCE_COLLISION) {
|
||||
if (from == BOUNCE_COLLISION) {
|
||||
hits += 1;
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -7,14 +7,14 @@
|
||||
class BounceVisitor : public SDLPP::Visitor {
|
||||
public:
|
||||
BounceVisitor() = default;
|
||||
void visit( const SDLPP::RenderObject &obj ) override;
|
||||
void setFromId( uint64_t id ) override {
|
||||
void visit(const SDLPP::RenderObject &obj) override;
|
||||
void setFromId(uint64_t id) override {
|
||||
from = id;
|
||||
}
|
||||
uint64_t getFromId() const override {
|
||||
return from;
|
||||
}
|
||||
void setVisitorType( uint64_t type ) override {
|
||||
void setVisitorType(uint64_t type) override {
|
||||
_type = type;
|
||||
}
|
||||
uint64_t getVisitorType() const override {
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
#include "../objectids.hpp"
|
||||
#include "../sprites.hpp"
|
||||
|
||||
void GoombaVisitor::visit( const SDLPP::RenderObject &obj ) {
|
||||
void GoombaVisitor::visit(const SDLPP::RenderObject &obj) {
|
||||
auto id = obj.getId();
|
||||
switch ( id ) {
|
||||
switch (id) {
|
||||
case FLOOR_ID:
|
||||
case BRICK_ID:
|
||||
case BRICK_TOP_ID:
|
||||
@@ -28,17 +28,17 @@ void GoombaVisitor::visit( const SDLPP::RenderObject &obj ) {
|
||||
case CANNON_TOWER_ID:
|
||||
case CANNON_PEDESTAL_ID:
|
||||
case CANNON_ID:
|
||||
if ( from == NPC_FLOOR_DETECT ) {
|
||||
if (from == NPC_FLOOR_DETECT) {
|
||||
onGround = true;
|
||||
groundY = obj.getPos().getY();
|
||||
} else if ( from == NPC_LEFT_SIDE_DETECT ) {
|
||||
if(!left && !right) {
|
||||
} 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) {
|
||||
} else if (from == NPC_RIGHT_SIDE_DETECT) {
|
||||
if (!left && !right) {
|
||||
movement_blockage = obj.getPos();
|
||||
validXPos = movement_blockage.getX() - BLOCK_SIZE;
|
||||
}
|
||||
|
||||
@@ -9,17 +9,17 @@
|
||||
class GoombaVisitor : public SDLPP::Visitor {
|
||||
public:
|
||||
GoombaVisitor() = default;
|
||||
void visit( const SDLPP::RenderObject &obj ) override;
|
||||
void visit(const SDLPP::RenderObject &obj) override;
|
||||
bool isOnGround() const {
|
||||
return onGround;
|
||||
}
|
||||
bool isDead() const {
|
||||
return death;
|
||||
}
|
||||
void setFromId( uint64_t id ) override {
|
||||
void setFromId(uint64_t id) override {
|
||||
from = id;
|
||||
}
|
||||
void setVisitorType( uint64_t type ) override {
|
||||
void setVisitorType(uint64_t type) override {
|
||||
_type = type;
|
||||
}
|
||||
uint64_t getVisitorType() const override {
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
#include "../objectids.hpp"
|
||||
#include "../sprites.hpp"
|
||||
|
||||
void MarioVisitor::visit( const SDLPP::RenderObject &obj ) {
|
||||
void MarioVisitor::visit(const SDLPP::RenderObject &obj) {
|
||||
auto id = obj.getId();
|
||||
switch ( id ) {
|
||||
switch (id) {
|
||||
case FLOOR_ID:
|
||||
case BRICK_ID:
|
||||
case BRICK_TOP_ID:
|
||||
@@ -28,22 +28,23 @@ void MarioVisitor::visit( const SDLPP::RenderObject &obj ) {
|
||||
case CANNON_TOWER_ID:
|
||||
case CANNON_PEDESTAL_ID:
|
||||
case CANNON_ID:
|
||||
if ( from == MARIO_FLOOR_DETECT ) {
|
||||
if (from == MARIO_FLOOR_DETECT) {
|
||||
onGround = true;
|
||||
groundY = obj.getPos().getY();
|
||||
} else if ( from == MARIO_LEFT_SIDE_DETECT ) {
|
||||
if(!left && !right) {
|
||||
} 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) {
|
||||
} else if (from == MARIO_RIGHT_SIDE_DETECT) {
|
||||
if (!left && !right) {
|
||||
movement_blockage = obj.getPos();
|
||||
}
|
||||
right = true;
|
||||
} else if (from == MARIO_TOP_DETECT) {
|
||||
top_hit = true;
|
||||
} else if (from == MARIO_TOP_LEFT_DETECT || from == MARIO_TOP_RIGHT_DETECT) {
|
||||
} else if (from == MARIO_TOP_LEFT_DETECT ||
|
||||
from == MARIO_TOP_RIGHT_DETECT) {
|
||||
rightleftpos = obj.getPos();
|
||||
top_left_right = true;
|
||||
}
|
||||
@@ -54,7 +55,7 @@ void MarioVisitor::visit( const SDLPP::RenderObject &obj ) {
|
||||
_quit = true;
|
||||
break;
|
||||
case GOOMBA_ID:
|
||||
if(from != MARIO_FLOOR_DETECT && from != MARIO_ENEMY_DETECT) {
|
||||
if (from != MARIO_FLOOR_DETECT && from != MARIO_ENEMY_DETECT) {
|
||||
death = true;
|
||||
_quit = true;
|
||||
} else {
|
||||
|
||||
@@ -8,8 +8,12 @@
|
||||
|
||||
class MarioVisitor : public SDLPP::Visitor {
|
||||
public:
|
||||
MarioVisitor(bool is_jumping, SDLPP::Scene &scene, bool &quit, int &coin_count, std::vector< std::shared_ptr< MarioBlock > > &moving_objects) : jumping(is_jumping), _scene(scene), _quit(quit), _coin_count(coin_count), _moving_objects(moving_objects) {}
|
||||
void visit( const SDLPP::RenderObject &obj ) override;
|
||||
MarioVisitor(bool is_jumping, SDLPP::Scene &scene, bool &quit,
|
||||
int &coin_count,
|
||||
std::vector<std::shared_ptr<MarioBlock>> &moving_objects)
|
||||
: jumping(is_jumping), _scene(scene), _quit(quit),
|
||||
_coin_count(coin_count), _moving_objects(moving_objects) {}
|
||||
void visit(const SDLPP::RenderObject &obj) override;
|
||||
bool isOnGround() const {
|
||||
return onGround;
|
||||
}
|
||||
@@ -22,13 +26,13 @@ public:
|
||||
double newXPos() const {
|
||||
return newX;
|
||||
}
|
||||
void setFromId( uint64_t id ) override {
|
||||
void setFromId(uint64_t id) override {
|
||||
from = id;
|
||||
}
|
||||
uint64_t getFromId() const override {
|
||||
return from;
|
||||
}
|
||||
void setVisitorType( uint64_t type ) override {
|
||||
void setVisitorType(uint64_t type) override {
|
||||
_type = type;
|
||||
}
|
||||
uint64_t getVisitorType() const override {
|
||||
@@ -125,7 +129,7 @@ private:
|
||||
bool &_quit;
|
||||
int &_coin_count;
|
||||
bool mushroom = false;
|
||||
std::vector< std::shared_ptr< MarioBlock > > &_moving_objects;
|
||||
std::vector<std::shared_ptr<MarioBlock>> &_moving_objects;
|
||||
bool _bounce = false;
|
||||
};
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
#include "../objectids.hpp"
|
||||
#include "../sprites.hpp"
|
||||
|
||||
void MushroomVisitor::visit( const SDLPP::RenderObject &obj ) {
|
||||
void MushroomVisitor::visit(const SDLPP::RenderObject &obj) {
|
||||
auto id = obj.getId();
|
||||
switch ( id ) {
|
||||
switch (id) {
|
||||
case FLOOR_ID:
|
||||
case BRICK_ID:
|
||||
case BRICK_TOP_ID:
|
||||
@@ -28,17 +28,17 @@ void MushroomVisitor::visit( const SDLPP::RenderObject &obj ) {
|
||||
case CANNON_TOWER_ID:
|
||||
case CANNON_PEDESTAL_ID:
|
||||
case CANNON_ID:
|
||||
if ( from == NPC_FLOOR_DETECT ) {
|
||||
if (from == NPC_FLOOR_DETECT) {
|
||||
onGround = true;
|
||||
groundY = obj.getPos().getY();
|
||||
} else if ( from == NPC_LEFT_SIDE_DETECT ) {
|
||||
if(!left && !right) {
|
||||
} 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) {
|
||||
} else if (from == NPC_RIGHT_SIDE_DETECT) {
|
||||
if (!left && !right) {
|
||||
movement_blockage = obj.getPos();
|
||||
validXPos = movement_blockage.getX() - BLOCK_SIZE;
|
||||
}
|
||||
|
||||
@@ -9,17 +9,17 @@
|
||||
class MushroomVisitor : public SDLPP::Visitor {
|
||||
public:
|
||||
MushroomVisitor() = default;
|
||||
void visit( const SDLPP::RenderObject &obj ) override;
|
||||
void visit(const SDLPP::RenderObject &obj) override;
|
||||
bool isOnGround() const {
|
||||
return onGround;
|
||||
}
|
||||
void setFromId( uint64_t id ) override {
|
||||
void setFromId(uint64_t id) override {
|
||||
from = id;
|
||||
}
|
||||
uint64_t getFromId() const override {
|
||||
return from;
|
||||
}
|
||||
void setVisitorType( uint64_t type ) override {
|
||||
void setVisitorType(uint64_t type) override {
|
||||
_type = type;
|
||||
}
|
||||
uint64_t getVisitorType() const override {
|
||||
|
||||
@@ -4,23 +4,28 @@
|
||||
#include "mushroom_visitor.hpp"
|
||||
#include "goomba_visitor.hpp"
|
||||
|
||||
std::shared_ptr< SDLPP::Visitor >
|
||||
getVisitor( const MarioBlock &block, SDLPP::Scene &scene, bool &quit,
|
||||
int &coin_count,
|
||||
std::vector< std::shared_ptr< MarioBlock > > &moving_objects ) {
|
||||
std::shared_ptr< SDLPP::Visitor > result{};
|
||||
switch(block.getId()) {
|
||||
case MARIO_ID:
|
||||
result = std::static_pointer_cast<SDLPP::Visitor>(std::make_shared<MarioVisitor>(block.getMovement().getY() < 0, scene, quit, coin_count, moving_objects));
|
||||
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;
|
||||
std::shared_ptr<SDLPP::Visitor>
|
||||
getVisitor(const MarioBlock &block, SDLPP::Scene &scene, bool &quit,
|
||||
int &coin_count,
|
||||
std::vector<std::shared_ptr<MarioBlock>> &moving_objects) {
|
||||
std::shared_ptr<SDLPP::Visitor> result{};
|
||||
switch (block.getId()) {
|
||||
case MARIO_ID:
|
||||
result = std::static_pointer_cast<SDLPP::Visitor>(
|
||||
std::make_shared<MarioVisitor>(block.getMovement().getY() < 0,
|
||||
scene, quit, coin_count,
|
||||
moving_objects));
|
||||
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;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
#include "../blocks.hpp"
|
||||
|
||||
std::shared_ptr< SDLPP::Visitor >
|
||||
getVisitor( const MarioBlock &block, SDLPP::Scene &scene, bool &quit,
|
||||
int &coin_count,
|
||||
std::vector< std::shared_ptr< MarioBlock > > &moving_objects );
|
||||
std::shared_ptr<SDLPP::Visitor>
|
||||
getVisitor(const MarioBlock &block, SDLPP::Scene &scene, bool &quit,
|
||||
int &coin_count,
|
||||
std::vector<std::shared_ptr<MarioBlock>> &moving_objects);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user