Mario editor: use visitors

This commit is contained in:
zvon 2021-05-02 14:14:11 +02:00
parent 34324d3054
commit 96857a99af
11 changed files with 268 additions and 100 deletions

View File

@ -18,7 +18,7 @@ endif
COMMON_OBJECTS = blocks.${OBJEXT} global_vars.${OBJEXT} sprites.${OBJEXT} maploader.${OBJEXT}
MARIO_OBJECTS = mario.${OBJEXT} mario_visitor.${OBJEXT} ${COMMON_OBJECTS}
EDITOR_OBJECTS = editor.${OBJEXT} ${COMMON_OBJECTS}
EDITOR_OBJECTS = editor.${OBJEXT} edit_box.${OBJEXT} editor_visitor.${OBJEXT} ${COMMON_OBJECTS}
ifeq ($(UNAME_S),Linux)
MARIO_OBJECTS += libsdlpp.so
@ -61,6 +61,10 @@ mario_visitor.${OBJEXT}: mario_visitor.cpp ../sdlpp/sdlpp.hpp mario_visitor.hpp
$(CXX) $(CXXFLAGS) -c ${OUTPUTFLAG}$@ $<
editor.${OBJEXT}: editor.cpp ../sdlpp/sdlpp.hpp sprites.hpp
$(CXX) $(CXXFLAGS) -c ${OUTPUTFLAG}$@ $<
edit_box.${OBJEXT}: edit_box.cpp ../sdlpp/sdlpp.hpp sprites.hpp edit_box.hpp
$(CXX) $(CXXFLAGS) -c ${OUTPUTFLAG}$@ $<
editor_visitor.${OBJEXT}: editor_visitor.cpp ../sdlpp/sdlpp.hpp sprites.hpp editor_visitor.hpp
$(CXX) $(CXXFLAGS) -c ${OUTPUTFLAG}$@ $<
libsdlpp.so: ../sdlpp
$(MAKE) clean -C ../sdlpp
$(MAKE) -C ../sdlpp

View File

