Mario: turtle blocks initial version
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
#include "turtle_visitor.hpp"
|
||||
#include "../../sdlpp/sdlpp_renderobject.hpp"
|
||||
#include "../objectids.hpp"
|
||||
#include "../sprites.hpp"
|
||||
#include "../mario.hpp"
|
||||
#include "../blocks/turtleblock.hpp"
|
||||
|
||||
void TurtleVisitor::visit(const SDLPP::RenderObject &obj) {
|
||||
auto id = obj.getId();
|
||||
auto marioBlock = reinterpret_cast<const MarioBlock&>(obj);
|
||||
switch (id) {
|
||||
case FLOOR_ID:
|
||||
case BRICK_ID:
|
||||
case BRICK_TOP_ID:
|
||||
if(marioBlock.isBouncing()) {
|
||||
bounce = true;
|
||||
instant_death = true;
|
||||
return;
|
||||
}
|
||||
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:
|
||||
instant_death = true;
|
||||
break;
|
||||
case TURTLE_ID:
|
||||
{
|
||||
auto &turtle = dynamic_cast<const TurtleBlock &>(obj);
|
||||
if ((from == NPC_LEFT_SIDE_DETECT || from == NPC_RIGHT_SIDE_DETECT) && turtle.isShell()) {
|
||||
switch_movement = true;
|
||||
next_movement = turtle.getMovementAfterSwitch();
|
||||
if(from == NPC_LEFT_SIDE_DETECT) {
|
||||
valid_turtle_hit_pos = obj.getPos().getX() + BLOCK_SIZE;
|
||||
} else {
|
||||
valid_turtle_hit_pos = obj.getPos().getX() - BLOCK_SIZE;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MARIO_ID:
|
||||
{
|
||||
auto &mario = dynamic_cast<const Mario &>(obj);
|
||||
if (from == NPC_TOP_DETECT && obj.getPos().getY() <= turtle_pos.getY() - 0.5*BLOCK_SIZE && !mario.isJumping()) {
|
||||
death = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FIREBALL_ID:
|
||||
instant_death = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
#ifndef TURTLE_VISITOR_H
|
||||
#define TURTLE_VISITOR_H
|
||||
|
||||
#include "../../sdlpp/sdlpp_visitor.hpp"
|
||||
#include "../../sdlpp/sdlpp_geometry.hpp"
|
||||
#include "../../sdlpp/sdlpp_scene.hpp"
|
||||
#include "../blocks.hpp"
|
||||
|
||||
class TurtleVisitor : public SDLPP::Visitor {
|
||||
public:
|
||||
TurtleVisitor() = delete;
|
||||
TurtleVisitor(const SDLPP::Vec2D<double> &pos) : turtle_pos(pos) {}
|
||||
void visit(const SDLPP::RenderObject &obj) override;
|
||||
bool isOnGround() const {
|
||||
return onGround;
|
||||
}
|
||||
bool isDead() const {
|
||||
return death;
|
||||
}
|
||||
bool instantDeath() const {
|
||||
return instant_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;
|
||||
}
|
||||
bool switchMovement() const {
|
||||
return switch_movement;
|
||||
}
|
||||
double getNextMovement() const {
|
||||
return next_movement;
|
||||
}
|
||||
double getTurtleHitValidPos() const {
|
||||
return valid_turtle_hit_pos;
|
||||
}
|
||||
bool shouldBounce() const {
|
||||
return bounce;
|
||||
}
|
||||
|
||||
private:
|
||||
bool onGround = false;
|
||||
double groundY = 0;
|
||||
uint64_t _type{};
|
||||
bool death = false;
|
||||
bool instant_death = false;
|
||||
uint64_t from = -1;
|
||||
bool left = false;
|
||||
bool right = false;
|
||||
bool top_hit = false;
|
||||
bool bounce = false;
|
||||
SDLPP::Vec2D<double> movement_blockage;
|
||||
double validXPos = 0;
|
||||
const SDLPP::Vec2D<double> turtle_pos;
|
||||
bool switch_movement = false;
|
||||
double next_movement = 0;
|
||||
double valid_turtle_hit_pos = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user