Mario: Fireball works

This commit is contained in:
2022-11-12 21:32:18 +01:00
parent 3cde73d1ed
commit 7bd652f4e9
19 changed files with 300 additions and 16 deletions
+3
View File
@@ -57,6 +57,9 @@ void GoombaVisitor::visit(const SDLPP::RenderObject &obj) {
}
}
break;
case FIREBALL_ID:
instant_death = true;
break;
default:
break;
}
+4
View File
@@ -17,6 +17,9 @@ public:
bool isDead() const {
return death;
}
bool instantDeath() const {
return instant_death;
}
void setFromId(uint64_t id) override {
from = id;
}
@@ -54,6 +57,7 @@ private:
double groundY = 0;
uint64_t _type{};
bool death = false;
bool instant_death = false;
uint64_t from = -1;
bool left = false;
bool right = false;
+54
View File
@@ -0,0 +1,54 @@
#include "projectile_visitor.hpp"
#include "../../sdlpp/sdlpp_renderobject.hpp"
#include "../objectids.hpp"
#include "../sprites.hpp"
void ProjectileVisitor::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 == 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 GOOMBA_ID:
std::cout << "DEATH" << std::endl;
death = true;
default:
break;
}
}
+60
View File
@@ -0,0 +1,60 @@
#ifndef PROJECTILE_VISITOR_H
#define PROJECTILE_VISITOR_H
#include "../../sdlpp/sdlpp_visitor.hpp"
#include "../../sdlpp/sdlpp_geometry.hpp"
#include "../../sdlpp/sdlpp_scene.hpp"
#include "../blocks.hpp"
class ProjectileVisitor : public SDLPP::Visitor {
public:
ProjectileVisitor() = 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;
}
double getValidXPos() {
return validXPos;
}
private:
bool onGround = false;
double groundY = 0;
double validXPos = 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
+5
View File
@@ -3,6 +3,7 @@
#include "mario_visitor.hpp"
#include "mushroom_visitor.hpp"
#include "goomba_visitor.hpp"
#include "projectile_visitor.hpp"
#include "../mario.hpp"
std::shared_ptr<SDLPP::Visitor>
@@ -28,6 +29,10 @@ getVisitor(const MarioBlock &block, SDLPP::Scene &scene,
result = std::static_pointer_cast<SDLPP::Visitor>(
std::make_shared<GoombaVisitor>(block.getPos()));
break;
case FIREBALL_ID:
result = std::static_pointer_cast<SDLPP::Visitor>(
std::make_shared<ProjectileVisitor>());
break;
default:
break;
}