@ -4,6 +4,17 @@
#include "sprites.hpp"
#include <unordered_map>
MarioBlock::MarioBlock(int x, int y, std::shared_ptr<SDLPP::Renderer> renderer, std::shared_ptr<SDLPP::Texture> texture, SDL_Rect src) : RectangleRender( x * BLOCK_SIZE, 1 - (16-y) * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, renderer, texture, src ) {}
void MarioBlock::visit( SDLPP::Visitor &visitor ) {
if(!_tool && visitor.getVisitorType() == TOOL_VISITOR_TYPE) {
destroy();
}
visitor.visit(*this);
}
void MarioBlock::setTool(bool tool) {
_tool = tool;
}
const std::vector< uint64_t > possibleBlocks = { FLOOR_ID,
HILL_INCLINE_ID,
HILL_DECLINE_ID,
@ -33,11 +44,10 @@ const std::unordered_map<uint64_t, const SDL_Rect*> block_mapping = {
};
std::shared_ptr< SDLPP::RectangleRender >
createBlock( std::shared_ptr< SDLPP::Renderer > &renderer, double x, double y,
createBlock( std::shared_ptr< SDLPP::Renderer > &renderer, int x, int y,
std::shared_ptr< SDLPP::Texture > &texture, const SDL_Rect &src,
uint64_t id, bool collision = false ) {
auto block = std::make_shared< SDLPP::RectangleRender >(
x, y, BLOCK_SIZE, BLOCK_SIZE, renderer, texture, src );
auto block = std::make_shared<MarioBlock>(x, y, renderer, texture, src);
block->setId( id );
block->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
block->setStatic();
@ -70,7 +80,7 @@ SDL_Rect getSourceRectByID( uint64_t id, BlockType type ) {
}
return ret_src;
}
std::shared_ptr<SDLPP::RectangleRender> createTerrainBlock( uint64_t block_id, BlockType type, std::shared_ptr<SDLPP::Renderer> &renderer, double x, double y, std::shared_ptr<SDLPP::Texture> texture, bool collision ) {
std::shared_ptr<SDLPP::RectangleRender> createTerrainBlock( uint64_t block_id, BlockType type, std::shared_ptr<SDLPP::Renderer> &renderer, int x, int y, std::shared_ptr<SDLPP::Texture> texture, bool collision ) {
return createBlock( renderer, x, y, texture,
getSourceRectByID( block_id, type ), block_id,
collision );
@ -81,8 +91,8 @@ std::shared_ptr<SDLPP::RectangleRender> createTerrainBlock( uint64_t block_id, B
std::shared_ptr< SDLPP::RectangleRender >
createTerrainBlock( uint64_t block_id, BlockType type,
std::shared_ptr< SDLPP::Renderer > &renderer, double x,
double y, bool collision ) {
std::shared_ptr< SDLPP::Renderer > &renderer, int x,
int y, bool collision ) {
return createTerrainBlock(block_id, type, renderer, x, y, g_terrain_texture, collision);
}
@ -93,7 +103,7 @@ createTerrainBlock( uint64_t block_id, BlockType type,
return createTerrainBlock(block_id, type, renderer, g_terrain_texture, collision);
}
std::shared_ptr<SDLPP::RectangleRender> createMario( BlockType type, std::shared_ptr<SDLPP::Renderer> &renderer, double x, double y ) {
std::shared_ptr<SDLPP::RectangleRender> createMario( BlockType type, std::shared_ptr<SDLPP::Renderer> &renderer, int x, int y ) {
//TODO add type additions
return createBlock( renderer, x, y, g_mario_texture, MARIO_STANDING_SRC, MARIO_ID, true );
}

View File

@ -4,6 +4,15 @@
#include "../sdlpp/sdlpp_rectrenderer.hpp"
#include <memory>
class MarioBlock : public SDLPP::RectangleRender {
public:
MarioBlock(int x, int y, std::shared_ptr<SDLPP::Renderer> renderer, std::shared_ptr<SDLPP::Texture> texture, SDL_Rect src);
void visit( SDLPP::Visitor &visitor ) override;
void setTool(bool tool = true);
private:
bool _tool = false;
};
extern const std::vector<uint64_t> possibleBlocks;
enum BlockType {
@ -14,9 +23,9 @@ enum BlockType {
};
std::shared_ptr<SDLPP::RectangleRender> createTerrainBlock( uint64_t block_id, BlockType type, std::shared_ptr<SDLPP::Renderer> &renderer, bool collision = false );
std::shared_ptr<SDLPP::RectangleRender> createTerrainBlock( uint64_t block_id, BlockType type, std::shared_ptr<SDLPP::Renderer> &renderer, double x, double y, bool collision = false );
std::shared_ptr<SDLPP::RectangleRender> createTerrainBlock( uint64_t block_id, BlockType type, std::shared_ptr<SDLPP::Renderer> &renderer, int x, int y, bool collision = false );
std::shared_ptr<SDLPP::RectangleRender> createTerrainBlock( uint64_t block_id, BlockType type, std::shared_ptr<SDLPP::Renderer> &renderer, std::shared_ptr<SDLPP::Texture> texture, bool collision = false );
std::shared_ptr<SDLPP::RectangleRender> createTerrainBlock( uint64_t block_id, BlockType type, std::shared_ptr<SDLPP::Renderer> &renderer, double x, double y, std::shared_ptr<SDLPP::Texture> texture, bool collision = false );
std::shared_ptr<SDLPP::RectangleRender> createMario( BlockType type, std::shared_ptr<SDLPP::Renderer> &renderer, double x, double y );
std::shared_ptr<SDLPP::RectangleRender> createTerrainBlock( uint64_t block_id, BlockType type, std::shared_ptr<SDLPP::Renderer> &renderer, int x, int y, std::shared_ptr<SDLPP::Texture> texture, bool collision = false );
std::shared_ptr<SDLPP::RectangleRender> createMario( BlockType type, std::shared_ptr<SDLPP::Renderer> &renderer, int x, int y );
#endif

19
mario/edit_box.cpp Normal file
View File

@ -0,0 +1,19 @@
#include "edit_box.hpp"
EditBox::EditBox(int x, int y, std::shared_ptr<SDLPP::Renderer> renderer) : SDLPP::RectangleRender(BLOCK_SIZE + x*BLOCK_SIZE, 4*BLOCK_SIZE + y*BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, renderer) {
_x = x;
_y = y;
setId(EDITOR_EDIT_SQUARE);
setColiderColor("#FF00AA");
setPermanent();
setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
addCollision(SDLPP::RectColider(0,0,1,1));
}
SDLPP::Vec2D<int> EditBox::getIndexes() const {
return {_x, _y};
}
void EditBox::visit( SDLPP::Visitor &visitor ) {
visitor.visit( *this );
}

14
mario/edit_box.hpp Normal file
View File

@ -0,0 +1,14 @@
#include "../sdlpp/sdlpp.hpp"
#include "objectids.hpp"
#include "blocks.hpp"
#include "sprites.hpp"
class EditBox : public SDLPP::RectangleRender {
public:
EditBox(int x, int y, std::shared_ptr<SDLPP::Renderer> renderer);
SDLPP::Vec2D<int> getIndexes() const;
void visit( SDLPP::Visitor &visitor ) override;
private:
int _x;
int _y;
};

View File

@ -10,47 +10,27 @@
#endif // UNIX
#include <thread>
#include <mutex>
#include "global_vars.hpp"
#include "objectids.hpp"
#include "blocks.hpp"
#include "maploader.hpp"
#include "../sdlpp/sdlpp_mouse.hpp"
#define EDIT_SQUARE 0xF001
#define MOUSE_ID 0xF002
#define LEFT_ID 0xF003
#define RIGHT_ID 0xF004
#include "edit_box.hpp"
#include "editor_visitor.hpp"
std::shared_ptr< SDLPP::Renderer > renderer = nullptr;
bool quit = false;
std::vector<std::array<std::tuple<uint8_t, uint16_t, uint8_t, uint8_t, uint8_t, uint8_t>,16>> objects = {};
bool update_size = false;
bool selected_left = false;
bool selected_right = false;
std::vector<std::array<std::tuple<uint8_t, uint16_t, uint8_t, uint8_t, uint8_t, uint8_t>,16>> objects = {};
uint64_t current_selected_flags = 0;
uint64_t previous_selected_flags = 0;
std::mutex destruction_mutex;
int current_start_index = 0;
int current_max_index = 0;
std::pair<int, int> current_box = {0, 0};
std::pair<int, int> backup_box = {0, 0};
std::shared_ptr<SDLPP::RenderObject> placeholderGround = nullptr;
class EditBox : public SDLPP::RectangleRender {
public:
EditBox(int x, int y, std::shared_ptr<SDLPP::Renderer> renderer) : SDLPP::RectangleRender(BLOCK_SIZE + x*BLOCK_SIZE, 4*BLOCK_SIZE + y*BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, renderer) {
_x = x;
_y = y;
setId(EDIT_SQUARE);
setColiderColor("#FF00AA");
setPermanent();
setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
addCollision(SDLPP::RectColider(0,0,1,1));
}
std::pair<int, int> getIndexes() {
return {_x, _y};
}
private:
int _x;
int _y;
};
SDLPP::Vec2D<int> current_box = {0, 0};
std::shared_ptr<SDLPP::RenderObject> current_tool = nullptr;
void handleKeyDown( SDL_Keycode key, SDLPP::Scene &scene ) {
switch ( key ) {
@ -107,59 +87,48 @@ void pollEvents( SDLPP::Scene &scene ) {
}
break;
case SDL_MOUSEMOTION: {
auto mouse = scene.getObjects({MOUSE_ID})[0];
auto mouse = scene.getObjects({EDITOR_MOUSE_ID})[0];
mouse->setPos(SDLPP::Mouse::getMousePositionDouble(scene.getRenderer(), SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER));
auto collisions = scene.getCollisions(*mouse);
selected_left = false;
selected_right = false;
current_box = {-1, -1};
if(collisions.size() >= 2) {
for(auto &collision : collisions) {
if(collision.second->getId() == EDIT_SQUARE) {
current_box = dynamic_cast<EditBox&>(*collision.second).getIndexes();
placeholderGround->setPos(BLOCK_SIZE + current_box.first * BLOCK_SIZE, 4*BLOCK_SIZE + current_box.second * BLOCK_SIZE);
} else if (collision.second->getId() == LEFT_ID) {
selected_left = true;
} else if (collision.second->getId() == RIGHT_ID) {
selected_right = true;
}
}
MouseVisitor visitor;
scene.visitCollisions(*mouse, visitor);
current_selected_flags = visitor.getFlags();
current_box = visitor.getEditBoxIndexes();
if(visitor.foundEditBox()) {
current_tool->setPos(BLOCK_SIZE + current_box.getX() * BLOCK_SIZE, 4*BLOCK_SIZE + current_box.getY() * BLOCK_SIZE);
}
}
break;
case SDL_MOUSEBUTTONUP:
if(selected_left && current_start_index != 0) {
if(previous_selected_flags == current_selected_flags && MouseVisitor::moveMapLeft(current_selected_flags) && current_start_index != 0) {
current_start_index -= 1;
scene.moveEverything(BLOCK_SIZE, 0);
}
if(selected_right && current_start_index != current_max_index) {
if(previous_selected_flags == current_selected_flags && MouseVisitor::moveMapRight(current_selected_flags) && current_start_index != current_max_index) {
current_start_index += 1;
scene.moveEverything(-BLOCK_SIZE,0);
}
if(current_box == backup_box && current_box.first != -1) {
auto mouse = scene.getObjects({MOUSE_ID})[0];
mouse->setPos(SDLPP::Mouse::getMousePositionDouble(scene.getRenderer(), SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER));
auto collisions = scene.getCollisions(*mouse);
std::cout << "BOUT TO" << std::endl;
bool deleted = false;
for(auto &collision : collisions) {
if(collision.second->getId() == FLOOR_ID) {
std::cout << "DELETING" << std::endl;
collision.second->destroy();
objects[current_start_index + current_box.first][current_box.second] = {OVERWORLD, 0, 0, 0, 0, 0};
deleted = true;
break;
}
if(current_box.getX() != -1) {
std::lock_guard<std::mutex> lock(destruction_mutex);
ToolVisitor visitor;
visitor.setVisitorType(TOOL_VISITOR_TYPE);
scene.visitCollisions(*current_tool, visitor);
if(visitor.removeBlock()) {
// TODO check if modifier
objects[current_start_index + current_box.getX()][current_box.getY()] = {OVERWORLD, 0, 0, 0, 0, 0};
}
if(visitor.addBlock()) {
// TODO check if modifier
objects[current_start_index + current_box.getX()][current_box.getY()] = {OVERWORLD, current_tool->getId(), 0, 0, 0, 0};
auto obj = createTerrainBlock(current_tool->getId(), OVERWORLD, renderer, 1 + current_box.getX(), current_box.getY(), true);
obj->getCollisions()[0]->setId(EDITOR_TERRAIN_ID);
scene.addObject(obj);
scene.setZIndex(obj, 1);
}
if(deleted)
break;
std::cout << "ADDING" << std::endl;
objects[current_start_index + current_box.first][current_box.second] = {OVERWORLD, FLOOR_ID, 0, 0, 0, 0};
scene.addObject(createTerrainBlock(FLOOR_ID, OVERWORLD, renderer, BLOCK_SIZE + current_box.first * BLOCK_SIZE, 4*BLOCK_SIZE + current_box.second * BLOCK_SIZE, true));
}
break;
case SDL_MOUSEBUTTONDOWN:
backup_box = current_box;
previous_selected_flags = current_selected_flags;
break;
default:
break;
@ -227,7 +196,7 @@ int main() {
auto rectangle1 = std::make_shared< SDLPP::RectangleRender >(
0, 4 * BLOCK_SIZE, BLOCK_SIZE, 16 * BLOCK_SIZE, renderer, "#FFFFFF88", true);
rectangle1->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
rectangle1->setId(LEFT_ID);
rectangle1->setId(EDITOR_LEFT_MAP_ID);
rectangle1->setPermanent();
rectangle1->addCollision(SDLPP::RectColider(0, 0, 1, 1));
scene->addObject(rectangle1);
@ -235,7 +204,7 @@ int main() {
auto rectangle2 = std::make_shared< SDLPP::RectangleRender >(
19*BLOCK_SIZE, 4 * BLOCK_SIZE, BLOCK_SIZE, 16 * BLOCK_SIZE, renderer, "#FFFFFF88", true);
rectangle2->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
rectangle2->setId(RIGHT_ID);
rectangle2->setId(EDITOR_RIGHT_MAP_ID);
rectangle2->setPermanent();
rectangle2->addCollision(SDLPP::RectColider(0, 0, 1, 1));
scene->addObject(rectangle2);
@ -245,13 +214,13 @@ int main() {
font, "#000000", "#282828", 0.05 );
auto left = std::make_shared< SDLPP::TextRenderer >(
0, 11.5 * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, renderer, "<", font_config);
left->setId(LEFT_ID);
left->setId(0);
left->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
left->setPermanent();
scene->addObject(left);
auto right = std::make_shared< SDLPP::TextRenderer >(
19*BLOCK_SIZE, 11.5 * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, renderer, ">", font_config);
right->setId(RIGHT_ID);
right->setId(0);
right->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
right->setPermanent();
scene->addObject(right);
@ -263,9 +232,11 @@ int main() {
}
auto mouse =
std::make_shared< SDLPP::RectangleRender >( 0.01, 0.01, 0.01, 0.01, renderer );
std::make_shared< SDLPP::RectangleRender >( 0.01, 0.01, 0, 0, renderer );
mouse->setMinWidth(1);
mouse->setMinHeight(1);
mouse->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
mouse->setId( MOUSE_ID );
mouse->setId( EDITOR_MOUSE_ID );
mouse->setColiderColor("#00FF00");
mouse->addCollision(
SDLPP::RectColider( { 0, 0 }, { 1, 1 } ) );
@ -274,11 +245,12 @@ int main() {
auto placeholder_texture = std::make_shared< SDLPP::Texture >(
renderer, "sprites/terrain.png", MARIO_OVERWORLD_COLORKEY );
placeholderGround = createTerrainBlock(FLOOR_ID, OVERWORLD, renderer, placeholder_texture, true);
placeholderGround->setTextureAlpha(100);
placeholderGround->setId(0);
scene->addObject(placeholderGround);
scene->moveZTop(placeholderGround);
current_tool = createTerrainBlock(FLOOR_ID, OVERWORLD, renderer, placeholder_texture, false);
current_tool->addCollision(SDLPP::RectColider(0.1, 0.1, 0.8, 0.8));
current_tool->setTextureAlpha(100);
dynamic_cast<MarioBlock&>(*current_tool).setTool();
scene->addObject(current_tool);
scene->moveZTop(current_tool);
scene->moveEverything(BLOCK_SIZE, 0);
FPSmanager gFPS;
@ -292,6 +264,7 @@ int main() {
while ( !quit ) {
SDL_PumpEvents();
SDL_framerateDelay( &gFPS );
std::lock_guard<std::mutex> lock(destruction_mutex);
scene->renderScene();
renderer->presentRenderer();
frames++;

56
mario/editor_visitor.cpp Normal file
View File

@ -0,0 +1,56 @@
#include "editor_visitor.hpp"
#include "../sdlpp/sdlpp_renderobject.hpp"
#include "objectids.hpp"
#include "edit_box.hpp"
#define SELECTED_LEFT_MAP 0x00000001
#define SELECTED_RIGHT_MAP 0x00000002
#define SELECTED_LEFT_SELECT 0x00000004
#define SELECTED_RIGHT_SELECT 0x00000004
#define SELECTED_REMOVE_BLOCK 0x00000008
#define SELECTED_REMOVE_MODIFIER 0x00000010
void MouseVisitor::visit( const SDLPP::RenderObject &obj ) {
auto id = obj.getId();
switch ( id ) {
case EDITOR_LEFT_MAP_ID:
select_flags |= SELECTED_LEFT_MAP;
break;
case EDITOR_RIGHT_MAP_ID:
select_flags |= SELECTED_RIGHT_MAP;
break;
case EDITOR_EDIT_SQUARE:
edit_box = true;
edit_box_location = dynamic_cast<const EditBox&>(obj).getIndexes();
break;
default:
break;
}
}
bool MouseVisitor::moveMapLeft(uint64_t flags) {
return flags & SELECTED_LEFT_MAP;
}
bool MouseVisitor::moveMapRight(uint64_t flags) {
return flags & SELECTED_RIGHT_MAP;
}
void ToolVisitor::visit( const SDLPP::RenderObject &obj ) {
auto id = obj.getCollisions()[0]->getId();
switch ( id ) {
case EDITOR_TERRAIN_ID:
remove_block = true;
if(obj.getId() == source_id) {
add_block = false;
}
default:
break;
}
}
bool ToolVisitor::addBlock() {
return add_block;
}
bool ToolVisitor::removeBlock() {
return remove_block;
}

66
mario/editor_visitor.hpp Normal file
View File

@ -0,0 +1,66 @@
#ifndef EDITOR_VISITOR_H
#define EDITOR_VISITOR_H
#include "../sdlpp/sdlpp_visitor.hpp"
#include "../sdlpp/sdlpp_geometry.hpp"
#include <memory>
class MouseVisitor : public SDLPP::Visitor {
public:
MouseVisitor() {}
virtual void visit( const SDLPP::RenderObject &obj ) override;
virtual void setFromId( uint64_t /*UNUSED*/ ) override {}
virtual uint64_t getFromId() override {return 0;}
uint64_t getFlags() {
return select_flags;
}
bool foundEditBox() {
return edit_box;
}
SDLPP::Vec2D<int> getEditBoxIndexes() {
return edit_box_location;
}
virtual void setVisitorType( uint64_t type ) override {
_type = type;
}
virtual uint64_t getVisitorType() override {
return _type;
}
static bool moveMapLeft(uint64_t flags);
static bool moveMapRight(uint64_t flags);
private:
uint64_t select_flags = 0;
bool edit_box = false;
SDLPP::Vec2D<int> edit_box_location = {-1, -1};
uint64_t _type;
};
class ToolVisitor : public SDLPP::Visitor {
public:
ToolVisitor() {};
virtual void visit( const SDLPP::RenderObject &obj ) override;
virtual void setFromId( uint64_t id ) override {
source_id = id;
}
virtual uint64_t getFromId() override {
return source_id;
}
virtual void setVisitorType( uint64_t type ) override {
_type = type;
}
virtual uint64_t getVisitorType() override {
return _type;
}
bool addBlock();
bool removeBlock();
private:
bool remove_block = false;
bool add_block = true;
uint64_t source_id = 0;
uint64_t _type = 0;
};
#endif

View File

@ -38,7 +38,7 @@ void loadMap(std::shared_ptr<SDLPP::Scene> &scene, std::shared_ptr<SDLPP::Rectan
collision = true;
}
// TODO add modifiers to createTerrainBlock
auto obj = createTerrainBlock(id, static_cast<BlockType>(type), renderer, i * BLOCK_SIZE, 1 - (16-j) * BLOCK_SIZE, collision);
auto obj = createTerrainBlock(id, static_cast<BlockType>(type), renderer, i, j, collision);
if(obj != nullptr)
scene->addObject(obj);
if(character) {
@ -51,6 +51,7 @@ void loadMap(std::shared_ptr<SDLPP::Scene> &scene, std::shared_ptr<SDLPP::Rectan
scene->moveZTop(mario);
}
// editor loader
void loadMap(std::shared_ptr<SDLPP::Scene> &scene, const std::string &file, std::shared_ptr<SDLPP::Renderer> &renderer, std::vector<std::array<std::tuple<uint8_t, uint16_t, uint8_t, uint8_t, uint8_t, uint8_t>,16>> &objects) {
std::ifstream map_file;
map_file.open(file, std::ios::in | std::ios::binary);
@ -81,17 +82,13 @@ void loadMap(std::shared_ptr<SDLPP::Scene> &scene, const std::string &file, std:
}
}
col[j] = {type, id, character_type, character, modifier_type, modifier_data};
bool collision = false;
if(id == FLOOR_ID) {
collision = true;
}
// TODO add modifiers to createTerrainBlock
auto obj = createTerrainBlock(id, static_cast<BlockType>(type), renderer, i * BLOCK_SIZE, 1 - (16-j) * BLOCK_SIZE, collision);
if(obj != nullptr)
scene->addObject(obj);
auto obj = createTerrainBlock(id, static_cast<BlockType>(type), renderer, i, j, true);
obj->getCollisions()[0]->setId(EDITOR_TERRAIN_ID);
scene->addObject(obj);
if(character) {
if(character == MARIO_ID) {
scene->addObject(createMario(static_cast<BlockType>(character_type), renderer, i * BLOCK_SIZE, 1 - (16-j) * BLOCK_SIZE));
scene->addObject(createMario(static_cast<BlockType>(character_type), renderer, i, j));
}
}
}

View File

@ -20,9 +20,18 @@ public:
double newXPos() {
return newX;
}
virtual void fromId( uint64_t id ) override {
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;
}
@ -38,6 +47,7 @@ private:
uint64_t from = -1;
bool left = false;
bool right = false;
uint64_t _type = 0;
};
#endif

View File

@ -29,4 +29,14 @@
#define MARIO_LEFT_SIDE_DETECT 0x2002
#define MARIO_RIGHT_SIDE_DETECT 0x2003
#define EDITOR_EDIT_SQUARE 0xF001
#define EDITOR_MOUSE_ID 0xF002
#define EDITOR_LEFT_MAP_ID 0xF003
#define EDITOR_RIGHT_MAP_ID 0xF004
#define EDITOR_TERRAIN_ID 0xF005
#define TOOL_VISITOR_TYPE 0xE001
#define MOUSE_VISITOR_TYPE 0xE002
#define MARIO_VISITOR_TYPE 0xE003
#endif