Mario: formatting
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
zv0n 2021-10-18 09:08:35 +02:00
parent f3062464d2
commit 8ca70fa11e
19 changed files with 1262 additions and 1250 deletions

View File

@ -21,8 +21,8 @@ MarioBlock::MarioBlock( int x, int y,
const std::shared_ptr<SDLPP::Renderer> &renderer, const std::shared_ptr<SDLPP::Renderer> &renderer,
std::shared_ptr<SDLPP::Texture> texture, SDL_Rect src, std::shared_ptr<SDLPP::Texture> texture, SDL_Rect src,
bool can_be_destroyed, bool destructible) bool can_be_destroyed, bool destructible)
: RectangleRender( x * BLOCK_SIZE, 1 - ( 16 - y ) * BLOCK_SIZE, : RectangleRender(x * BLOCK_SIZE, 1 - (16 - y) * BLOCK_SIZE, BLOCK_SIZE,
BLOCK_SIZE, BLOCK_SIZE, renderer, texture, src ) { BLOCK_SIZE, renderer, texture, src) {
_can_be_destroyed = can_be_destroyed; _can_be_destroyed = can_be_destroyed;
_destructible = can_be_destroyed && destructible; _destructible = can_be_destroyed && destructible;
setMovementSpeed(1); setMovementSpeed(1);
@ -53,7 +53,8 @@ void MarioBlock::visit( SDLPP::Visitor &visitor ) {
setPos(getPos() - SDLPP::Vec2D<double>(0, BLOCK_SIZE)); setPos(getPos() - SDLPP::Vec2D<double>(0, BLOCK_SIZE));
if (getCollisions().size() < 2) if (getCollisions().size() < 2)
addCollision( SDLPP::RectColider( 0.1, 0.1, 0.8, 0.8, BOUNCE_COLLISION ) ); addCollision(
SDLPP::RectColider(0.1, 0.1, 0.8, 0.8, BOUNCE_COLLISION));
updateSizeAndPosition(); updateSizeAndPosition();
g_playground->visitCollisions(*this, bv); g_playground->visitCollisions(*this, bv);
setPos(getPos() + SDLPP::Vec2D<double>(0, BLOCK_SIZE)); setPos(getPos() + SDLPP::Vec2D<double>(0, BLOCK_SIZE));
@ -63,7 +64,8 @@ void MarioBlock::visit( SDLPP::Visitor &visitor ) {
} }
if (hasCoin()) { if (hasCoin()) {
removeCoin(); removeCoin();
auto coin = createTerrainBlock(COIN_ID, LandType::OVERWORLD, renderer); auto coin =
createTerrainBlock(COIN_ID, LandType::OVERWORLD, renderer);
coin->setPos(getPos()); coin->setPos(getPos());
std::dynamic_pointer_cast<CoinBlock>(coin)->setParent(this); std::dynamic_pointer_cast<CoinBlock>(coin)->setParent(this);
dynamic_cast<MarioVisitor &>(visitor).setCoin(); dynamic_cast<MarioVisitor &>(visitor).setCoin();
@ -71,7 +73,8 @@ void MarioBlock::visit( SDLPP::Visitor &visitor ) {
} }
if (hasMushroom()) { if (hasMushroom()) {
removeMushroom(); removeMushroom();
auto mushroom = createTerrainBlock(MUSHROOM_ID, LandType::OVERWORLD, renderer); auto mushroom =
createTerrainBlock(MUSHROOM_ID, LandType::OVERWORLD, renderer);
mushroom->setPos(getPos()); mushroom->setPos(getPos());
std::dynamic_pointer_cast<MushroomBlock>(mushroom)->setParent(this); std::dynamic_pointer_cast<MushroomBlock>(mushroom)->setParent(this);
dynamic_cast<MarioVisitor &>(visitor).setMushroomBlock(mushroom); dynamic_cast<MarioVisitor &>(visitor).setMushroomBlock(mushroom);
@ -158,14 +161,12 @@ void MarioBlock::custom_move( int ticks ) {
} }
} }
if (_traveling) { if (_traveling) {
bool overshot_x = (getMovement().getX() < 0 && bool overshot_x =
getPos().getX() <= _target.getX()) || (getMovement().getX() < 0 && getPos().getX() <= _target.getX()) ||
(getMovement().getX() > 0 && (getMovement().getX() > 0 && getPos().getX() >= _target.getX());
getPos().getX() >= _target.getX()); bool overshot_y =
bool overshot_y = (getMovement().getY() < 0 && (getMovement().getY() < 0 && getPos().getY() <= _target.getY()) ||
getPos().getY() <= _target.getY()) || (getMovement().getY() > 0 && getPos().getY() >= _target.getY());
(getMovement().getY() > 0 &&
getPos().getY() >= _target.getY());
if (overshot_x) { if (overshot_x) {
setPos(_target.getX(), getPos().getY()); setPos(_target.getX(), getPos().getY());
setMovement(0, getMovement().getY()); setMovement(0, getMovement().getY());
@ -469,18 +470,15 @@ createBlockById( uint64_t id, int x, int y,
break; break;
case SIDEWAY_PIPE_MIDDLE_BOTTOM_ID: case SIDEWAY_PIPE_MIDDLE_BOTTOM_ID:
result = std::static_pointer_cast<MarioBlock>( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< SidewayPipeMiddleBottomBlock >( x, y, std::make_shared<SidewayPipeMiddleBottomBlock>(x, y, renderer));
renderer ) );
break; break;
case SIDEWAY_PIPE_CONNECTOR_TOP_ID: case SIDEWAY_PIPE_CONNECTOR_TOP_ID:
result = std::static_pointer_cast<MarioBlock>( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< SidewayPipeConnectorTopBlock >( x, y, std::make_shared<SidewayPipeConnectorTopBlock>(x, y, renderer));
renderer ) );
break; break;
case SIDEWAY_PIPE_CONNECTOR_BOTTOM_ID: case SIDEWAY_PIPE_CONNECTOR_BOTTOM_ID:
result = std::static_pointer_cast<MarioBlock>( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< SidewayPipeConnectorBottomBlock >( x, y, std::make_shared<SidewayPipeConnectorBottomBlock>(x, y, renderer));
renderer ) );
break; break;
case TREE_PLATFORM_TOP_LEFT_ID: case TREE_PLATFORM_TOP_LEFT_ID:
result = std::static_pointer_cast<MarioBlock>( result = std::static_pointer_cast<MarioBlock>(
@ -508,28 +506,23 @@ createBlockById( uint64_t id, int x, int y,
break; break;
case MUSHROOM_PLATFORM_TOP_LEFT_ID: case MUSHROOM_PLATFORM_TOP_LEFT_ID:
result = std::static_pointer_cast<MarioBlock>( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< MushroomPlatformTopLeftBlock >( x, y, std::make_shared<MushroomPlatformTopLeftBlock>(x, y, renderer));
renderer ) );
break; break;
case MUSHROOM_PLATFORM_TOP_MIDDLE_ID: case MUSHROOM_PLATFORM_TOP_MIDDLE_ID:
result = std::static_pointer_cast<MarioBlock>( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< MushroomPlatformTopMiddleBlock >( x, y, std::make_shared<MushroomPlatformTopMiddleBlock>(x, y, renderer));
renderer ) );
break; break;
case MUSHROOM_PLATFORM_TOP_RIGHT_ID: case MUSHROOM_PLATFORM_TOP_RIGHT_ID:
result = std::static_pointer_cast<MarioBlock>( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< MushroomPlatformTopRightBlock >( x, y, std::make_shared<MushroomPlatformTopRightBlock>(x, y, renderer));
renderer ) );
break; break;
case MUSHROOM_PLATFORM_BARK_TOP_ID: case MUSHROOM_PLATFORM_BARK_TOP_ID:
result = std::static_pointer_cast<MarioBlock>( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< MushroomPlatformBarkTopBlock >( x, y, std::make_shared<MushroomPlatformBarkTopBlock>(x, y, renderer));
renderer ) );
break; break;
case MUSHROOM_PLATFORM_BARK_BOTTOM_ID: case MUSHROOM_PLATFORM_BARK_BOTTOM_ID:
result = std::static_pointer_cast<MarioBlock>( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< MushroomPlatformBarkBottomBlock >( x, y, std::make_shared<MushroomPlatformBarkBottomBlock>(x, y, renderer));
renderer ) );
break; break;
case TREE_BARK_ID: case TREE_BARK_ID:
result = std::static_pointer_cast<MarioBlock>( result = std::static_pointer_cast<MarioBlock>(
@ -662,12 +655,14 @@ void MarioBlock::setBaseRect(SDL_Rect rect) {
_base_src = rect; _base_src = rect;
setType(getType()); setType(getType());
} }
void MarioBlock::checkVisibility(double rightmost_x) { void MarioBlock::checkVisibility(double rightmost_x) {
// we assume that object's X > 0 as otherwise it would be destroyed // we assume that object's X > 0 as otherwise it would be destroyed
if (!getHidden() && getAbsolutePos().getX() < rightmost_x) { if (!getHidden() && getAbsolutePos().getX() < rightmost_x) {
_was_visible = true; _was_visible = true;
} }
} }
bool MarioBlock::wasVisible() const { bool MarioBlock::wasVisible() const {
return _was_visible; return _was_visible;
} }

View File

@ -11,8 +11,7 @@ struct LandType {
class MarioBlock : public SDLPP::RectangleRender { class MarioBlock : public SDLPP::RectangleRender {
public: public:
MarioBlock( int x, int y, MarioBlock(int x, int y, const std::shared_ptr<SDLPP::Renderer> &renderer,
const std::shared_ptr< SDLPP::Renderer > &renderer,
std::shared_ptr<SDLPP::Texture> texture, SDL_Rect src, std::shared_ptr<SDLPP::Texture> texture, SDL_Rect src,
bool can_be_destroyed = false, bool destructible = false); bool can_be_destroyed = false, bool destructible = false);
void visit(SDLPP::Visitor &visitor) override; void visit(SDLPP::Visitor &visitor) override;

View File

@ -3,7 +3,11 @@
#include "blocks.hpp" #include "blocks.hpp"
#include "sprites.hpp" #include "sprites.hpp"
EditBox::EditBox(int x, int y, float start_x, float start_y, int map_width, int map_height, std::shared_ptr<SDLPP::Renderer> renderer) : SDLPP::RectangleRender(start_x + x*BLOCK_SIZE, start_y + y*BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, renderer) { EditBox::EditBox(int x, int y, float start_x, float start_y, int map_width,
int map_height, std::shared_ptr<SDLPP::Renderer> renderer)
: SDLPP::RectangleRender(start_x + x * BLOCK_SIZE,
start_y + y * BLOCK_SIZE, BLOCK_SIZE,
BLOCK_SIZE, renderer) {
_x = x; _x = x;
_y = y; _y = y;
setId(EDITOR_EDIT_SQUARE); setId(EDITOR_EDIT_SQUARE);

View File

@ -5,9 +5,11 @@
class EditBox : public SDLPP::RectangleRender { class EditBox : public SDLPP::RectangleRender {
public: public:
EditBox(int x, int y, float start_x, float start_y, int map_width, int map_height, std::shared_ptr<SDLPP::Renderer> renderer); EditBox(int x, int y, float start_x, float start_y, int map_width,
int map_height, std::shared_ptr<SDLPP::Renderer> renderer);
virtual SDLPP::Vec2D<int> getIndexes() const; virtual SDLPP::Vec2D<int> getIndexes() const;
virtual void visit(SDLPP::Visitor &visitor) override; virtual void visit(SDLPP::Visitor &visitor) override;
private: private:
int _x; int _x;
int _y; int _y;

View File

@ -123,19 +123,23 @@ void updateTool() {
switch (tool_role) { switch (tool_role) {
case BlockRole::TERRAIN: case BlockRole::TERRAIN:
target_texture = global_vars.translucent_terrain_texture; target_texture = global_vars.translucent_terrain_texture;
target_src = global_vars.tools[global_vars.tool.index]->getTextureSourceRect(); target_src =
global_vars.tools[global_vars.tool.index]->getTextureSourceRect();
break; break;
case BlockRole::MARIO: case BlockRole::MARIO:
target_texture = global_vars.translucent_mario_texture; target_texture = global_vars.translucent_mario_texture;
target_src = global_vars.characters[global_vars.tool.index]->getTextureSourceRect(); target_src = global_vars.characters[global_vars.tool.index]
->getTextureSourceRect();
break; break;
case BlockRole::MODIFIER: case BlockRole::MODIFIER:
target_texture = global_vars.translucent_mod_texture; target_texture = global_vars.translucent_mod_texture;
target_src = global_vars.mods[global_vars.tool.index]->getTextureSourceRect(); target_src =
global_vars.mods[global_vars.tool.index]->getTextureSourceRect();
break; break;
case BlockRole::CHARACTER: case BlockRole::CHARACTER:
target_texture = global_vars.translucent_enemies_texture; target_texture = global_vars.translucent_enemies_texture;
target_src = global_vars.characters[global_vars.tool.index]->getTextureSourceRect(); target_src = global_vars.characters[global_vars.tool.index]
->getTextureSourceRect();
break; break;
} }
global_vars.current_tool->setHidden(true); global_vars.current_tool->setHidden(true);
@ -375,8 +379,7 @@ void selectPrevTool() {
if (global_vars.tool.index % multiplier == 0) { if (global_vars.tool.index % multiplier == 0) {
subtraction = multiplier + 1; subtraction = multiplier + 1;
} }
if ( global_vars.tool.index == 0 || if (global_vars.tool.index == 0 || global_vars.tool.index - subtraction >
global_vars.tool.index - subtraction >
static_cast<uint64_t>(-multiplier)) { static_cast<uint64_t>(-multiplier)) {
return; return;
} }
@ -533,14 +536,12 @@ void mouseUpAction( uint64_t flags, SDLPP::Scene &scene ) {
if (MouseVisitor::moveModsLeft(flags) && if (MouseVisitor::moveModsLeft(flags) &&
global_vars.tool.cur_page_mods != 0) { global_vars.tool.cur_page_mods != 0) {
global_vars.tool.cur_page_mods--; global_vars.tool.cur_page_mods--;
updateToolSelection( global_vars.tool.cur_page_mods + 1, updateToolSelection(global_vars.tool.cur_page_mods + 1, ToolType::MOD);
ToolType::MOD );
} }
if (MouseVisitor::moveModsRight(flags) && if (MouseVisitor::moveModsRight(flags) &&
global_vars.tool.cur_page_mods != global_vars.tool.max_page_mods) { global_vars.tool.cur_page_mods != global_vars.tool.max_page_mods) {
global_vars.tool.cur_page_mods++; global_vars.tool.cur_page_mods++;
updateToolSelection( global_vars.tool.cur_page_mods - 1, updateToolSelection(global_vars.tool.cur_page_mods - 1, ToolType::MOD);
ToolType::MOD );
} }
if (MouseVisitor::moveCharactersLeft(flags) && if (MouseVisitor::moveCharactersLeft(flags) &&
global_vars.tool.cur_page_characters != 0) { global_vars.tool.cur_page_characters != 0) {
@ -621,8 +622,7 @@ void placeTool( SDLPP::Scene &scene ) {
case VisitorType::Character: case VisitorType::Character:
if (tool_type == BlockRole::MARIO) { if (tool_type == BlockRole::MARIO) {
obj.setCharacter(MARIO_ID, global_vars.current_world_type); obj.setCharacter(MARIO_ID, global_vars.current_world_type);
new_obj = new_obj = createMario(global_vars.current_world_type, renderer,
createMario( global_vars.current_world_type, renderer,
global_vars.mouse.edit_box.getX(), global_vars.mouse.edit_box.getX(),
global_vars.mouse.edit_box.getY(), true); global_vars.mouse.edit_box.getY(), true);
// remove mario if exists // remove mario if exists
@ -632,11 +632,14 @@ void placeTool( SDLPP::Scene &scene ) {
new_obj->getCollisions()[0]->setId(EDITOR_CHARACTER_ID); new_obj->getCollisions()[0]->setId(EDITOR_CHARACTER_ID);
z_index = scene.getObjects().size() - 1; z_index = scene.getObjects().size() - 1;
} else { } else {
obj.setCharacter(global_vars.current_tool->getId(), global_vars.current_world_type); obj.setCharacter(global_vars.current_tool->getId(),
new_obj = createTerrainBlock(obj.getCharacterId(), obj.getCharacterType(), renderer, global_vars.mouse.edit_box.getX(), global_vars.mouse.edit_box.getY(), false, true); global_vars.current_world_type);
new_obj = createTerrainBlock(
obj.getCharacterId(), obj.getCharacterType(), renderer,
global_vars.mouse.edit_box.getX(),
global_vars.mouse.edit_box.getY(), false, true);
new_obj->getCollisions()[0]->setId(EDITOR_CHARACTER_ID); new_obj->getCollisions()[0]->setId(EDITOR_CHARACTER_ID);
dynamic_cast< MarioBlock * >( new_obj.get() ) dynamic_cast<MarioBlock *>(new_obj.get())->setTerrain(false);
->setTerrain( false );
z_index = scene.getObjects().size() - 1; z_index = scene.getObjects().size() - 1;
} }
break; break;
@ -647,13 +650,11 @@ void placeTool( SDLPP::Scene &scene ) {
obj.getModifierId(), LandType::OVERWORLD, renderer, obj.getModifierId(), LandType::OVERWORLD, renderer,
global_vars.mouse.edit_box.getX(), global_vars.mouse.edit_box.getX(),
global_vars.mouse.edit_box.getY(), false, true); global_vars.mouse.edit_box.getY(), false, true);
new_obj->setTextureKeepSRC( new_obj->setTextureKeepSRC(global_vars.translucent_mod_texture);
global_vars.translucent_mod_texture );
new_obj->setData(global_vars.current_tool->getData()); new_obj->setData(global_vars.current_tool->getData());
new_obj->getCollisions()[0]->setId(EDITOR_TERRAIN_ID); new_obj->getCollisions()[0]->setId(EDITOR_TERRAIN_ID);
// TODO createModifierBlock // TODO createModifierBlock
dynamic_cast< MarioBlock * >( new_obj.get() ) dynamic_cast<MarioBlock *>(new_obj.get())->setTerrain(false);
->setTerrain( false );
z_index = scene.getObjects().size() - 1; z_index = scene.getObjects().size() - 1;
break; break;
default: default:
@ -779,9 +780,9 @@ void createGrid( double start_x, double start_y, int count_x, int count_y,
std::pair<std::shared_ptr<SDLPP::TextRenderer>, std::pair<std::shared_ptr<SDLPP::TextRenderer>,
std::shared_ptr<SDLPP::TextRenderer>> std::shared_ptr<SDLPP::TextRenderer>>
createArrowControls( createArrowControls(double left_x, double right_x, double start_y,
double left_x, double right_x, double start_y, double height, double height, uint64_t left_id, uint64_t right_id,
uint64_t left_id, uint64_t right_id, std::shared_ptr< SDLPP::Scene > &scene, std::shared_ptr<SDLPP::Scene> &scene,
std::shared_ptr<SDLPP::FontConfiguration> &font_config) { std::shared_ptr<SDLPP::FontConfiguration> &font_config) {
auto renderer = scene->getRendererShared(); auto renderer = scene->getRendererShared();
// white rectangles // white rectangles
@ -838,20 +839,18 @@ void populateToolGrid(
switch (type) { switch (type) {
case ToolType::CHARACTER: case ToolType::CHARACTER:
if (block == MARIO_ID) { if (block == MARIO_ID) {
tool_store.push_back( createMario( tool_store.push_back(createMario(global_vars.current_world_type,
global_vars.current_world_type, renderer, 0, 0, true ) ); renderer, 0, 0, true));
break; break;
} }
// fall through // fall through
case ToolType::MOD: case ToolType::MOD:
tool_store.push_back( tool_store.push_back(createTerrainBlock(
createTerrainBlock( block, global_vars.current_world_type, block, global_vars.current_world_type, renderer, false, true));
renderer, false, true ) );
break; break;
case ToolType::BLOCK: case ToolType::BLOCK:
tool_store.push_back( tool_store.push_back(createTerrainBlock(
createTerrainBlock( block, global_vars.current_world_type, block, global_vars.current_world_type, renderer, false, true));
renderer, false, true ) );
break; break;
default: default:
break; break;
@ -877,9 +876,8 @@ void populateToolGrid(
} }
} }
auto tool_text = std::make_shared<SDLPP::TextRenderer>( auto tool_text = std::make_shared<SDLPP::TextRenderer>(
start_x - BLOCK_SIZE, start_y - BLOCK_SIZE, start_x - BLOCK_SIZE, start_y - BLOCK_SIZE, (count_x + 2) * BLOCK_SIZE,
( count_x + 2 ) * BLOCK_SIZE, BLOCK_SIZE, renderer, title, font_config, BLOCK_SIZE, renderer, title, font_config, SDLPP_TEXT_CENTER);
SDLPP_TEXT_CENTER );
tool_text->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER); tool_text->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
tool_text->setPermanent(); tool_text->setPermanent();
scene->addObject(tool_text); scene->addObject(tool_text);
@ -921,8 +919,7 @@ void checkArrowsEnabled( uint64_t cur_page, uint64_t max_page,
uint64_t left_flag, uint64_t right_flag, uint64_t left_flag, uint64_t right_flag,
std::shared_ptr<SDLPP::TextRenderer> &left_arrow, std::shared_ptr<SDLPP::TextRenderer> &left_arrow,
std::shared_ptr<SDLPP::TextRenderer> &right_arrow, std::shared_ptr<SDLPP::TextRenderer> &right_arrow,
std::shared_ptr< SDLPP::Font > &font, std::shared_ptr<SDLPP::Font> &font, bool map = false) {
bool map = false ) {
if (cur_page == 0 && getFlag(left_flag)) { if (cur_page == 0 && getFlag(left_flag)) {
setFlag(UPDATE_FLAG); setFlag(UPDATE_FLAG);
unsetFlag(left_flag); unsetFlag(left_flag);
@ -965,8 +962,8 @@ int main() {
auto font = std::make_shared<SDLPP::Font>("testfont.ttf", 36); auto font = std::make_shared<SDLPP::Font>("testfont.ttf", 36);
auto font_config = std::make_shared<SDLPP::FontConfiguration>( auto font_config = std::make_shared<SDLPP::FontConfiguration>(
font, "#000000", "#282828", 0.05); font, "#000000", "#282828", 0.05);
g_text_config = std::make_shared< SDLPP::FontConfiguration >( g_text_config = std::make_shared<SDLPP::FontConfiguration>(font, "#FFFFFF",
font, "#FFFFFF", "#000000", 0.15 ); "#000000", 0.15);
auto renderer = std::make_shared<SDLPP::Renderer>(w); auto renderer = std::make_shared<SDLPP::Renderer>(w);
renderer->setBlendMode(SDL_BLENDMODE_BLEND); renderer->setBlendMode(SDL_BLENDMODE_BLEND);
@ -1029,8 +1026,8 @@ int main() {
scene, "TERRAIN", font_config); scene, "TERRAIN", font_config);
arrows = createArrowControls( arrows = createArrowControls(
(MAP_WIDTH - TOOLS_WIDTH - 1) * BLOCK_SIZE, MAP_WIDTH * BLOCK_SIZE, (MAP_WIDTH - TOOLS_WIDTH - 1) * BLOCK_SIZE, MAP_WIDTH * BLOCK_SIZE,
1 - ( MAP_HEIGHT + 3 ) * BLOCK_SIZE, 2 * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, 2 * BLOCK_SIZE, EDITOR_LEFT_TOOL_ID,
EDITOR_LEFT_TOOL_ID, EDITOR_RIGHT_TOOL_ID, scene, font_config ); EDITOR_RIGHT_TOOL_ID, scene, font_config);
auto left_tool_arrow = arrows.first; auto left_tool_arrow = arrows.first;
auto right_tool_arrow = arrows.second; auto right_tool_arrow = arrows.second;
createGrid((MAP_WIDTH - TOOLS_WIDTH) * BLOCK_SIZE, createGrid((MAP_WIDTH - TOOLS_WIDTH) * BLOCK_SIZE,
@ -1040,38 +1037,36 @@ int main() {
1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, ToolType::MOD, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, ToolType::MOD,
possibleMods, global_vars.mods, global_vars.mod_boxes, possibleMods, global_vars.mods, global_vars.mod_boxes,
scene, "MODS", font_config); scene, "MODS", font_config);
arrows = createArrowControls( arrows = createArrowControls(4 * BLOCK_SIZE, (MOD_WIDTH + 5) * BLOCK_SIZE,
4 * BLOCK_SIZE, ( MOD_WIDTH + 5 ) * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE,
1 - ( MAP_HEIGHT + 3 ) * BLOCK_SIZE, 2 * BLOCK_SIZE, EDITOR_LEFT_MOD_ID, 2 * BLOCK_SIZE, EDITOR_LEFT_MOD_ID,
EDITOR_RIGHT_MOD_ID, scene, font_config); EDITOR_RIGHT_MOD_ID, scene, font_config);
auto left_mod_arrow = arrows.first; auto left_mod_arrow = arrows.first;
auto right_mod_arrow = arrows.second; auto right_mod_arrow = arrows.second;
createGrid( 5 * BLOCK_SIZE, 1 - ( MAP_HEIGHT + 3 ) * BLOCK_SIZE, MOD_WIDTH, createGrid(5 * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, MOD_WIDTH, 2,
2, scene ); scene);
// characters // characters
populateToolGrid(CHARACTER_WIDTH, 2, (MOD_WIDTH + 8) * BLOCK_SIZE, populateToolGrid(CHARACTER_WIDTH, 2, (MOD_WIDTH + 8) * BLOCK_SIZE,
1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, ToolType::CHARACTER, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, ToolType::CHARACTER,
possibleCharacters, global_vars.characters, possibleCharacters, global_vars.characters,
global_vars.character_boxes, scene, "CHARACTERS", global_vars.character_boxes, scene, "CHARACTERS",
font_config); font_config);
arrows = arrows = createArrowControls((MOD_WIDTH + 7) * BLOCK_SIZE,
createArrowControls( ( MOD_WIDTH + 7 ) * BLOCK_SIZE,
(MOD_WIDTH + 8 + CHARACTER_WIDTH) * BLOCK_SIZE, (MOD_WIDTH + 8 + CHARACTER_WIDTH) * BLOCK_SIZE,
1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE,
2 * BLOCK_SIZE, EDITOR_LEFT_CHARACTER_ID, 2 * BLOCK_SIZE, EDITOR_LEFT_CHARACTER_ID,
EDITOR_RIGHT_CHARACTER_ID, scene, font_config); EDITOR_RIGHT_CHARACTER_ID, scene, font_config);
auto left_char_arrow = arrows.first; auto left_char_arrow = arrows.first;
auto right_char_arrow = arrows.second; auto right_char_arrow = arrows.second;
createGrid( ( MOD_WIDTH + 8 ) * BLOCK_SIZE, createGrid((MOD_WIDTH + 8) * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE,
1 - ( MAP_HEIGHT + 3 ) * BLOCK_SIZE, CHARACTER_WIDTH, 2, CHARACTER_WIDTH, 2, scene);
scene );
// world type // world type
populateWorldType(OVERWORLD_WIDTH, 2, BLOCK_SIZE, populateWorldType(OVERWORLD_WIDTH, 2, BLOCK_SIZE,
1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, scene, "WORLD", 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, scene, "WORLD",
font_config); font_config);
createGrid( BLOCK_SIZE, 1 - ( MAP_HEIGHT + 3 ) * BLOCK_SIZE, createGrid(BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, OVERWORLD_WIDTH,
OVERWORLD_WIDTH, 2, scene ); 2, scene);
global_vars.map.max_page = global_vars.objects.size() - MAP_WIDTH; global_vars.map.max_page = global_vars.objects.size() - MAP_WIDTH;
@ -1082,8 +1077,8 @@ int main() {
global_vars.tool.max_page_characters = global_vars.tool.max_page_characters =
(possibleCharacters.size() - 1) / (2 * CHARACTER_WIDTH); (possibleCharacters.size() - 1) / (2 * CHARACTER_WIDTH);
auto mouse = std::make_shared< SDLPP::RectangleRender >( 0.01, 0.01, 0, 0, auto mouse =
renderer ); std::make_shared<SDLPP::RectangleRender>(0.01, 0.01, 0, 0, renderer);
mouse->setMinWidth(1); mouse->setMinWidth(1);
mouse->setMinHeight(1); mouse->setMinHeight(1);
mouse->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER); mouse->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
@ -1110,8 +1105,7 @@ int main() {
COIN_MODIFIER_ID, LandType::OVERWORLD, renderer, 0, 0, false, true); COIN_MODIFIER_ID, LandType::OVERWORLD, renderer, 0, 0, false, true);
global_vars.coin_tool->setData(1); global_vars.coin_tool->setData(1);
global_vars.coin_tool->removeCollisions(); global_vars.coin_tool->removeCollisions();
global_vars.coin_tool->addCollision( global_vars.coin_tool->addCollision(SDLPP::RectColider(0.1, 0.1, 0.8, 0.8));
SDLPP::RectColider( 0.1, 0.1, 0.8, 0.8 ) );
global_vars.translucent_mod_texture = g_translucent_mod_texture; global_vars.translucent_mod_texture = g_translucent_mod_texture;
global_vars.translucent_enemies_texture = g_translucent_enemies_texture; global_vars.translucent_enemies_texture = g_translucent_enemies_texture;
dynamic_cast<MarioBlock &>(*global_vars.current_tool).setTool(); dynamic_cast<MarioBlock &>(*global_vars.current_tool).setTool();

View File

@ -97,16 +97,16 @@ void ToolVisitor::visit( const SDLPP::RenderObject &obj ) {
remove_block = true; remove_block = true;
if (obj.getId() == source_id && if (obj.getId() == source_id &&
((m_obj.getType() == source_type && ((m_obj.getType() == source_type &&
getVisitorType() == VisitorType::Terrain) || ( m_obj.getData() == _data && getVisitorType() == VisitorType::Modifier))) { getVisitorType() == VisitorType::Terrain) ||
(m_obj.getData() == _data &&
getVisitorType() == VisitorType::Modifier))) {
add_block = false; add_block = false;
} }
} } break;
break;
case EDITOR_CHARACTER_ID: { case EDITOR_CHARACTER_ID: {
const auto &m_obj = dynamic_cast<const MarioBlock &>(obj); const auto &m_obj = dynamic_cast<const MarioBlock &>(obj);
remove_block = true; remove_block = true;
if ( obj.getId() == source_id && if (obj.getId() == source_id && m_obj.getType() == source_type &&
m_obj.getType() == source_type &&
getVisitorType() == VisitorType::Character) { getVisitorType() == VisitorType::Character) {
add_block = false; add_block = false;
} }

View File

@ -92,7 +92,8 @@ void moveToMarioPosition( SDLPP::Scene &scene,
// sometimes there is a concurrency problem and prev_pos == cur_pos, in // sometimes there is a concurrency problem and prev_pos == cur_pos, in
// that case move everything so Mario is standing on the left edge of the // that case move everything so Mario is standing on the left edge of the
// screen // screen
if(mario_pos_difference.getX() < 0.01 && mario_pos_difference.getX() > -0.01) { if (mario_pos_difference.getX() < 0.01 &&
mario_pos_difference.getX() > -0.01) {
// 0.01 is the width of visible leftStop // 0.01 is the width of visible leftStop
scene.moveEverything(-(mario->getAbsolutePos().getX() - 0.01), 0); scene.moveEverything(-(mario->getAbsolutePos().getX() - 0.01), 0);
} else { } else {
@ -150,11 +151,12 @@ void doInput( std::shared_ptr< SDLPP::Scene > scene ) {
if (!moving_objects[i]->wasVisible()) { if (!moving_objects[i]->wasVisible()) {
continue; continue;
} }
auto visitor = auto visitor = getVisitor(*moving_objects[i], *scene, quit,
getVisitor( *moving_objects[i], *scene, quit, coin_count, moving_objects ); coin_count, moving_objects);
scene->visitCollisions(*moving_objects[i], *visitor); scene->visitCollisions(*moving_objects[i], *visitor);
moving_objects[i]->handleVisitor(*visitor); moving_objects[i]->handleVisitor(*visitor);
auto rightmost_pos = moving_objects[i]->getAbsolutePos().getX() + auto rightmost_pos =
moving_objects[i]->getAbsolutePos().getX() +
moving_objects[i]->getDoubleRect().second.getX(); moving_objects[i]->getDoubleRect().second.getX();
if (rightmost_pos < 0 && moving_objects[i] != mario) { if (rightmost_pos < 0 && moving_objects[i] != mario) {
moving_objects[i]->destroy(); moving_objects[i]->destroy();
@ -180,8 +182,7 @@ void doInput( std::shared_ptr< SDLPP::Scene > scene ) {
auto rightBarrier = width * 0.5; auto rightBarrier = width * 0.5;
auto rightmostX = auto rightmostX =
scene->rightmost()->getRect().x + scene->rightmost()->getRect().w; scene->rightmost()->getRect().x + scene->rightmost()->getRect().w;
scene->moveEverything( scene->moveEverything((playerX > rightBarrier && rightmostX > width) *
( playerX > rightBarrier && rightmostX > width ) *
(rightBarrier - playerX) / width, (rightBarrier - playerX) / width,
0); 0);
update = update || (playerX > rightBarrier && rightmostX > width); update = update || (playerX > rightBarrier && rightmostX > width);
@ -235,8 +236,8 @@ int main() {
scene->addObject(defeat); scene->addObject(defeat);
leftStop = std::make_shared< SDLPP::RectangleRender >( -0.1, 0, 0.11, 0, leftStop =
renderer ); std::make_shared<SDLPP::RectangleRender>(-0.1, 0, 0.11, 0, renderer);
leftStop->setId(STOP_MOVEMENT); leftStop->setId(STOP_MOVEMENT);
leftStop->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER); leftStop->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
leftStop->setPermanent(); leftStop->setPermanent();
@ -276,12 +277,15 @@ int main() {
update = true; update = true;
std::unordered_set<uint64_t> background_ids = { std::unordered_set<uint64_t> background_ids = {
HILL_INCLINE_ID, HILL_DECLINE_ID, HILL_DOTS_RIGHT_ID, HILL_DOTS_LEFT_ID, HILL_INCLINE_ID, HILL_DECLINE_ID, HILL_DOTS_RIGHT_ID,
HILL_FILL_ID, HILL_TOP_ID, BUSH_LEFT_ID, BUSH_MIDDLE_ID, BUSH_RIGHT_ID, HILL_DOTS_LEFT_ID, HILL_FILL_ID, HILL_TOP_ID,
BUSH_LEFT_ID, BUSH_MIDDLE_ID, BUSH_RIGHT_ID,
CLOUD_LEFT_BOTTOM_ID, CLOUD_MIDDLE_BOTTOM_ID, CLOUD_RIGHT_BOTTOM_ID, CLOUD_LEFT_BOTTOM_ID, CLOUD_MIDDLE_BOTTOM_ID, CLOUD_RIGHT_BOTTOM_ID,
CLOUD_LEFT_TOP_ID, CLOUD_MIDDLE_TOP_ID, CLOUD_RIGHT_TOP_ID, CLOUD_LEFT_TOP_ID, CLOUD_MIDDLE_TOP_ID, CLOUD_RIGHT_TOP_ID,
CASTLE_LEFT_ID, CASTLE_RIGHT_ID, CASTLE_BLACK_ID, CASTLE_ENTRY_ID, CASTLE_LEFT_ID, CASTLE_RIGHT_ID, CASTLE_BLACK_ID,
CASTLE_TOWER_ID, CASTLE_TOWER_FILLED_ID, WATER_TOP_ID, WATER_FILL_ID }; CASTLE_ENTRY_ID, CASTLE_TOWER_ID, CASTLE_TOWER_FILLED_ID,
WATER_TOP_ID, WATER_FILL_ID
};
scene->setBackgroundObjectIDs(background_ids); scene->setBackgroundObjectIDs(background_ids);
scene->updateBackgroundObjectZIndex(); scene->updateBackgroundObjectZIndex();

View File

@ -90,9 +90,8 @@ MapObject parseBlock( std::ifstream &map_file ) {
// editor loader // editor loader
void loadMap(std::shared_ptr<SDLPP::Scene> &scene, void loadMap(std::shared_ptr<SDLPP::Scene> &scene,
std::shared_ptr<SDLPP::RenderObject> &mario, std::shared_ptr<SDLPP::RenderObject> &mario,
const std::string &file, const std::string &file, std::vector<mapColumnType> &objects,
std::vector< mapColumnType > &objects, bool editor, bool editor, size_t editor_width) {
size_t editor_width ) {
auto renderer = scene->getRendererShared(); auto renderer = scene->getRendererShared();
std::ifstream map_file; std::ifstream map_file;
map_file.open(file, std::ios::in | std::ios::binary); map_file.open(file, std::ios::in | std::ios::binary);
@ -116,17 +115,14 @@ void loadMap( std::shared_ptr< SDLPP::Scene > &scene,
bool removeCollisions = false; bool removeCollisions = false;
int coinCount = 0; int coinCount = 0;
bool mushroom = false; bool mushroom = false;
if ( !editor && if (!editor && block.getModifierId() == DESTRUCTIBLE_MODIFIER_ID) {
block.getModifierId() == DESTRUCTIBLE_MODIFIER_ID ) {
destructible = true; destructible = true;
} }
if ( !editor && if (!editor && block.getModifierId() == BACKGROUND_MODIFIER_ID) {
block.getModifierId() == BACKGROUND_MODIFIER_ID ) {
destructible = false; destructible = false;
removeCollisions = true; removeCollisions = true;
} }
if ( !editor && if (!editor && block.getModifierId() == COIN_MODIFIER_ID) {
block.getModifierId() == COIN_MODIFIER_ID ) {
coinCount = block.getModifierData(); coinCount = block.getModifierData();
} }
if (!editor && block.getModifierId() == MUSHROOM_MODIFIER_ID) { if (!editor && block.getModifierId() == MUSHROOM_MODIFIER_ID) {
@ -134,9 +130,9 @@ void loadMap( std::shared_ptr< SDLPP::Scene > &scene,
} }
// TODO add modifiers to createTerrainBlock // TODO add modifiers to createTerrainBlock
if (block.getTerrainId() != 0) { if (block.getTerrainId() != 0) {
auto obj = createTerrainBlock( auto obj = createTerrainBlock(block.getTerrainId(),
block.getTerrainId(), block.getTerrainType(), block.getTerrainType(), renderer,
renderer, i, j, destructible, editor ); i, j, destructible, editor);
if (obj != nullptr) { if (obj != nullptr) {
obj->setCoinCount(coinCount); obj->setCoinCount(coinCount);
if (mushroom) { if (mushroom) {
@ -156,8 +152,7 @@ void loadMap( std::shared_ptr< SDLPP::Scene > &scene,
if (block.hasCharacter()) { if (block.hasCharacter()) {
if (block.getCharacterId() == MARIO_ID) { if (block.getCharacterId() == MARIO_ID) {
if (editor) { if (editor) {
scene->addObject( createMario( scene->addObject(createMario(block.getCharacterType(),
block.getCharacterType(),
renderer, i, j, true)); renderer, i, j, true));
mario = mario =
scene->getObject(scene->getObjects().size() - 1); scene->getObject(scene->getObjects().size() - 1);
@ -178,9 +173,9 @@ void loadMap( std::shared_ptr< SDLPP::Scene > &scene,
} }
if (editor && block.hasModifier()) { if (editor && block.hasModifier()) {
// TODO createModifierBlock with data // TODO createModifierBlock with data
auto mod = createTerrainBlock( auto mod = createTerrainBlock(block.getModifierId(),
block.getModifierId(), LandType::OVERWORLD, renderer, i, j, LandType::OVERWORLD, renderer, i,
false, editor ); j, false, editor);
mod->setData(block.getModifierData()); mod->setData(block.getModifierData());
mod->setTextureKeepSRC(g_translucent_mod_texture); mod->setTextureKeepSRC(g_translucent_mod_texture);
mod->getCollisions()[0]->setId(EDITOR_TERRAIN_ID); mod->getCollisions()[0]->setId(EDITOR_TERRAIN_ID);
@ -202,7 +197,8 @@ void saveMap( const std::string &file, std::vector< mapColumnType > &objects ) {
for (auto &col : objects) { for (auto &col : objects) {
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
auto &block = col[i]; auto &block = col[i];
auto wide_terrain = combineTerrain(block.getTerrainId(), block.getTerrainType()); auto wide_terrain =
combineTerrain(block.getTerrainId(), block.getTerrainType());
// if block has additional data it needs to indicate it // if block has additional data it needs to indicate it
if (block.hasCharacter() || block.hasModifier()) { if (block.hasCharacter() || block.hasModifier()) {
wide_terrain |= WIDE_TERRAIN_HAS_ADDITIONAL; wide_terrain |= WIDE_TERRAIN_HAS_ADDITIONAL;
@ -210,11 +206,14 @@ void saveMap( const std::string &file, std::vector< mapColumnType > &objects ) {
write16Bits(output_file, wide_terrain); write16Bits(output_file, wide_terrain);
uint8_t additional_data = 0; uint8_t additional_data = 0;
if (block.hasCharacter()) { if (block.hasCharacter()) {
additional_data = combineAdditionalData(block.getCharacterId(), block.getCharacterType()); additional_data = combineAdditionalData(
block.getCharacterId(), block.getCharacterType());
} else if (block.hasModifier()) { } else if (block.hasModifier()) {
// TODO seriously change order of id/data!!! // TODO seriously change order of id/data!!!
// we have IDs like 0x600X but only X is useful data, the 0x6 at the beginning is to differentiate mods from characters // we have IDs like 0x600X but only X is useful data, the 0x6 at
additional_data = combineAdditionalData(block.getModifierData(), block.getModifierId() & 0x000F); // the beginning is to differentiate mods from characters
additional_data = combineAdditionalData(
block.getModifierData(), block.getModifierId() & 0x000F);
additional_data |= ADDITIONAL_IS_MOD; additional_data |= ADDITIONAL_IS_MOD;
} }
if (additional_data) { if (additional_data) {

View File

@ -12,8 +12,8 @@ void loadMap( std::shared_ptr< SDLPP::Scene > &scene,
const std::string &file); const std::string &file);
void loadMap(std::shared_ptr<SDLPP::Scene> &scene, void loadMap(std::shared_ptr<SDLPP::Scene> &scene,
std::shared_ptr<SDLPP::RenderObject> &mario, std::shared_ptr<SDLPP::RenderObject> &mario,
const std::string &file, const std::string &file, std::vector<mapColumnType> &objects,
std::vector< mapColumnType > &objects, bool editor = false, size_t editor_width = 0 ); bool editor = false, size_t editor_width = 0);
void saveMap(const std::string &file, std::vector<mapColumnType> &objects); void saveMap(const std::string &file, std::vector<mapColumnType> &objects);
#endif #endif

View File

@ -14,8 +14,7 @@ MapObject::MapObject( uint16_t terrain_id, uint8_t terrain_type,
uint8_t character_id, uint8_t character_type, uint8_t character_id, uint8_t character_type,
uint32_t modifier_id, uint8_t modifier_data) uint32_t modifier_id, uint8_t modifier_data)
: MapObject(terrain_id, static_cast<LandType::Value>(terrain_type), : MapObject(terrain_id, static_cast<LandType::Value>(terrain_type),
character_id, character_id, static_cast<LandType::Value>(character_type),
static_cast< LandType::Value >( character_type ),
modifier_id, modifier_data) {} modifier_id, modifier_data) {}
void MapObject::setTerrain(uint16_t id, LandType::Value land_type) { void MapObject::setTerrain(uint16_t id, LandType::Value land_type) {

View File

@ -4,7 +4,8 @@
#include "sprites.hpp" #include "sprites.hpp"
#include "visitors/mario_visitor.hpp" #include "visitors/mario_visitor.hpp"
Mario::Mario(int x, int y, const std::shared_ptr< SDLPP::Renderer > &renderer) : MarioBlock(x, y, renderer, g_mario_texture, MARIO_STANDING_SRC) { Mario::Mario(int x, int y, const std::shared_ptr<SDLPP::Renderer> &renderer)
: MarioBlock(x, y, renderer, g_mario_texture, MARIO_STANDING_SRC) {
setAnimationFrames(MARIO_WALK_ANIM); setAnimationFrames(MARIO_WALK_ANIM);
setId(MARIO_ID); setId(MARIO_ID);
setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER); setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
@ -17,22 +18,21 @@ Mario::Mario(int x, int y, const std::shared_ptr< SDLPP::Renderer > &renderer) :
bottom_detect.setOutlineColor("#FF0000"); bottom_detect.setOutlineColor("#FF0000");
bottom_detect.setMinHeight(1); bottom_detect.setMinHeight(1);
addCollision(bottom_detect); addCollision(bottom_detect);
addCollision( addCollision(SDLPP::RectColider(0, 0.25, 0.1, 0.6, MARIO_LEFT_SIDE_DETECT));
SDLPP::RectColider( 0, 0.25, 0.1, 0.6, MARIO_LEFT_SIDE_DETECT ) );
addCollision( addCollision(
SDLPP::RectColider(0.9, 0.25, 0.1, 0.6, MARIO_RIGHT_SIDE_DETECT)); SDLPP::RectColider(0.9, 0.25, 0.1, 0.6, MARIO_RIGHT_SIDE_DETECT));
addCollision( addCollision(SDLPP::RectColider(0, 0, 0.1, 0.1, MARIO_TOP_LEFT_DETECT));
SDLPP::RectColider( 0, 0, 0.1, 0.1, MARIO_TOP_LEFT_DETECT ) ); addCollision(SDLPP::RectColider(0.9, 0, 0.1, 0.1, MARIO_TOP_LEFT_DETECT));
addCollision( top_collision = std::make_shared<SDLPP::RectColider>(0.5, 0, 0.2, 0.15,
SDLPP::RectColider( 0.9, 0, 0.1, 0.1, MARIO_TOP_LEFT_DETECT ) ); MARIO_TOP_DETECT);
top_collision = std::make_shared<SDLPP::RectColider>( 0.5, 0, 0.2, 0.15, MARIO_TOP_DETECT );
addCollision(top_collision); addCollision(top_collision);
addCollision(SDLPP::RectColider(0, 1, 1, 0.2, MARIO_ENEMY_DETECT)); addCollision(SDLPP::RectColider(0, 1, 1, 0.2, MARIO_ENEMY_DETECT));
setColiderColor("#FF0000"); setColiderColor("#FF0000");
setStatic(false); setStatic(false);
bounce_speed *= 4; bounce_speed *= 4;
} }
Mario::Mario(const std::shared_ptr< SDLPP::Renderer > &renderer) : Mario(0, 0, renderer) {} Mario::Mario(const std::shared_ptr<SDLPP::Renderer> &renderer)
: Mario(0, 0, renderer) {}
void Mario::walkLeft() { void Mario::walkLeft() {
if (on_ground) if (on_ground)
resumeAnimation(); resumeAnimation();
@ -65,7 +65,8 @@ void Mario::setStanding() {
void Mario::handleVisitor(SDLPP::Visitor &visitor) { void Mario::handleVisitor(SDLPP::Visitor &visitor) {
#ifndef EDITOR #ifndef EDITOR
// TODO - https://web.archive.org/web/20130807122227/http://i276.photobucket.com/albums/kk21/jdaster64/smb_playerphysics.png // TODO -
// https://web.archive.org/web/20130807122227/http://i276.photobucket.com/albums/kk21/jdaster64/smb_playerphysics.png
auto &m_visitor = dynamic_cast<MarioVisitor &>(visitor); auto &m_visitor = dynamic_cast<MarioVisitor &>(visitor);
// handle gravity // handle gravity
on_ground = m_visitor.isOnGround(); on_ground = m_visitor.isOnGround();
@ -95,9 +96,18 @@ void Mario::handleVisitor(SDLPP::Visitor &visitor) {
// TODO more readable function names // TODO more readable function names
if (m_visitor.isStopped()) { if (m_visitor.isStopped()) {
setPos(m_visitor.getStopX(), getPos().getY()); setPos(m_visitor.getStopX(), getPos().getY());
} else if ( m_visitor.canGoLeft() != m_visitor.canGoRight() && !(on_ground && m_visitor.getMovementBlockage().getY() > getPos().getY() + BLOCK_SIZE/2) ) { } else if (m_visitor.canGoLeft() != m_visitor.canGoRight() &&
// only stop mario on ground if the block obstructs at least half of him (important for bug when mario lands from a high jump and is teleported if visitor is fired at wrong moment) !(on_ground && m_visitor.getMovementBlockage().getY() >
SDLPP::Vec2D<double> next_pos = { m_visitor.getMovementBlockage().getX() + (m_visitor.canGoLeft() * -1 + m_visitor.canGoRight() * 1) * BLOCK_SIZE, getPos().getY() }; getPos().getY() + BLOCK_SIZE / 2)) {
// only stop mario on ground if the block obstructs at least half of him
// (important for bug when mario lands from a high jump and is
// teleported if visitor is fired at wrong moment)
SDLPP::Vec2D<double> next_pos = {
m_visitor.getMovementBlockage().getX() +
(m_visitor.canGoLeft() * -1 + m_visitor.canGoRight() * 1) *
BLOCK_SIZE,
getPos().getY()
};
setPos(next_pos); setPos(next_pos);
} else if (m_visitor.moveTop() && jumping && !stop_jump) { } else if (m_visitor.moveTop() && jumping && !stop_jump) {
auto objPos = m_visitor.getRightLeftPos(); auto objPos = m_visitor.getRightLeftPos();

View File

@ -14,9 +14,9 @@ const SDL_Rect MARIO_JUMP_SRC = { 119, 9, 16, 16 };
const SDL_Rect MARIO_STANDING_BIG_SRC = { 1, 26, 16, 32 }; const SDL_Rect MARIO_STANDING_BIG_SRC = { 1, 26, 16, 32 };
const SDL_Rect MARIO_DEATH_BIG_SRC = { 22, 26, 16, 32 }; const SDL_Rect MARIO_DEATH_BIG_SRC = { 22, 26, 16, 32 };
const std::vector< SDL_Rect > MARIO_WALK_BIG_ANIM = { const std::vector<SDL_Rect> MARIO_WALK_BIG_ANIM = { { 43, 26, 16, 32 },
{ 43, 26, 16, 32 }, { 60, 9, 16, 32 }, { 77, 9, 16, 32 } { 60, 9, 16, 32 },
}; { 77, 9, 16, 32 } };
const SDL_Rect MARIO_CHANGE_DIR_BIG_SRC = { 98, 26, 16, 32 }; const SDL_Rect MARIO_CHANGE_DIR_BIG_SRC = { 98, 26, 16, 32 };
const SDL_Rect MARIO_JUMP_BIG_SRC = { 119, 26, 16, 32 }; const SDL_Rect MARIO_JUMP_BIG_SRC = { 119, 26, 16, 32 };

View File

@ -3,7 +3,11 @@
#include "blocks.hpp" #include "blocks.hpp"
#include "sprites.hpp" #include "sprites.hpp"
ToolBox::ToolBox(int x, int y, double start_x, double start_y, std::shared_ptr<SDLPP::Renderer> renderer, bool coliders) : SDLPP::RectangleRender(start_x + x*BLOCK_SIZE, start_y + y*BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, renderer) { ToolBox::ToolBox(int x, int y, double start_x, double start_y,
std::shared_ptr<SDLPP::Renderer> renderer, bool coliders)
: SDLPP::RectangleRender(start_x + x * BLOCK_SIZE,
start_y + y * BLOCK_SIZE, BLOCK_SIZE,
BLOCK_SIZE, renderer) {
_x = x; _x = x;
_y = y; _y = y;
setId(EDITOR_TOOL_ID); setId(EDITOR_TOOL_ID);

View File

@ -5,7 +5,8 @@
class ToolBox : public SDLPP::RectangleRender { class ToolBox : public SDLPP::RectangleRender {
public: public:
ToolBox(int x, int y, double start_x, double start_y, std::shared_ptr<SDLPP::Renderer> renderer, bool coliders = true); ToolBox(int x, int y, double start_x, double start_y,
std::shared_ptr<SDLPP::Renderer> renderer, bool coliders = true);
virtual SDLPP::Vec2D<int> getIndexes() const; virtual SDLPP::Vec2D<int> getIndexes() const;
virtual void visit(SDLPP::Visitor &visitor) override; virtual void visit(SDLPP::Visitor &visitor) override;
uint64_t getType() const { uint64_t getType() const {
@ -14,6 +15,7 @@ public:
void setType(uint64_t type) { void setType(uint64_t type) {
_type = type; _type = type;
} }
private: private:
int _x; int _x;
int _y; int _y;