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

@ -17,88 +17,91 @@
#define CAN_BE_DESTROYED_FLAG 0x0000000000000001 #define CAN_BE_DESTROYED_FLAG 0x0000000000000001
#define HAS_COLLISION 0x0000000000000002 #define HAS_COLLISION 0x0000000000000002
MarioBlock::MarioBlock( int x, int y, 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);
_coins = 0; _coins = 0;
_mushroom = false; _mushroom = false;
_base_src = src; _base_src = src;
} }
void MarioBlock::visit( SDLPP::Visitor &visitor ) { void MarioBlock::visit(SDLPP::Visitor &visitor) {
#ifdef EDITOR #ifdef EDITOR
if ( !_tool && _terrain && if (!_tool && _terrain &&
visitor.getVisitorType() == VisitorType::Terrain ) { visitor.getVisitorType() == VisitorType::Terrain) {
destroy(); destroy();
} }
if ( !_tool && !_terrain && if (!_tool && !_terrain &&
(visitor.getVisitorType() == VisitorType::Modifier || (visitor.getVisitorType() == VisitorType::Modifier ||
visitor.getVisitorType() == VisitorType::Character)) { visitor.getVisitorType() == VisitorType::Character)) {
destroy(); destroy();
} }
#else #else
if ( visitor.getFromId() == MARIO_TOP_DETECT && if (visitor.getFromId() == MARIO_TOP_DETECT &&
dynamic_cast< MarioVisitor & >( visitor ).canDestroy() ) { dynamic_cast<MarioVisitor &>(visitor).canDestroy()) {
// TODO if big mario and _can_be_destroyed // TODO if big mario and _can_be_destroyed
if ( _destructible && !hasCoin() ) { if (_destructible && !hasCoin()) {
destroy(); destroy();
} else { } else {
BounceVisitor bv; BounceVisitor bv;
bv.setVisitorType( VisitorType::Terrain ); bv.setVisitorType(VisitorType::Terrain);
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));
updateSizeAndPosition(); updateSizeAndPosition();
if ( bv.canBounce() ) if (bv.canBounce())
bounce(); bounce();
} }
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();
dynamic_cast< MarioVisitor & >( visitor ).setCoinBlock(coin); dynamic_cast<MarioVisitor &>(visitor).setCoinBlock(coin);
} }
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);
} }
} }
#endif #endif
visitor.visit( *this ); visitor.visit(*this);
} }
void MarioBlock::setTool( bool tool ) { void MarioBlock::setTool(bool tool) {
_tool = tool; _tool = tool;
} }
void MarioBlock::setTerrain( bool terrain ) { void MarioBlock::setTerrain(bool terrain) {
_terrain = terrain; _terrain = terrain;
} }
void MarioBlock::bounce() { void MarioBlock::bounce() {
if ( _bouncing ) { if (_bouncing) {
return; return;
} }
_bouncing = true; _bouncing = true;
og_pos = getPos(); og_pos = getPos();
ticks_to_bounce = bounce_ticks; ticks_to_bounce = bounce_ticks;
setMovement( 0, -bounce_speed ); setMovement(0, -bounce_speed);
} }
void MarioBlock::travelToPos(const SDLPP::Vec2D<double> &target) { void MarioBlock::travelToPos(const SDLPP::Vec2D<double> &target) {
if(_traveling) { if (_traveling) {
return; return;
} }
_traveling = true; _traveling = true;
@ -106,11 +109,11 @@ void MarioBlock::travelToPos(const SDLPP::Vec2D<double> &target) {
auto movement = (_target - getPos()); auto movement = (_target - getPos());
auto abs_mov_x = movement.getX(); auto abs_mov_x = movement.getX();
if(abs_mov_x < 0) { if (abs_mov_x < 0) {
abs_mov_x *= -1; abs_mov_x *= -1;
} }
auto abs_mov_y = movement.getY(); auto abs_mov_y = movement.getY();
if(abs_mov_y < 0) { if (abs_mov_y < 0) {
abs_mov_y *= -1; abs_mov_y *= -1;
} }
@ -120,11 +123,11 @@ void MarioBlock::travelToPos(const SDLPP::Vec2D<double> &target) {
} }
void MarioBlock::gravity(int ticks) { void MarioBlock::gravity(int ticks) {
if(_on_ground) { if (_on_ground) {
return; return;
} }
_ticks_till_gravity -= ticks; _ticks_till_gravity -= ticks;
if(_ticks_till_gravity < 0) { if (_ticks_till_gravity < 0) {
addMovement(0, _gravity_acceleration); addMovement(0, _gravity_acceleration);
_ticks_till_gravity = _base_gravity_ticks; _ticks_till_gravity = _base_gravity_ticks;
} }
@ -138,51 +141,49 @@ bool MarioBlock::isTraveling() const {
return _traveling; return _traveling;
} }
void MarioBlock::custom_move( int ticks ) { void MarioBlock::custom_move(int ticks) {
if ( !_bouncing && !_traveling ) { if (!_bouncing && !_traveling) {
return; return;
} }
if( _bouncing ) { if (_bouncing) {
if ( getMovement().getY() < 0 ) { if (getMovement().getY() < 0) {
ticks_to_bounce -= ticks; ticks_to_bounce -= ticks;
if ( ticks_to_bounce < 0 ) { if (ticks_to_bounce < 0) {
setMovement( 0, bounce_speed ); setMovement(0, bounce_speed);
ticks_to_bounce = bounce_ticks; ticks_to_bounce = bounce_ticks;
} }
} else { } else {
if ( getPos().getY() >= og_pos.getY() ) { if (getPos().getY() >= og_pos.getY()) {
setMovement( 0, 0 ); setMovement(0, 0);
setPos( getPos().getX(), og_pos.getY() ); setPos(getPos().getX(), og_pos.getY());
_bouncing = false; _bouncing = false;
} }
} }
} }
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 && if (overshot_x) {
getPos().getY() >= _target.getY());
if(overshot_x) {
setPos(_target.getX(), getPos().getY()); setPos(_target.getX(), getPos().getY());
setMovement(0, getMovement().getY()); setMovement(0, getMovement().getY());
} }
if(overshot_y) { if (overshot_y) {
setPos(getPos().getX(), _target.getY()); setPos(getPos().getX(), _target.getY());
setMovement(getMovement().getX(), 0); setMovement(getMovement().getX(), 0);
} }
if(getMovement() == SDLPP::Vec2D<double>(0,0)) { if (getMovement() == SDLPP::Vec2D<double>(0, 0)) {
_traveling = false; _traveling = false;
} }
} }
} }
void MarioBlock::setType( LandType::Value type ) { void MarioBlock::setType(LandType::Value type) {
_type = type; _type = type;
setWorldTypeSrc( _type ); setWorldTypeSrc(_type);
} }
LandType::Value MarioBlock::getType() const { LandType::Value MarioBlock::getType() const {
return _type; return _type;
@ -203,20 +204,20 @@ void MarioBlock::removeMushroom() {
void MarioBlock::addMushroom() { void MarioBlock::addMushroom() {
_mushroom = true; _mushroom = true;
} }
void MarioBlock::setCoinCount( int coins ) { void MarioBlock::setCoinCount(int coins) {
_coins = coins; _coins = coins;
} }
void MarioBlock::setDestructible( bool destructible ) { void MarioBlock::setDestructible(bool destructible) {
_destructible = destructible; _destructible = destructible;
} }
void MarioBlock::ensureCollision() { void MarioBlock::ensureCollision() {
if ( getCollisions().size() == 0 ) { if (getCollisions().size() == 0) {
addCollision( SDLPP::RectColider( 0, 0, 1, 1 ) ); addCollision(SDLPP::RectColider(0, 0, 1, 1));
} }
} }
void MarioBlock::setWorldTypeSrc( LandType::Value world ) { void MarioBlock::setWorldTypeSrc(LandType::Value world) {
auto rect = _base_src; auto rect = _base_src;
switch ( world ) { switch (world) {
case LandType::OVERWORLD: case LandType::OVERWORLD:
rect.x += OVERWORLD_SHIFT.getX(); rect.x += OVERWORLD_SHIFT.getX();
rect.y += OVERWORLD_SHIFT.getY(); rect.y += OVERWORLD_SHIFT.getY();
@ -234,10 +235,10 @@ void MarioBlock::setWorldTypeSrc( LandType::Value world ) {
rect.y += BOWSER_SHIFT.getY(); rect.y += BOWSER_SHIFT.getY();
break; break;
} }
setTextureSourceRect( rect ); setTextureSourceRect(rect);
} }
const std::vector< uint64_t > possibleBlocks = { const std::vector<uint64_t> possibleBlocks = {
FLOOR_ID, FLOOR_ID,
STEP_ID, STEP_ID,
HILL_TOP_ID, HILL_TOP_ID,
@ -298,362 +299,354 @@ const std::vector< uint64_t > possibleBlocks = {
CANNON_ID, CANNON_ID,
}; };
const std::vector< uint64_t > possibleMods = { const std::vector<uint64_t> possibleMods = {
DESTRUCTIBLE_MODIFIER_ID, DESTRUCTIBLE_MODIFIER_ID,
BACKGROUND_MODIFIER_ID, BACKGROUND_MODIFIER_ID,
COIN_MODIFIER_ID, COIN_MODIFIER_ID,
MUSHROOM_MODIFIER_ID, MUSHROOM_MODIFIER_ID,
}; };
const std::vector< uint64_t > possibleCharacters = { const std::vector<uint64_t> possibleCharacters = {
MARIO_ID, MARIO_ID,
GOOMBA_ID, GOOMBA_ID,
}; };
const std::vector< LandType::Value > possibleLands = { const std::vector<LandType::Value> possibleLands = {
LandType::OVERWORLD, LandType::UNDERWORLD, LandType::WATER, LandType::BOWSER LandType::OVERWORLD, LandType::UNDERWORLD, LandType::WATER, LandType::BOWSER
}; };
std::shared_ptr< MarioBlock > std::shared_ptr<MarioBlock>
createBlockById( uint64_t id, int x, int y, createBlockById(uint64_t id, int x, int y,
std::shared_ptr< SDLPP::Renderer > &renderer ) { std::shared_ptr<SDLPP::Renderer> &renderer) {
std::shared_ptr< MarioBlock > result = nullptr; std::shared_ptr<MarioBlock> result = nullptr;
switch ( id ) { switch (id) {
case FLOOR_ID: case FLOOR_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< FloorBlock >( x, y, renderer ) ); std::make_shared<FloorBlock>(x, y, renderer));
break; break;
case HILL_INCLINE_ID: case HILL_INCLINE_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< HillInclineBlock >( x, y, renderer ) ); std::make_shared<HillInclineBlock>(x, y, renderer));
break; break;
case HILL_DECLINE_ID: case HILL_DECLINE_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< HillDeclineBlock >( x, y, renderer ) ); std::make_shared<HillDeclineBlock>(x, y, renderer));
break; break;
case HILL_DOTS_RIGHT_ID: case HILL_DOTS_RIGHT_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< HillDotsRightBlock >( x, y, renderer ) ); std::make_shared<HillDotsRightBlock>(x, y, renderer));
break; break;
case HILL_DOTS_LEFT_ID: case HILL_DOTS_LEFT_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< HillDotsLeftBlock >( x, y, renderer ) ); std::make_shared<HillDotsLeftBlock>(x, y, renderer));
break; break;
case HILL_FILL_ID: case HILL_FILL_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< HillFillBlock >( x, y, renderer ) ); std::make_shared<HillFillBlock>(x, y, renderer));
break; break;
case HILL_TOP_ID: case HILL_TOP_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< HillTopBlock >( x, y, renderer ) ); std::make_shared<HillTopBlock>(x, y, renderer));
break; break;
case BUSH_LEFT_ID: case BUSH_LEFT_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< BushLeftBlock >( x, y, renderer ) ); std::make_shared<BushLeftBlock>(x, y, renderer));
break; break;
case BUSH_MIDDLE_ID: case BUSH_MIDDLE_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< BushMiddleBlock >( x, y, renderer ) ); std::make_shared<BushMiddleBlock>(x, y, renderer));
break; break;
case BUSH_RIGHT_ID: case BUSH_RIGHT_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< BushRightBlock >( x, y, renderer ) ); std::make_shared<BushRightBlock>(x, y, renderer));
break; break;
case CLOUD_LEFT_BOTTOM_ID: case CLOUD_LEFT_BOTTOM_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< CloudLeftBottomBlock >( x, y, renderer ) ); std::make_shared<CloudLeftBottomBlock>(x, y, renderer));
break; break;
case CLOUD_MIDDLE_BOTTOM_ID: case CLOUD_MIDDLE_BOTTOM_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< CloudMiddleBottomBlock >( x, y, renderer ) ); std::make_shared<CloudMiddleBottomBlock>(x, y, renderer));
break; break;
case CLOUD_RIGHT_BOTTOM_ID: case CLOUD_RIGHT_BOTTOM_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< CloudRightBottomBlock >( x, y, renderer ) ); std::make_shared<CloudRightBottomBlock>(x, y, renderer));
break; break;
case CLOUD_LEFT_TOP_ID: case CLOUD_LEFT_TOP_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< CloudLeftTopBlock >( x, y, renderer ) ); std::make_shared<CloudLeftTopBlock>(x, y, renderer));
break; break;
case CLOUD_MIDDLE_TOP_ID: case CLOUD_MIDDLE_TOP_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< CloudMiddleTopBlock >( x, y, renderer ) ); std::make_shared<CloudMiddleTopBlock>(x, y, renderer));
break; break;
case CLOUD_RIGHT_TOP_ID: case CLOUD_RIGHT_TOP_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< CloudRightTopBlock >( x, y, renderer ) ); std::make_shared<CloudRightTopBlock>(x, y, renderer));
break; break;
case PIPE_LEFT_BOTTOM_ID: case PIPE_LEFT_BOTTOM_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< PipeLeftBottomBlock >( x, y, renderer ) ); std::make_shared<PipeLeftBottomBlock>(x, y, renderer));
break; break;
case PIPE_RIGHT_BOTTOM_ID: case PIPE_RIGHT_BOTTOM_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< PipeRightBottomBlock >( x, y, renderer ) ); std::make_shared<PipeRightBottomBlock>(x, y, renderer));
break; break;
case PIPE_LEFT_TOP_ID: case PIPE_LEFT_TOP_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< PipeLeftTopBlock >( x, y, renderer ) ); std::make_shared<PipeLeftTopBlock>(x, y, renderer));
break; break;
case PIPE_RIGHT_TOP_ID: case PIPE_RIGHT_TOP_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< PipeRightTopBlock >( x, y, renderer ) ); std::make_shared<PipeRightTopBlock>(x, y, renderer));
break; break;
case CASTLE_LEFT_ID: case CASTLE_LEFT_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< CastleLeftBlock >( x, y, renderer ) ); std::make_shared<CastleLeftBlock>(x, y, renderer));
break; break;
case CASTLE_RIGHT_ID: case CASTLE_RIGHT_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< CastleRightBlock >( x, y, renderer ) ); std::make_shared<CastleRightBlock>(x, y, renderer));
break; break;
case CASTLE_BLACK_ID: case CASTLE_BLACK_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< CastleBlackBlock >( x, y, renderer ) ); std::make_shared<CastleBlackBlock>(x, y, renderer));
break; break;
case CASTLE_ENTRY_ID: case CASTLE_ENTRY_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< CastleEntryBlock >( x, y, renderer ) ); std::make_shared<CastleEntryBlock>(x, y, renderer));
break; break;
case CASTLE_TOWER_ID: case CASTLE_TOWER_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< CastleTowerBlock >( x, y, renderer ) ); std::make_shared<CastleTowerBlock>(x, y, renderer));
break; break;
case CASTLE_TOWER_FILLED_ID: case CASTLE_TOWER_FILLED_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< CastleTowerFilledBlock >( x, y, renderer ) ); std::make_shared<CastleTowerFilledBlock>(x, y, renderer));
break; break;
case VINE_TOP_ID: case VINE_TOP_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< VineTopBlock >( x, y, renderer ) ); std::make_shared<VineTopBlock>(x, y, renderer));
break; break;
case VINE_BOTTOM_ID: case VINE_BOTTOM_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< VineBottomBlock >( x, y, renderer ) ); std::make_shared<VineBottomBlock>(x, y, renderer));
break; break;
case POLE_TOP_ID: case POLE_TOP_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< PoleTopBlock >( x, y, renderer ) ); std::make_shared<PoleTopBlock>(x, y, renderer));
break; break;
case POLE_BOTTOM_ID: case POLE_BOTTOM_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< PoleBottomBlock >( x, y, renderer ) ); std::make_shared<PoleBottomBlock>(x, y, renderer));
break; break;
case FLAG_ID: case FLAG_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< FlagBlock >( x, y, renderer ) ); std::make_shared<FlagBlock>(x, y, renderer));
break; break;
case STEP_ID: case STEP_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< StepBlock >( x, y, renderer ) ); std::make_shared<StepBlock>(x, y, renderer));
break; break;
case BRICK_ID: case BRICK_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< BrickBlock >( x, y, renderer ) ); std::make_shared<BrickBlock>(x, y, renderer));
break; break;
case BRICK_TOP_ID: case BRICK_TOP_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< BrickTopBlock >( x, y, renderer ) ); std::make_shared<BrickTopBlock>(x, y, renderer));
break; break;
case SIDEWAY_PIPE_END_TOP_ID: case SIDEWAY_PIPE_END_TOP_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< SidewayPipeEndTopBlock >( x, y, renderer ) ); std::make_shared<SidewayPipeEndTopBlock>(x, y, renderer));
break; break;
case SIDEWAY_PIPE_END_BOTTOM_ID: case SIDEWAY_PIPE_END_BOTTOM_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< SidewayPipeEndBottomBlock >( x, y, renderer ) ); std::make_shared<SidewayPipeEndBottomBlock>(x, y, renderer));
break; break;
case SIDEWAY_PIPE_MIDDLE_TOP_ID: case SIDEWAY_PIPE_MIDDLE_TOP_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< SidewayPipeMiddleTopBlock >( x, y, renderer ) ); std::make_shared<SidewayPipeMiddleTopBlock>(x, y, renderer));
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>(
std::make_shared< TreePlatformTopLeftBlock >( x, y, renderer ) ); std::make_shared<TreePlatformTopLeftBlock>(x, y, renderer));
break; break;
case TREE_PLATFORM_TOP_MIDDLE_ID: case TREE_PLATFORM_TOP_MIDDLE_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< TreePlatformTopMiddleBlock >( x, y, renderer ) ); std::make_shared<TreePlatformTopMiddleBlock>(x, y, renderer));
break; break;
case TREE_PLATFORM_TOP_RIGHT_ID: case TREE_PLATFORM_TOP_RIGHT_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< TreePlatformTopRightBlock >( x, y, renderer ) ); std::make_shared<TreePlatformTopRightBlock>(x, y, renderer));
break; break;
case TREE_PLATFORM_BARK_ID: case TREE_PLATFORM_BARK_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< TreePlatformBarkBlock >( x, y, renderer ) ); std::make_shared<TreePlatformBarkBlock>(x, y, renderer));
break; break;
case WATER_TOP_ID: case WATER_TOP_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< WaterTopBlock >( x, y, renderer ) ); std::make_shared<WaterTopBlock>(x, y, renderer));
break; break;
case WATER_FILL_ID: case WATER_FILL_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< WaterFillBlock >( x, y, renderer ) ); std::make_shared<WaterFillBlock>(x, y, renderer));
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>(
std::make_shared< TreeBarkBlock >( x, y, renderer ) ); std::make_shared<TreeBarkBlock>(x, y, renderer));
break; break;
case TREE_LEAVES_SMALL_ID: case TREE_LEAVES_SMALL_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< TreeLeavesSmallBlock >( x, y, renderer ) ); std::make_shared<TreeLeavesSmallBlock>(x, y, renderer));
break; break;
case TREE_LEAVES_TOP_ID: case TREE_LEAVES_TOP_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< TreeLeavesTopBlock >( x, y, renderer ) ); std::make_shared<TreeLeavesTopBlock>(x, y, renderer));
break; break;
case TREE_LEAVES_BOTTOM_ID: case TREE_LEAVES_BOTTOM_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< TreeLeavesBottomBlock >( x, y, renderer ) ); std::make_shared<TreeLeavesBottomBlock>(x, y, renderer));
break; break;
case CANNON_TOWER_ID: case CANNON_TOWER_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< CannonTowerBlock >( x, y, renderer ) ); std::make_shared<CannonTowerBlock>(x, y, renderer));
break; break;
case CANNON_PEDESTAL_ID: case CANNON_PEDESTAL_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< CannonPedestalBlock >( x, y, renderer ) ); std::make_shared<CannonPedestalBlock>(x, y, renderer));
break; break;
case CANNON_ID: case CANNON_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< CannonBlock >( x, y, renderer ) ); std::make_shared<CannonBlock>(x, y, renderer));
break; break;
case MARIO_ID: case MARIO_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< Mario >( x, y, renderer ) ); std::make_shared<Mario>(x, y, renderer));
break; break;
case GOOMBA_ID: case GOOMBA_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< GoombaBlock >( x, y, renderer ) ); std::make_shared<GoombaBlock>(x, y, renderer));
break; break;
case DESTRUCTIBLE_MODIFIER_ID: case DESTRUCTIBLE_MODIFIER_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< DestructibleModifierBlock >( x, y, renderer ) ); std::make_shared<DestructibleModifierBlock>(x, y, renderer));
break; break;
case BACKGROUND_MODIFIER_ID: case BACKGROUND_MODIFIER_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< BackgroundModifierBlock >( x, y, renderer ) ); std::make_shared<BackgroundModifierBlock>(x, y, renderer));
break; break;
#ifdef EDITOR #ifdef EDITOR
case COIN_MODIFIER_ID: case COIN_MODIFIER_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< CoinEditorBlock >( x, y, renderer ) ); std::make_shared<CoinEditorBlock>(x, y, renderer));
break; break;
#endif #endif
case MUSHROOM_MODIFIER_ID: case MUSHROOM_MODIFIER_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< MushroomModifierBlock >( x, y, renderer ) ); std::make_shared<MushroomModifierBlock>(x, y, renderer));
break; break;
#ifndef EDITOR #ifndef EDITOR
case COIN_ID: case COIN_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< CoinBlock >( x, y, renderer ) ); std::make_shared<CoinBlock>(x, y, renderer));
break; break;
case MUSHROOM_ID: case MUSHROOM_ID:
result = std::static_pointer_cast< MarioBlock >( result = std::static_pointer_cast<MarioBlock>(
std::make_shared< MushroomBlock >( x, y, renderer ) ); std::make_shared<MushroomBlock>(x, y, renderer));
break; break;
#endif #endif
} }
return result; return result;
} }
std::shared_ptr< MarioBlock > std::shared_ptr<MarioBlock>
createBlock( std::shared_ptr< SDLPP::Renderer > &renderer, int x, int y, createBlock(std::shared_ptr<SDLPP::Renderer> &renderer, int x, int y,
uint64_t id, LandType::Value land_type, bool destructible, uint64_t id, LandType::Value land_type, bool destructible,
bool editor ) { bool editor) {
auto block = createBlockById( id, x, y, renderer ); auto block = createBlockById(id, x, y, renderer);
if ( block == nullptr ) { if (block == nullptr) {
return nullptr; return nullptr;
} }
block->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER ); block->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
block->setStatic(); block->setStatic();
block->setType( land_type ); block->setType(land_type);
if ( destructible ) { if (destructible) {
block->setDestructible(); block->setDestructible();
} }
if ( editor ) { if (editor) {
block->ensureCollision(); block->ensureCollision();
} }
return block; return block;
} }
// TODO coin count // TODO coin count
std::shared_ptr< MarioBlock > std::shared_ptr<MarioBlock>
createTerrainBlock( uint64_t block_id, LandType::Value type, createTerrainBlock(uint64_t block_id, LandType::Value type,
std::shared_ptr< SDLPP::Renderer > &renderer, int x, int y, std::shared_ptr<SDLPP::Renderer> &renderer, int x, int y,
bool destructible, bool editor ) { bool destructible, bool editor) {
return createBlock( renderer, x, y, block_id, type, destructible, editor ); return createBlock(renderer, x, y, block_id, type, destructible, editor);
} }
std::shared_ptr< MarioBlock > std::shared_ptr<MarioBlock>
createTerrainBlock( uint64_t block_id, LandType::Value type, createTerrainBlock(uint64_t block_id, LandType::Value type,
std::shared_ptr< SDLPP::Renderer > &renderer, std::shared_ptr<SDLPP::Renderer> &renderer,
bool destructible, bool editor ) { bool destructible, bool editor) {
return createTerrainBlock( block_id, type, renderer, 0, 0, destructible, return createTerrainBlock(block_id, type, renderer, 0, 0, destructible,
editor ); editor);
} }
std::shared_ptr< MarioBlock > std::shared_ptr<MarioBlock>
createMario( LandType::Value type, std::shared_ptr< SDLPP::Renderer > &renderer, createMario(LandType::Value type, std::shared_ptr<SDLPP::Renderer> &renderer,
int x, int y, bool editor ) { int x, int y, bool editor) {
// TODO add type additions // TODO add type additions
auto mario = createBlock( renderer, x, y, MARIO_ID, type, false, true ); auto mario = createBlock(renderer, x, y, MARIO_ID, type, false, true);
if ( editor ) { if (editor) {
mario->setTerrain( false ); mario->setTerrain(false);
mario->removeCollisions(); mario->removeCollisions();
mario->ensureCollision(); mario->ensureCollision();
} }
return mario; return mario;
} }
enum BlockRole::Value getBlockRole( uint64_t id ) { enum BlockRole::Value getBlockRole(uint64_t id) {
if ( id >= 0x7000 ) if (id >= 0x7000)
return BlockRole::TERRAIN; return BlockRole::TERRAIN;
if ( id == MARIO_ID ) if (id == MARIO_ID)
return BlockRole::MARIO; return BlockRole::MARIO;
if ( id < MARIO_ID ) if (id < MARIO_ID)
return BlockRole::CHARACTER; return BlockRole::CHARACTER;
return BlockRole::MODIFIER; return BlockRole::MODIFIER;
} }
@ -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,24 +11,23 @@ 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; void setTool(bool tool = true);
void setTool( bool tool = true ); void setTerrain(bool terrain = true);
void setTerrain( bool terrain = true );
void bounce(); void bounce();
void travelToPos(const SDLPP::Vec2D<double> &target); void travelToPos(const SDLPP::Vec2D<double> &target);
void custom_move( int ticks ) override; void custom_move(int ticks) override;
void setType( LandType::Value type ); void setType(LandType::Value type);
LandType::Value getType() const; LandType::Value getType() const;
virtual void onScrollUp() {} virtual void onScrollUp() {}
virtual void onScrollDown() {} virtual void onScrollDown() {}
virtual uint8_t getData() const { virtual uint8_t getData() const {
return 0; return 0;
} }
virtual void setData( uint8_t /*UNUSED*/ ) {} virtual void setData(uint8_t /*UNUSED*/) {}
// handle own visitor // handle own visitor
virtual void handleVisitor(SDLPP::Visitor &visitor) {} virtual void handleVisitor(SDLPP::Visitor &visitor) {}
bool hasCoin(); bool hasCoin();
@ -36,8 +35,8 @@ public:
void removeCoin(); void removeCoin();
void removeMushroom(); void removeMushroom();
void addMushroom(); void addMushroom();
void setCoinCount( int coins ); void setCoinCount(int coins);
void setDestructible( bool destructible = true ); void setDestructible(bool destructible = true);
void ensureCollision(); void ensureCollision();
bool isBouncing() const; bool isBouncing() const;
bool isTraveling() const; bool isTraveling() const;
@ -52,7 +51,7 @@ protected:
void gravity(int ticks); void gravity(int ticks);
void setOnGround(bool on_ground = true) { void setOnGround(bool on_ground = true) {
_on_ground = on_ground; _on_ground = on_ground;
if(on_ground) { if (on_ground) {
setMovement(getMovement().getX(), 0); setMovement(getMovement().getX(), 0);
} }
} }
@ -63,7 +62,7 @@ protected:
_base_gravity_ticks = ticks; _base_gravity_ticks = ticks;
} }
virtual void setWorldTypeSrc( LandType::Value world ); virtual void setWorldTypeSrc(LandType::Value world);
private: private:
bool _tool = false; bool _tool = false;
@ -76,22 +75,22 @@ private:
bool _mushroom = false; bool _mushroom = false;
bool _release_coin = false; bool _release_coin = false;
int ticks_to_bounce = 0; int ticks_to_bounce = 0;
SDLPP::Vec2D< double > og_pos = {}; SDLPP::Vec2D<double> og_pos = {};
LandType::Value _type; LandType::Value _type;
SDL_Rect _base_src; SDL_Rect _base_src;
SDLPP::Vec2D<double> _target = {0,0}; SDLPP::Vec2D<double> _target = { 0, 0 };
bool _on_ground = true; bool _on_ground = true;
int _base_gravity_ticks = 1000 / 60; int _base_gravity_ticks = 1000 / 60;
int _ticks_till_gravity = 0; int _ticks_till_gravity = 0;
double _gravity_acceleration = 1.0/(64.0/7.0); double _gravity_acceleration = 1.0 / (64.0 / 7.0);
bool _was_visible = false; bool _was_visible = false;
}; };
extern const std::vector< uint64_t > possibleBlocks; extern const std::vector<uint64_t> possibleBlocks;
extern const std::vector< uint64_t > possibleMods; extern const std::vector<uint64_t> possibleMods;
extern const std::vector< uint64_t > possibleCharacters; extern const std::vector<uint64_t> possibleCharacters;
extern const std::vector< LandType::Value > possibleLands; extern const std::vector<LandType::Value> possibleLands;
struct BlockRole { struct BlockRole {
enum Value { enum Value {
@ -102,18 +101,18 @@ struct BlockRole {
}; };
}; };
std::shared_ptr< MarioBlock > std::shared_ptr<MarioBlock>
createTerrainBlock( uint64_t block_id, LandType::Value type, createTerrainBlock(uint64_t block_id, LandType::Value type,
std::shared_ptr< SDLPP::Renderer > &renderer, std::shared_ptr<SDLPP::Renderer> &renderer,
bool destructible = false, bool editor = false ); bool destructible = false, bool editor = false);
std::shared_ptr< MarioBlock > std::shared_ptr<MarioBlock>
createTerrainBlock( uint64_t block_id, LandType::Value type, createTerrainBlock(uint64_t block_id, LandType::Value type,
std::shared_ptr< SDLPP::Renderer > &renderer, int x, int y, std::shared_ptr<SDLPP::Renderer> &renderer, int x, int y,
bool destructible = false, bool editor = false ); bool destructible = false, bool editor = false);
std::shared_ptr< MarioBlock > std::shared_ptr<MarioBlock>
createMario( LandType::Value type, std::shared_ptr< SDLPP::Renderer > &renderer, createMario(LandType::Value type, std::shared_ptr<SDLPP::Renderer> &renderer,
int x, int y, bool editor = false ); int x, int y, bool editor = false);
enum BlockRole::Value getBlockRole( uint64_t id ); enum BlockRole::Value getBlockRole(uint64_t id);
#endif #endif

View File

@ -3,20 +3,24 @@
#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);
setColiderColor("#FF00AA"); setColiderColor("#FF00AA");
setPermanent(); setPermanent();
setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER); setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
addCollision(SDLPP::RectColider(0,0,1,1)); addCollision(SDLPP::RectColider(0, 0, 1, 1));
} }
SDLPP::Vec2D<int> EditBox::getIndexes() const { SDLPP::Vec2D<int> EditBox::getIndexes() const {
return {_x, _y}; return { _x, _y };
} }
void EditBox::visit( SDLPP::Visitor &visitor ) { void EditBox::visit(SDLPP::Visitor &visitor) {
visitor.visit( *this ); visitor.visit(*this);
} }

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;

File diff suppressed because it is too large Load Diff

View File

@ -16,9 +16,9 @@
#define SELECTED_RIGHT_CHARACTER 0x00000100 #define SELECTED_RIGHT_CHARACTER 0x00000100
#define SELECTED_LEFT_CHARACTER 0x00000200 #define SELECTED_LEFT_CHARACTER 0x00000200
void MouseVisitor::visit( const SDLPP::RenderObject &obj ) { void MouseVisitor::visit(const SDLPP::RenderObject &obj) {
auto id = obj.getId(); auto id = obj.getId();
switch ( id ) { switch (id) {
case EDITOR_LEFT_MAP_ID: case EDITOR_LEFT_MAP_ID:
select_flags |= SELECTED_LEFT_MAP; select_flags |= SELECTED_LEFT_MAP;
break; break;
@ -45,72 +45,72 @@ void MouseVisitor::visit( const SDLPP::RenderObject &obj ) {
break; break;
case EDITOR_EDIT_SQUARE: case EDITOR_EDIT_SQUARE:
edit_box = true; edit_box = true;
edit_box_location = dynamic_cast< const EditBox & >( obj ).getIndexes(); edit_box_location = dynamic_cast<const EditBox &>(obj).getIndexes();
break; break;
case EDITOR_TOOL_ID: case EDITOR_TOOL_ID:
tool_box = true; tool_box = true;
tool_box_location = dynamic_cast< const ToolBox & >( obj ).getIndexes(); tool_box_location = dynamic_cast<const ToolBox &>(obj).getIndexes();
tool_box_type = dynamic_cast< const ToolBox & >( obj ).getType(); tool_box_type = dynamic_cast<const ToolBox &>(obj).getType();
break; break;
default: default:
break; break;
} }
} }
bool MouseVisitor::moveMapLeft( uint64_t flags ) { bool MouseVisitor::moveMapLeft(uint64_t flags) {
return flags & SELECTED_LEFT_MAP; return flags & SELECTED_LEFT_MAP;
} }
bool MouseVisitor::moveMapRight( uint64_t flags ) { bool MouseVisitor::moveMapRight(uint64_t flags) {
return flags & SELECTED_RIGHT_MAP; return flags & SELECTED_RIGHT_MAP;
} }
bool MouseVisitor::moveToolsLeft( uint64_t flags ) { bool MouseVisitor::moveToolsLeft(uint64_t flags) {
return flags & SELECTED_LEFT_TOOL; return flags & SELECTED_LEFT_TOOL;
} }
bool MouseVisitor::moveToolsRight( uint64_t flags ) { bool MouseVisitor::moveToolsRight(uint64_t flags) {
return flags & SELECTED_RIGHT_TOOL; return flags & SELECTED_RIGHT_TOOL;
} }
bool MouseVisitor::moveModsLeft( uint64_t flags ) { bool MouseVisitor::moveModsLeft(uint64_t flags) {
return flags & SELECTED_LEFT_MOD; return flags & SELECTED_LEFT_MOD;
} }
bool MouseVisitor::moveModsRight( uint64_t flags ) { bool MouseVisitor::moveModsRight(uint64_t flags) {
return flags & SELECTED_RIGHT_MOD; return flags & SELECTED_RIGHT_MOD;
} }
bool MouseVisitor::moveCharactersLeft( uint64_t flags ) { bool MouseVisitor::moveCharactersLeft(uint64_t flags) {
return flags & SELECTED_LEFT_CHARACTER; return flags & SELECTED_LEFT_CHARACTER;
} }
bool MouseVisitor::moveCharactersRight( uint64_t flags ) { bool MouseVisitor::moveCharactersRight(uint64_t flags) {
return flags & SELECTED_RIGHT_CHARACTER; return flags & SELECTED_RIGHT_CHARACTER;
} }
void ToolVisitor::visit( const SDLPP::RenderObject &obj ) { void ToolVisitor::visit(const SDLPP::RenderObject &obj) {
auto id = obj.getCollisions()[0]->getId(); auto id = obj.getCollisions()[0]->getId();
switch ( id ) { switch (id) {
case EDITOR_TERRAIN_ID: { case EDITOR_TERRAIN_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::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;
} }
} }
default: default:
break; break;
} }

View File

@ -17,8 +17,8 @@ struct VisitorType {
class MouseVisitor : public SDLPP::Visitor { class MouseVisitor : public SDLPP::Visitor {
public: public:
MouseVisitor() = default; MouseVisitor() = default;
void visit( const SDLPP::RenderObject &obj ) override; void visit(const SDLPP::RenderObject &obj) override;
void setFromId( uint64_t /*UNUSED*/ ) override {} void setFromId(uint64_t /*UNUSED*/) override {}
uint64_t getFromId() const override { uint64_t getFromId() const override {
return 0; return 0;
} }
@ -28,16 +28,16 @@ public:
bool foundEditBox() const { bool foundEditBox() const {
return edit_box; return edit_box;
} }
const SDLPP::Vec2D< int > &getEditBoxIndexes() const { const SDLPP::Vec2D<int> &getEditBoxIndexes() const {
return edit_box_location; return edit_box_location;
} }
bool foundToolBox() const { bool foundToolBox() const {
return tool_box; return tool_box;
} }
const SDLPP::Vec2D< int > &getToolBoxIndexes() const { const SDLPP::Vec2D<int> &getToolBoxIndexes() const {
return tool_box_location; return tool_box_location;
} }
void setVisitorType( uint64_t type ) override { void setVisitorType(uint64_t type) override {
_type = type; _type = type;
} }
uint64_t getVisitorType() const override { uint64_t getVisitorType() const override {
@ -47,21 +47,21 @@ public:
return tool_box_type; return tool_box_type;
} }
static bool moveMapLeft( uint64_t flags ); static bool moveMapLeft(uint64_t flags);
static bool moveMapRight( uint64_t flags ); static bool moveMapRight(uint64_t flags);
static bool moveToolsLeft( uint64_t flags ); static bool moveToolsLeft(uint64_t flags);
static bool moveToolsRight( uint64_t flags ); static bool moveToolsRight(uint64_t flags);
static bool moveModsLeft( uint64_t flags ); static bool moveModsLeft(uint64_t flags);
static bool moveModsRight( uint64_t flags ); static bool moveModsRight(uint64_t flags);
static bool moveCharactersLeft( uint64_t flags ); static bool moveCharactersLeft(uint64_t flags);
static bool moveCharactersRight( uint64_t flags ); static bool moveCharactersRight(uint64_t flags);
private: private:
uint64_t select_flags = 0; uint64_t select_flags = 0;
bool edit_box = false; bool edit_box = false;
bool tool_box = false; bool tool_box = false;
SDLPP::Vec2D< int > edit_box_location = { -1, -1 }; SDLPP::Vec2D<int> edit_box_location = { -1, -1 };
SDLPP::Vec2D< int > tool_box_location = { -1, -1 }; SDLPP::Vec2D<int> tool_box_location = { -1, -1 };
uint64_t _type{}; uint64_t _type{};
uint64_t tool_box_type = 0; uint64_t tool_box_type = 0;
}; };
@ -69,14 +69,14 @@ private:
class ToolVisitor : public SDLPP::Visitor { class ToolVisitor : public SDLPP::Visitor {
public: public:
ToolVisitor() = default; ToolVisitor() = default;
void visit( const SDLPP::RenderObject &obj ) override; void visit(const SDLPP::RenderObject &obj) override;
void setFromId( uint64_t id ) override { void setFromId(uint64_t id) override {
source_id = id; source_id = id;
} }
uint64_t getFromId() const override { uint64_t getFromId() const override {
return source_id; return source_id;
} }
void setVisitorType( uint64_t type ) override { void setVisitorType(uint64_t type) override {
_type = type; _type = type;
} }
uint64_t getVisitorType() const override { uint64_t getVisitorType() const override {

View File

@ -1,12 +1,12 @@
#include "global_vars.hpp" #include "global_vars.hpp"
#include "../sdlpp/sdlpp_texture.hpp" #include "../sdlpp/sdlpp_texture.hpp"
std::shared_ptr< SDLPP::Texture > g_terrain_texture{}; std::shared_ptr<SDLPP::Texture> g_terrain_texture{};
std::shared_ptr< SDLPP::Texture > g_mario_texture{}; std::shared_ptr<SDLPP::Texture> g_mario_texture{};
std::shared_ptr< SDLPP::Texture > g_mod_texture{}; std::shared_ptr<SDLPP::Texture> g_mod_texture{};
std::shared_ptr< SDLPP::Texture > g_enemies_texture{}; std::shared_ptr<SDLPP::Texture> g_enemies_texture{};
std::shared_ptr< SDLPP::Texture > g_translucent_terrain_texture{}; std::shared_ptr<SDLPP::Texture> g_translucent_terrain_texture{};
std::shared_ptr< SDLPP::Texture > g_translucent_mod_texture{}; std::shared_ptr<SDLPP::Texture> g_translucent_mod_texture{};
std::shared_ptr< SDLPP::Texture > g_translucent_enemies_texture; std::shared_ptr<SDLPP::Texture> g_translucent_enemies_texture;
std::shared_ptr< SDLPP::Scene > g_playground{}; std::shared_ptr<SDLPP::Scene> g_playground{};
std::shared_ptr< SDLPP::FontConfiguration > g_text_config{}; std::shared_ptr<SDLPP::FontConfiguration> g_text_config{};

View File

@ -3,14 +3,14 @@
#include "../sdlpp/sdlpp.hpp" #include "../sdlpp/sdlpp.hpp"
extern std::shared_ptr< SDLPP::Texture > g_terrain_texture; extern std::shared_ptr<SDLPP::Texture> g_terrain_texture;
extern std::shared_ptr< SDLPP::Texture > g_mario_texture; extern std::shared_ptr<SDLPP::Texture> g_mario_texture;
extern std::shared_ptr< SDLPP::Texture > g_mod_texture; extern std::shared_ptr<SDLPP::Texture> g_mod_texture;
extern std::shared_ptr< SDLPP::Texture > g_enemies_texture; extern std::shared_ptr<SDLPP::Texture> g_enemies_texture;
extern std::shared_ptr< SDLPP::Texture > g_translucent_terrain_texture; extern std::shared_ptr<SDLPP::Texture> g_translucent_terrain_texture;
extern std::shared_ptr< SDLPP::Texture > g_translucent_mod_texture; extern std::shared_ptr<SDLPP::Texture> g_translucent_mod_texture;
extern std::shared_ptr< SDLPP::Texture > g_translucent_enemies_texture; extern std::shared_ptr<SDLPP::Texture> g_translucent_enemies_texture;
extern std::shared_ptr< SDLPP::Scene > g_playground; extern std::shared_ptr<SDLPP::Scene> g_playground;
extern std::shared_ptr< SDLPP::FontConfiguration > g_text_config; extern std::shared_ptr<SDLPP::FontConfiguration> g_text_config;
#endif #endif

View File

@ -22,20 +22,20 @@
bool quit = false; bool quit = false;
bool update = false; bool update = false;
std::shared_ptr< Mario > mario = nullptr; std::shared_ptr<Mario> mario = nullptr;
std::shared_ptr< SDLPP::RectangleRender > leftStop = nullptr; std::shared_ptr<SDLPP::RectangleRender> leftStop = nullptr;
std::shared_ptr< SDLPP::Renderer > renderer = nullptr; std::shared_ptr<SDLPP::Renderer> renderer = nullptr;
std::shared_ptr< SDLPP::TextRenderer > fps = nullptr; std::shared_ptr<SDLPP::TextRenderer> fps = nullptr;
std::shared_ptr< SDLPP::TextRenderer > coins = nullptr; std::shared_ptr<SDLPP::TextRenderer> coins = nullptr;
int coin_count = 0; int coin_count = 0;
int global_frames = 0; int global_frames = 0;
std::vector< std::shared_ptr< MarioBlock > > moving_objects = {}; std::vector<std::shared_ptr<MarioBlock>> moving_objects = {};
std::mutex render_mutex; std::mutex render_mutex;
void handleKeyDown( SDL_Keycode key, SDLPP::Scene &scene ) { void handleKeyDown(SDL_Keycode key, SDLPP::Scene &scene) {
switch ( key ) { switch (key) {
case SDLK_ESCAPE: case SDLK_ESCAPE:
quit = true; quit = true;
break; break;
@ -53,19 +53,19 @@ void handleKeyDown( SDL_Keycode key, SDLPP::Scene &scene ) {
break; break;
case SDLK_r: case SDLK_r:
scene.getRenderer().setRenderColiders( scene.getRenderer().setRenderColiders(
!scene.getRenderer().getRenderColiders() ); !scene.getRenderer().getRenderColiders());
break; break;
case SDLK_f: case SDLK_f:
if ( fps ) { if (fps) {
fps->setHidden( !fps->getHidden() ); fps->setHidden(!fps->getHidden());
} }
default: default:
break; break;
} }
} }
void handleKeyUp( SDL_Keycode key ) { void handleKeyUp(SDL_Keycode key) {
switch ( key ) { switch (key) {
case SDLK_a: case SDLK_a:
mario->walkRight(); mario->walkRight();
break; break;
@ -80,52 +80,53 @@ void handleKeyUp( SDL_Keycode key ) {
} }
} }
void moveToMarioPosition( SDLPP::Scene &scene, void moveToMarioPosition(SDLPP::Scene &scene,
SDLPP::Vec2D< double > &prev_mario ) { SDLPP::Vec2D<double> &prev_mario) {
auto rendDims = renderer->getDoubleDimensions(); auto rendDims = renderer->getDoubleDimensions();
if ( leftStop ) { if (leftStop) {
auto left = auto left =
rendDims.getX() < 2.0 ? -( rendDims.getX() - 1 ) / 2.0 - 0.1 : -0.5; rendDims.getX() < 2.0 ? -(rendDims.getX() - 1) / 2.0 - 0.1 : -0.5;
leftStop->setPos( left, 0 ); leftStop->setPos(left, 0);
} }
auto mario_pos_difference = prev_mario - mario->getAbsolutePos(); auto mario_pos_difference = prev_mario - mario->getAbsolutePos();
// 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 {
scene.moveEverything( mario_pos_difference.getX(), 0 ); scene.moveEverything(mario_pos_difference.getX(), 0);
} }
scene.updateSizeAndPosition(); scene.updateSizeAndPosition();
auto left_stop_rightmost = leftStop->getDoubleRect().first.getX() + auto left_stop_rightmost = leftStop->getDoubleRect().first.getX() +
leftStop->getDoubleRect().second.getX(); leftStop->getDoubleRect().second.getX();
if ( mario->getPos().getX() < left_stop_rightmost ) { if (mario->getPos().getX() < left_stop_rightmost) {
mario->setPos( left_stop_rightmost, mario->getPos().getY() ); mario->setPos(left_stop_rightmost, mario->getPos().getY());
} }
} }
void pollEvents( SDLPP::Scene &scene ) { void pollEvents(SDLPP::Scene &scene) {
SDL_Event event; SDL_Event event;
while ( SDLPP::getSDLEvent( event ) ) { while (SDLPP::getSDLEvent(event)) {
switch ( event.type ) { switch (event.type) {
case SDL_QUIT: case SDL_QUIT:
quit = true; quit = true;
break; break;
case SDL_KEYDOWN: case SDL_KEYDOWN:
if ( !event.key.repeat ) { if (!event.key.repeat) {
handleKeyDown( event.key.keysym.sym, scene ); handleKeyDown(event.key.keysym.sym, scene);
} }
break; break;
case SDL_KEYUP: case SDL_KEYUP:
handleKeyUp( event.key.keysym.sym ); handleKeyUp(event.key.keysym.sym);
break; break;
case SDL_WINDOWEVENT: case SDL_WINDOWEVENT:
if ( event.window.event == SDL_WINDOWEVENT_RESIZED ) { if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
auto prev_mario_pos = mario->getAbsolutePos(); auto prev_mario_pos = mario->getAbsolutePos();
scene.updateSizeAndPosition(); scene.updateSizeAndPosition();
moveToMarioPosition( scene, prev_mario_pos ); moveToMarioPosition(scene, prev_mario_pos);
update = true; update = true;
} }
default: default:
@ -134,45 +135,46 @@ void pollEvents( SDLPP::Scene &scene ) {
} }
} }
void doInput( std::shared_ptr< SDLPP::Scene > scene ) { void doInput(std::shared_ptr<SDLPP::Scene> scene) {
FPSmanager gFPS; FPSmanager gFPS;
SDL_initFramerate( &gFPS ); SDL_initFramerate(&gFPS);
SDL_setFramerate( &gFPS, 200 ); SDL_setFramerate(&gFPS, 200);
while ( !quit ) { while (!quit) {
SDL_framerateDelay( &gFPS ); SDL_framerateDelay(&gFPS);
pollEvents( *scene ); pollEvents(*scene);
std::lock_guard< std::mutex > lock( render_mutex ); std::lock_guard<std::mutex> lock(render_mutex);
scene->updateScene(); scene->updateScene();
auto prev_coin_count = coin_count; auto prev_coin_count = coin_count;
auto rightmost_x = renderer->getDoubleDimensions().getX(); auto rightmost_x = renderer->getDoubleDimensions().getX();
for(size_t i = 0; i < moving_objects.size(); i++) { for (size_t i = 0; i < moving_objects.size(); i++) {
moving_objects[i]->checkVisibility(rightmost_x); moving_objects[i]->checkVisibility(rightmost_x);
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]->getDoubleRect().second.getX(); moving_objects[i]->getAbsolutePos().getX() +
if(rightmost_pos < 0 && moving_objects[i] != mario) { moving_objects[i]->getDoubleRect().second.getX();
if (rightmost_pos < 0 && moving_objects[i] != mario) {
moving_objects[i]->destroy(); moving_objects[i]->destroy();
} }
} }
std::vector<uint64_t> killed_indices{}; std::vector<uint64_t> killed_indices{};
for(size_t i = 0; i < moving_objects.size(); i++) { for (size_t i = 0; i < moving_objects.size(); i++) {
if(moving_objects[i]->getKilled()) { if (moving_objects[i]->getKilled()) {
killed_indices.push_back(i); killed_indices.push_back(i);
} }
} }
std::reverse( killed_indices.begin(), killed_indices.end() ); std::reverse(killed_indices.begin(), killed_indices.end());
for(auto &index : killed_indices) { for (auto &index : killed_indices) {
moving_objects.erase(moving_objects.begin() + index); moving_objects.erase(moving_objects.begin() + index);
} }
if ( coin_count != prev_coin_count ) { if (coin_count != prev_coin_count) {
coins->changeText( std::to_string( coin_count ) + " COINS" ); coins->changeText(std::to_string(coin_count) + " COINS");
} }
// if player is > 0.7 of playground, move everything left // if player is > 0.7 of playground, move everything left
auto playerX = mario->getRect().x; auto playerX = mario->getRect().x;
@ -180,108 +182,110 @@ 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);
global_frames++; global_frames++;
} }
} }
#ifdef _WIN32 #ifdef _WIN32
int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PWSTR szCmdLine, int nCmdShow ) { PWSTR szCmdLine, int nCmdShow) {
#else #else
int main() { int main() {
#endif #endif
SDLPP::init(); SDLPP::init();
SDLPP::Window w( "Mario clone!" ); SDLPP::Window w("Mario clone!");
w.setResizable( true ); w.setResizable(true);
renderer = std::make_shared< SDLPP::Renderer >( w ); renderer = std::make_shared<SDLPP::Renderer>(w);
renderer->setBlendMode( SDL_BLENDMODE_BLEND ); renderer->setBlendMode(SDL_BLENDMODE_BLEND);
// prepare global vars // prepare global vars
g_terrain_texture = std::make_shared< SDLPP::Texture >( g_terrain_texture = std::make_shared<SDLPP::Texture>(
renderer, "sprites/terrain.png", MARIO_OVERWORLD_COLORKEY ); renderer, "sprites/terrain.png", MARIO_OVERWORLD_COLORKEY);
g_enemies_texture = std::make_shared< SDLPP::Texture >( g_enemies_texture = std::make_shared<SDLPP::Texture>(
renderer, "sprites/enemies.png", MARIO_OVERWORLD_COLORKEY ); renderer, "sprites/enemies.png", MARIO_OVERWORLD_COLORKEY);
auto scene = std::make_shared< SDLPP::Scene >( renderer ); auto scene = std::make_shared<SDLPP::Scene>(renderer);
g_playground = scene; g_playground = scene;
auto bg = std::make_shared< SDLPP::RectangleRender >( auto bg = std::make_shared<SDLPP::RectangleRender>(
0, 0, 10, 10, renderer, MARIO_OVERWORLD_COLORKEY, true ); 0, 0, 10, 10, renderer, MARIO_OVERWORLD_COLORKEY, true);
bg->setPermanent(); bg->setPermanent();
bg->setStatic(); bg->setStatic();
bg->setId( 1 ); bg->setId(1);
scene->addObject( bg ); scene->addObject(bg);
g_mario_texture = std::make_shared< SDLPP::Texture >( g_mario_texture = std::make_shared<SDLPP::Texture>(
renderer, "sprites/mario.png", MARIO_OVERWORLD_COLORKEY ); renderer, "sprites/mario.png", MARIO_OVERWORLD_COLORKEY);
g_translucent_terrain_texture = std::make_shared< SDLPP::Texture >( g_translucent_terrain_texture = std::make_shared<SDLPP::Texture>(
renderer, "sprites/terrain.png", MARIO_OVERWORLD_COLORKEY ); renderer, "sprites/terrain.png", MARIO_OVERWORLD_COLORKEY);
g_translucent_terrain_texture->setAlpha( 100 ); g_translucent_terrain_texture->setAlpha(100);
mario = std::make_shared< Mario >( renderer ); mario = std::make_shared<Mario>(renderer);
scene->addObject( mario ); scene->addObject(mario);
auto defeat = auto defeat =
std::make_shared< SDLPP::RectangleRender >( 0, 1.01, 0, 0, renderer ); std::make_shared<SDLPP::RectangleRender>(0, 1.01, 0, 0, renderer);
defeat->setId( DEATH_ID ); defeat->setId(DEATH_ID);
defeat->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER ); defeat->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
defeat->setPermanent(); defeat->setPermanent();
auto defeatCol = SDLPP::RectColider( -1, 0, -1, -1 ); auto defeatCol = SDLPP::RectColider(-1, 0, -1, -1);
defeatCol.setInfinite(); defeatCol.setInfinite();
defeat->addCollision( defeatCol ); defeat->addCollision(defeatCol);
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();
auto leftStopCol = SDLPP::RectColider( 0, -1, 1, -1 ); auto leftStopCol = SDLPP::RectColider(0, -1, 1, -1);
leftStopCol.setInfinite(); leftStopCol.setInfinite();
leftStop->addCollision( leftStopCol ); leftStop->addCollision(leftStopCol);
leftStop->setColiderColor( "#FF00FF" ); leftStop->setColiderColor("#FF00FF");
scene->addObject( leftStop ); scene->addObject(leftStop);
loadMap( scene, mario, "test_binary2.bin" ); loadMap(scene, mario, "test_binary2.bin");
auto font = std::make_shared< SDLPP::Font >( "testfont.ttf", 36 ); auto font = std::make_shared<SDLPP::Font>("testfont.ttf", 36);
fps = std::make_shared< SDLPP::TextRenderer >( fps = std::make_shared<SDLPP::TextRenderer>(
0.2, 0, 0.78, 0.1, renderer, font, "0fps", "#FFFFFF", "#000000", 0.1, 0.2, 0, 0.78, 0.1, renderer, font, "0fps", "#FFFFFF", "#000000", 0.1,
SDLPP_TEXT_RIGHT ); SDLPP_TEXT_RIGHT);
fps->setAlignment( SDLPP::OBJ_END, SDLPP::OBJ_START ); fps->setAlignment(SDLPP::OBJ_END, SDLPP::OBJ_START);
fps->setId( 0 ); fps->setId(0);
fps->setPermanent(); fps->setPermanent();
fps->setHidden( true ); fps->setHidden(true);
scene->addObject( fps ); scene->addObject(fps);
coins = std::make_shared< SDLPP::TextRenderer >( coins = std::make_shared<SDLPP::TextRenderer>(
0.2, 0, 0.78, 0.1, renderer, font, "0 COINS", "#FFFFFF", "#000000", 0.1, 0.2, 0, 0.78, 0.1, renderer, font, "0 COINS", "#FFFFFF", "#000000", 0.1,
SDLPP_TEXT_RIGHT ); SDLPP_TEXT_RIGHT);
coins->setAlignment( SDLPP::OBJ_START, SDLPP::OBJ_START ); coins->setAlignment(SDLPP::OBJ_START, SDLPP::OBJ_START);
coins->setId( 0 ); coins->setId(0);
coins->setPermanent(); coins->setPermanent();
scene->addObject( coins ); scene->addObject(coins);
FPSmanager gFPS; FPSmanager gFPS;
SDL_initFramerate( &gFPS ); SDL_initFramerate(&gFPS);
SDL_setFramerate( &gFPS, 60 ); SDL_setFramerate(&gFPS, 60);
auto base = SDL_GetTicks(); auto base = SDL_GetTicks();
int frames = 0; int frames = 0;
scene->moveEverything( -mario->getDoubleRect().first.getX() + 0.2, 0 ); scene->moveEverything(-mario->getDoubleRect().first.getX() + 0.2, 0);
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();
@ -290,35 +294,35 @@ int main() {
std::unordered_set<int> moving_object_ids = { std::unordered_set<int> moving_object_ids = {
GOOMBA_ID, GOOMBA_ID,
}; };
for(auto &obj : scene->getObjects(moving_object_ids)) { for (auto &obj : scene->getObjects(moving_object_ids)) {
moving_objects.push_back(std::dynamic_pointer_cast<MarioBlock>(obj)); moving_objects.push_back(std::dynamic_pointer_cast<MarioBlock>(obj));
} }
std::thread inputThread( doInput, scene ); std::thread inputThread(doInput, scene);
SDL_PumpEvents(); SDL_PumpEvents();
scene->updateSizeAndPosition(); scene->updateSizeAndPosition();
scene->renderScene(); scene->renderScene();
renderer->presentRenderer(); renderer->presentRenderer();
update = true; update = true;
while ( !quit ) { while (!quit) {
SDL_framerateDelay( &gFPS ); SDL_framerateDelay(&gFPS);
SDL_PumpEvents(); SDL_PumpEvents();
std::lock_guard< std::mutex > lock( render_mutex ); std::lock_guard<std::mutex> lock(render_mutex);
mario->setStanding(); mario->setStanding();
if ( update ) { if (update) {
scene->updateSizeAndPosition(); scene->updateSizeAndPosition();
update = false; update = false;
} }
scene->renderScene(); scene->renderScene();
renderer->presentRenderer(); renderer->presentRenderer();
frames++; frames++;
if ( SDL_GetTicks() - base >= 1000 ) { if (SDL_GetTicks() - base >= 1000) {
if ( global_frames < frames ) { if (global_frames < frames) {
frames = global_frames; frames = global_frames;
} }
global_frames = 0; global_frames = 0;
fps->changeText( std::to_string( frames ) + " fps" ); fps->changeText(std::to_string(frames) + " fps");
frames = 0; frames = 0;
base = SDL_GetTicks(); base = SDL_GetTicks();
} }

View File

@ -11,213 +11,212 @@
#define WIDE_TERRAIN_HAS_ADDITIONAL 0x8000 #define WIDE_TERRAIN_HAS_ADDITIONAL 0x8000
#define ADDITIONAL_IS_MOD 0x80 #define ADDITIONAL_IS_MOD 0x80
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 > tmp = {}; std::vector<mapColumnType> tmp = {};
loadMap( scene, mario, file, tmp, false ); loadMap(scene, mario, file, tmp, false);
scene->moveZTop( mario ); scene->moveZTop(mario);
} }
uint8_t read8Bits( std::ifstream &file ) { uint8_t read8Bits(std::ifstream &file) {
uint8_t data; uint8_t data;
file.read( ( char * )&data, sizeof( uint8_t ) / sizeof( char ) ); file.read((char *)&data, sizeof(uint8_t) / sizeof(char));
return data; return data;
} }
void write8Bits( std::ofstream &file, uint8_t data ) { void write8Bits(std::ofstream &file, uint8_t data) {
file.write( ( char * )&data, sizeof( uint8_t ) / sizeof( char ) ); file.write((char *)&data, sizeof(uint8_t) / sizeof(char));
} }
uint16_t read16Bits( std::ifstream &file ) { uint16_t read16Bits(std::ifstream &file) {
uint16_t data; uint16_t data;
file.read( ( char * )&data, sizeof( uint16_t ) / sizeof( char ) ); file.read((char *)&data, sizeof(uint16_t) / sizeof(char));
return data; return data;
} }
void write16Bits( std::ofstream &file, uint16_t data ) { void write16Bits(std::ofstream &file, uint16_t data) {
file.write( ( char * )&data, sizeof( uint16_t ) / sizeof( char ) ); file.write((char *)&data, sizeof(uint16_t) / sizeof(char));
} }
std::pair< uint16_t, uint8_t > separateWideTerrain( uint16_t wide_terrain ) { std::pair<uint16_t, uint8_t> separateWideTerrain(uint16_t wide_terrain) {
uint8_t terrain_type = ( wide_terrain & 0xF000 ) >> 12; uint8_t terrain_type = (wide_terrain & 0xF000) >> 12;
uint16_t terrain_id = ( wide_terrain & 0x0FFF ) | BLOCK_PREFIX; uint16_t terrain_id = (wide_terrain & 0x0FFF) | BLOCK_PREFIX;
return { terrain_id, terrain_type }; return { terrain_id, terrain_type };
} }
std::pair< uint8_t, uint8_t > separateAdditionalData( uint8_t data ) { std::pair<uint8_t, uint8_t> separateAdditionalData(uint8_t data) {
auto id = data & 0x0F; auto id = data & 0x0F;
auto type = ( data & 0xF0 ) >> 4; auto type = (data & 0xF0) >> 4;
return { id, type }; return { id, type };
} }
uint16_t combineTerrain( uint16_t id, uint8_t type ) { uint16_t combineTerrain(uint16_t id, uint8_t type) {
uint16_t wide_terrain = type; uint16_t wide_terrain = type;
wide_terrain = wide_terrain << 12; wide_terrain = wide_terrain << 12;
wide_terrain |= 0x0FFF & id; wide_terrain |= 0x0FFF & id;
return wide_terrain; return wide_terrain;
} }
uint8_t combineAdditionalData( uint8_t id, uint8_t type ) { uint8_t combineAdditionalData(uint8_t id, uint8_t type) {
return type << 4 | id; return type << 4 | id;
} }
MapObject parseBlock( std::ifstream &map_file ) { MapObject parseBlock(std::ifstream &map_file) {
uint8_t character_type = 0; uint8_t character_type = 0;
uint8_t character_id = 0; uint8_t character_id = 0;
uint32_t modifier_id = 0; uint32_t modifier_id = 0;
uint8_t modifier_data = 0; uint8_t modifier_data = 0;
uint16_t wide_terrain = read16Bits( map_file ); uint16_t wide_terrain = read16Bits(map_file);
auto terrain = separateWideTerrain( wide_terrain ); auto terrain = separateWideTerrain(wide_terrain);
uint16_t terrain_id = terrain.first; uint16_t terrain_id = terrain.first;
uint8_t terrain_type = terrain.second; uint8_t terrain_type = terrain.second;
if ( terrain_type & TERRAIN_TYPE_HAS_ADDITIONAL ) { if (terrain_type & TERRAIN_TYPE_HAS_ADDITIONAL) {
uint8_t additional_data = read8Bits( map_file ); uint8_t additional_data = read8Bits(map_file);
terrain_type &= ~TERRAIN_TYPE_HAS_ADDITIONAL; terrain_type &= ~TERRAIN_TYPE_HAS_ADDITIONAL;
if ( additional_data & ADDITIONAL_IS_MOD ) { if (additional_data & ADDITIONAL_IS_MOD) {
additional_data &= ~ADDITIONAL_IS_MOD; additional_data &= ~ADDITIONAL_IS_MOD;
auto modifier = separateAdditionalData( additional_data ); auto modifier = separateAdditionalData(additional_data);
// TODO swap modifier id and data // TODO swap modifier id and data
modifier_id = modifier.second | 0x6000; modifier_id = modifier.second | 0x6000;
modifier_data = modifier.first; modifier_data = modifier.first;
} else { } else {
// character // character
auto character = separateAdditionalData( additional_data ); auto character = separateAdditionalData(additional_data);
character_id = character.first; character_id = character.first;
character_type = character.second; character_type = character.second;
} }
} }
return MapObject( terrain_id, terrain_type, character_id, character_type, return MapObject(terrain_id, terrain_type, character_id, character_type,
modifier_id, modifier_data ); modifier_id, modifier_data);
} }
// 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);
uint16_t cols; uint16_t cols;
map_file.read( ( char * )&cols, sizeof( uint16_t ) / sizeof( char ) ); map_file.read((char *)&cols, sizeof(uint16_t) / sizeof(char));
if ( editor ) { if (editor) {
objects.resize( cols ); objects.resize(cols);
} }
mapColumnType *col = nullptr; mapColumnType *col = nullptr;
for ( uint16_t i = 0; i < cols; i++ ) { for (uint16_t i = 0; i < cols; i++) {
if ( editor ) { if (editor) {
col = &objects[i]; col = &objects[i];
} }
for ( int j = 0; j < 16; j++ ) { for (int j = 0; j < 16; j++) {
auto block = parseBlock( map_file ); auto block = parseBlock(map_file);
if ( editor ) { if (editor) {
col->at( j ) = block; col->at(j) = block;
} }
bool destructible = false; bool destructible = false;
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) {
mushroom = true; mushroom = true;
} }
// 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) {
obj->addMushroom(); obj->addMushroom();
} }
if(removeCollisions) { if (removeCollisions) {
obj->removeCollisions(); obj->removeCollisions();
} }
if ( obj != nullptr ) { if (obj != nullptr) {
if ( editor ) { if (editor) {
obj->getCollisions()[0]->setId( EDITOR_TERRAIN_ID ); obj->getCollisions()[0]->setId(EDITOR_TERRAIN_ID);
} }
scene->addObject( obj ); scene->addObject(obj);
} }
} }
} }
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);
} else { } else {
mario->setPos( i * BLOCK_SIZE, mario->setPos(i * BLOCK_SIZE,
1 - ( 16 - j ) * BLOCK_SIZE ); 1 - (16 - j) * BLOCK_SIZE);
} }
} else { } else {
auto obj = createTerrainBlock( auto obj = createTerrainBlock(
block.getCharacterId(), block.getCharacterType(), block.getCharacterId(), block.getCharacterType(),
renderer, i, j, destructible, editor); renderer, i, j, destructible, editor);
dynamic_cast< MarioBlock * >( obj.get() )->setTerrain( false ); dynamic_cast<MarioBlock *>(obj.get())->setTerrain(false);
if ( editor ) { if (editor) {
obj->getCollisions()[0]->setId( EDITOR_CHARACTER_ID ); obj->getCollisions()[0]->setId(EDITOR_CHARACTER_ID);
} }
scene->addObject(obj); scene->addObject(obj);
} }
} }
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);
dynamic_cast< MarioBlock * >( mod.get() )->setTerrain( false ); dynamic_cast<MarioBlock *>(mod.get())->setTerrain(false);
scene->addObject( mod ); scene->addObject(mod);
} }
} }
} }
if ( editor && objects.size() < editor_width ) { if (editor && objects.size() < editor_width) {
objects.resize( editor_width ); objects.resize(editor_width);
} }
} }
void saveMap( const std::string &file, std::vector< mapColumnType > &objects ) { void saveMap(const std::string &file, std::vector<mapColumnType> &objects) {
std::ofstream output_file; std::ofstream output_file;
output_file.open( file, std::ios::out | std::ios::binary ); output_file.open(file, std::ios::out | std::ios::binary);
uint16_t cols = objects.size(); uint16_t cols = objects.size();
output_file.write( ( char * )&cols, sizeof( uint16_t ) / sizeof( char ) ); output_file.write((char *)&cols, sizeof(uint16_t) / sizeof(char));
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;
} }
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(
} else if ( block.hasModifier() ) { block.getCharacterId(), block.getCharacterType());
} 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) {
write8Bits(output_file, additional_data); write8Bits(output_file, additional_data);
} }
} }

View File

@ -5,15 +5,15 @@
#include "../sdlpp/sdlpp_rectrenderer.hpp" #include "../sdlpp/sdlpp_rectrenderer.hpp"
#include "mapobject.hpp" #include "mapobject.hpp"
typedef std::array< MapObject, 16 > mapColumnType; typedef std::array<MapObject, 16> mapColumnType;
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);
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

@ -1,49 +1,48 @@
#include "mapobject.hpp" #include "mapobject.hpp"
MapObject::MapObject( uint16_t terrain_id, LandType::Value terrain_type, MapObject::MapObject(uint16_t terrain_id, LandType::Value terrain_type,
uint8_t character_id, LandType::Value character_type, uint8_t character_id, LandType::Value character_type,
uint32_t modifier_id, uint8_t modifier_data ) { uint32_t modifier_id, uint8_t modifier_data) {
setTerrain(terrain_id, terrain_type); setTerrain(terrain_id, terrain_type);
if(character_id != 0) if (character_id != 0)
setCharacter(character_id, character_type); setCharacter(character_id, character_type);
if(modifier_id != 0) if (modifier_id != 0)
setModifier(modifier_id, modifier_data); setModifier(modifier_id, modifier_data);
} }
MapObject::MapObject( uint16_t terrain_id, uint8_t terrain_type, 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) {
terrain_id = id; terrain_id = id;
terrain_type = land_type; terrain_type = land_type;
} }
void MapObject::setTerrain( uint16_t id, uint8_t land_type ) { void MapObject::setTerrain(uint16_t id, uint8_t land_type) {
setTerrain( id, static_cast< LandType::Value >( land_type ) ); setTerrain(id, static_cast<LandType::Value>(land_type));
} }
void MapObject::setCharacter( uint8_t id, LandType::Value land_type ) { void MapObject::setCharacter(uint8_t id, LandType::Value land_type) {
character_id = id; character_id = id;
character_type = land_type; character_type = land_type;
if(hasModifier()) { if (hasModifier()) {
modifier_id = 0; modifier_id = 0;
modifier_data = 0; modifier_data = 0;
} }
} }
void MapObject::setCharacter( uint8_t id, uint8_t land_type ) { void MapObject::setCharacter(uint8_t id, uint8_t land_type) {
setCharacter( id, static_cast< LandType::Value >( land_type ) ); setCharacter(id, static_cast<LandType::Value>(land_type));
} }
void MapObject::setModifier( uint32_t id, uint8_t data ) { void MapObject::setModifier(uint32_t id, uint8_t data) {
modifier_id = id; modifier_id = id;
modifier_data = data; modifier_data = data;
if(hasCharacter()) { if (hasCharacter()) {
character_id = 0; character_id = 0;
character_type = LandType::OVERWORLD; character_type = LandType::OVERWORLD;
} }
@ -54,14 +53,14 @@ void MapObject::unsetTerrain() {
} }
void MapObject::unsetModifier() { void MapObject::unsetModifier() {
if ( hasModifier() ) { if (hasModifier()) {
setModifier( 0, 0 ); setModifier(0, 0);
} }
} }
void MapObject::unsetCharacter() { void MapObject::unsetCharacter() {
if ( hasCharacter() ) { if (hasCharacter()) {
setCharacter( 0, 0 ); setCharacter(0, 0);
} }
} }

View File

@ -6,17 +6,17 @@
class MapObject { class MapObject {
public: public:
MapObject() = default; MapObject() = default;
MapObject( uint16_t terrain_id, uint8_t terrain_type, uint8_t character_id, MapObject(uint16_t terrain_id, uint8_t terrain_type, uint8_t character_id,
uint8_t character_type, uint32_t modifier_id, uint8_t character_type, uint32_t modifier_id,
uint8_t modifier_data ); uint8_t modifier_data);
MapObject( uint16_t terrain_id, LandType::Value terrain_type, MapObject(uint16_t terrain_id, LandType::Value terrain_type,
uint8_t character_id, LandType::Value character_type, uint8_t character_id, LandType::Value character_type,
uint32_t modifier_id, uint8_t modifier_data ); uint32_t modifier_id, uint8_t modifier_data);
void setTerrain( uint16_t id, LandType::Value land_type ); void setTerrain(uint16_t id, LandType::Value land_type);
void setTerrain( uint16_t id, uint8_t land_type ); void setTerrain(uint16_t id, uint8_t land_type);
void setCharacter( uint8_t id, LandType::Value land_type ); void setCharacter(uint8_t id, LandType::Value land_type);
void setCharacter( uint8_t id, uint8_t land_type ); void setCharacter(uint8_t id, uint8_t land_type);
void setModifier( uint32_t id, uint8_t data ); void setModifier(uint32_t id, uint8_t data);
void unsetTerrain(); void unsetTerrain();
void unsetModifier(); void unsetModifier();
void unsetCharacter(); void unsetCharacter();

View File

@ -4,40 +4,40 @@
#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)
setAnimationFrames( MARIO_WALK_ANIM ); : MarioBlock(x, y, renderer, g_mario_texture, MARIO_STANDING_SRC) {
setId( MARIO_ID ); setAnimationFrames(MARIO_WALK_ANIM);
setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER ); setId(MARIO_ID);
setAnimationSpeed( 12.5 ); setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
setAnimationSpeed(12.5);
pauseAnimation(); pauseAnimation();
setMovement( 0, 0 ); setMovement(0, 0);
setMovementSpeed( 1 ); setMovementSpeed(1);
auto bottom_detect = SDLPP::RectColider( 0.2, 1, 0.6, 0, MARIO_FLOOR_DETECT ); auto bottom_detect = SDLPP::RectColider(0.2, 1, 0.6, 0, MARIO_FLOOR_DETECT);
bottom_detect.setColor("#FF0000"); bottom_detect.setColor("#FF0000");
bottom_detect.setOutlineColor("#FF0000"); bottom_detect.setOutlineColor("#FF0000");
bottom_detect.setMinHeight(1); bottom_detect.setMinHeight(1);
addCollision(bottom_detect); addCollision(bottom_detect);
addCollision(SDLPP::RectColider(0, 0.25, 0.1, 0.6, MARIO_LEFT_SIDE_DETECT));
addCollision( addCollision(
SDLPP::RectColider( 0, 0.25, 0.1, 0.6, MARIO_LEFT_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.9, 0.25, 0.1, 0.6, MARIO_RIGHT_SIDE_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, 0, 0.1, 0.1, MARIO_TOP_LEFT_DETECT ) ); MARIO_TOP_DETECT);
addCollision( addCollision(top_collision);
SDLPP::RectColider( 0.9, 0, 0.1, 0.1, MARIO_TOP_LEFT_DETECT ) ); addCollision(SDLPP::RectColider(0, 1, 1, 0.2, MARIO_ENEMY_DETECT));
top_collision = std::make_shared<SDLPP::RectColider>( 0.5, 0, 0.2, 0.15, MARIO_TOP_DETECT );
addCollision( top_collision );
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();
addMovement( -side_movement, 0 ); addMovement(-side_movement, 0);
if ( getMovement().getX() < 0 && faces_right ) { if (getMovement().getX() < 0 && faces_right) {
flipHorizontally(); flipHorizontally();
top_collision->setPos(0.3, 0); top_collision->setPos(0.3, 0);
updateSizeAndPosition(); updateSizeAndPosition();
@ -46,10 +46,10 @@ void Mario::walkLeft() {
} }
void Mario::walkRight() { void Mario::walkRight() {
if(on_ground) if (on_ground)
resumeAnimation(); resumeAnimation();
addMovement( side_movement, 0 ); addMovement(side_movement, 0);
if ( getMovement().getX() > 0 && !faces_right ) { if (getMovement().getX() > 0 && !faces_right) {
flipHorizontally(); flipHorizontally();
top_collision->setPos(0.5, 0); top_collision->setPos(0.5, 0);
updateSizeAndPosition(); updateSizeAndPosition();
@ -58,70 +58,80 @@ void Mario::walkRight() {
} }
void Mario::setStanding() { void Mario::setStanding() {
if ( getMovement().getX() == 0 ) { if (getMovement().getX() == 0) {
pauseAnimation(); pauseAnimation();
} }
} }
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 -
auto &m_visitor = dynamic_cast<MarioVisitor&>(visitor); // https://web.archive.org/web/20130807122227/http://i276.photobucket.com/albums/kk21/jdaster64/smb_playerphysics.png
auto &m_visitor = dynamic_cast<MarioVisitor &>(visitor);
// handle gravity // handle gravity
on_ground = m_visitor.isOnGround(); on_ground = m_visitor.isOnGround();
if(!jumping && on_ground) { if (!jumping && on_ground) {
resetMovementY(); resetMovementY();
setBaseRect(MARIO_STANDING_SRC); setBaseRect(MARIO_STANDING_SRC);
if(getMovement().getX() != 0) if (getMovement().getX() != 0)
resumeAnimation(); resumeAnimation();
// for some reason falling of the edge causes on_ground to be true, but // for some reason falling of the edge causes on_ground to be true, but
// visitor ground_y is 0 // visitor ground_y is 0
if(m_visitor.getGroundY() != 0) { if (m_visitor.getGroundY() != 0) {
setPos(getPos().getX(), m_visitor.getGroundY() - BLOCK_SIZE); setPos(getPos().getX(), m_visitor.getGroundY() - BLOCK_SIZE);
} }
} }
// if we just left ground gravity didn't work in custom_move // if we just left ground gravity didn't work in custom_move
if(!on_ground && !jumping && getMovement().getY() == 0) { if (!on_ground && !jumping && getMovement().getY() == 0) {
addMovement(0, 2*gravity_add_falling); addMovement(0, 2 * gravity_add_falling);
} }
if(m_visitor.topBlock() && getMovement().getY() < 0) { if (m_visitor.topBlock() && getMovement().getY() < 0) {
resetMovementY(); resetMovementY();
stop_jump = true; stop_jump = true;
} }
if(m_visitor.shouldBounce()) { if (m_visitor.shouldBounce()) {
addMovement(0, -bounce_speed); addMovement(0, -bounce_speed);
} }
// make sure Mario isn't stuck inside a wall // make sure Mario isn't stuck inside a wall
// 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();
if(objPos.getX() < getPos().getX()) { if (objPos.getX() < getPos().getX()) {
setPos( objPos.getX() + BLOCK_SIZE, getPos().getY() ); setPos(objPos.getX() + BLOCK_SIZE, getPos().getY());
} else { } else {
setPos( objPos.getX() - BLOCK_SIZE, getPos().getY() ); setPos(objPos.getX() - BLOCK_SIZE, getPos().getY());
} }
} }
if(m_visitor.hasMushroom()) { if (m_visitor.hasMushroom()) {
setType(LandType::UNDERWORLD); setType(LandType::UNDERWORLD);
} }
#endif #endif
} }
void Mario::jump() { void Mario::jump() {
if(!on_ground) if (!on_ground)
return; return;
jumping = true; jumping = true;
stop_jump = false; stop_jump = false;
max_jump = getPos().getY() - 3*BLOCK_SIZE; max_jump = getPos().getY() - 3 * BLOCK_SIZE;
min_jump = getPos().getY() - 1*BLOCK_SIZE; min_jump = getPos().getY() - 1 * BLOCK_SIZE;
slow_jump = getPos().getY() - 2*BLOCK_SIZE; slow_jump = getPos().getY() - 2 * BLOCK_SIZE;
addMovement( 0, -jump_movement ); addMovement(0, -jump_movement);
ticks_till_gravity = base_gravity_ticks; ticks_till_gravity = base_gravity_ticks;
setBaseRect(MARIO_JUMP_SRC); setBaseRect(MARIO_JUMP_SRC);
pauseAnimation(); pauseAnimation();
@ -131,19 +141,19 @@ void Mario::stopJump() {
stop_jump = true; stop_jump = true;
} }
void Mario::custom_move( int ticks ) { void Mario::custom_move(int ticks) {
MarioBlock::custom_move(ticks); MarioBlock::custom_move(ticks);
if(!jumping && on_ground) if (!jumping && on_ground)
return; return;
if(getMovement().getY() >= 1.0625 * jump_movement) if (getMovement().getY() >= 1.0625 * jump_movement)
return; return;
ticks_till_gravity -= ticks; ticks_till_gravity -= ticks;
if(ticks_till_gravity < 0) { if (ticks_till_gravity < 0) {
if(getMovement().getY() > 0) { if (getMovement().getY() > 0) {
jumping = false; jumping = false;
addMovement(0, gravity_add_jumping); addMovement(0, gravity_add_jumping);
} else { } else {
if(stop_jump) { if (stop_jump) {
addMovement(0, gravity_add_falling); addMovement(0, gravity_add_falling);
} else { } else {
addMovement(0, gravity_add_jumping); addMovement(0, gravity_add_jumping);

View File

@ -7,16 +7,16 @@
class Mario : public MarioBlock { class Mario : public MarioBlock {
public: public:
Mario( int x, int y, const std::shared_ptr< SDLPP::Renderer > &renderer ); Mario(int x, int y, const std::shared_ptr<SDLPP::Renderer> &renderer);
Mario( const std::shared_ptr< SDLPP::Renderer > &renderer ); Mario(const std::shared_ptr<SDLPP::Renderer> &renderer);
void walkLeft(); void walkLeft();
void walkRight(); void walkRight();
void setStanding(); void setStanding();
void handleVisitor( SDLPP::Visitor &visitor ) override; void handleVisitor(SDLPP::Visitor &visitor) override;
void jump(); void jump();
void stopJump(); void stopJump();
void custom_move( int ticks ) override; void custom_move(int ticks) override;
void visit( SDLPP::Visitor &visitor ) override; void visit(SDLPP::Visitor &visitor) override;
private: private:
bool faces_right = true; bool faces_right = true;
@ -32,9 +32,9 @@ private:
// gravity should be added every frame in 60fps game // gravity should be added every frame in 60fps game
const int base_gravity_ticks = 1000 / 60; const int base_gravity_ticks = 1000 / 60;
const double gravity_add_jumping = jump_movement / 32.0; const double gravity_add_jumping = jump_movement / 32.0;
const double gravity_add_falling = jump_movement / ( 64.0 / 7.0 ); const double gravity_add_falling = jump_movement / (64.0 / 7.0);
std::shared_ptr< SDLPP::RectColider > top_collision = nullptr; std::shared_ptr<SDLPP::RectColider> top_collision = nullptr;
void setWorldTypeSrc( LandType::Value world ) override; void setWorldTypeSrc(LandType::Value world) override;
}; };
#endif #endif

View File

@ -6,17 +6,17 @@ const std::string MARIO_OVERWORLD_COLORKEY = "#93bbec";
const SDL_Rect MARIO_STANDING_SRC = { 1, 9, 16, 16 }; const SDL_Rect MARIO_STANDING_SRC = { 1, 9, 16, 16 };
const SDL_Rect MARIO_DEATH_SRC = { 22, 9, 16, 16 }; const SDL_Rect MARIO_DEATH_SRC = { 22, 9, 16, 16 };
const std::vector< SDL_Rect > MARIO_WALK_ANIM = { { 43, 9, 16, 16 }, const std::vector<SDL_Rect> MARIO_WALK_ANIM = { { 43, 9, 16, 16 },
{ 60, 9, 16, 16 }, { 60, 9, 16, 16 },
{ 77, 9, 16, 16 } }; { 77, 9, 16, 16 } };
const SDL_Rect MARIO_CHANGE_DIR_SRC = { 98, 9, 16, 16 }; const SDL_Rect MARIO_CHANGE_DIR_SRC = { 98, 9, 16, 16 };
const SDL_Rect MARIO_JUMP_SRC = { 119, 9, 16, 16 }; 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 };
@ -27,70 +27,70 @@ const SDL_Rect HILL_FILL_SRC = { 171, 97, 16, 16 };
const SDL_Rect HILL_DOTS_RIGHT_SRC = { 154, 97, 16, 16 }; const SDL_Rect HILL_DOTS_RIGHT_SRC = { 154, 97, 16, 16 };
const SDL_Rect HILL_DOTS_LEFT_SRC = { 188, 97, 16, 16 }; const SDL_Rect HILL_DOTS_LEFT_SRC = { 188, 97, 16, 16 };
const SDL_Rect HILL_TOP_SRC = { 171, 63, 16, 16 }; const SDL_Rect HILL_TOP_SRC = { 171, 63, 16, 16 };
const SDL_Rect BUSH_LEFT_SRC = {222,97,16,16}; const SDL_Rect BUSH_LEFT_SRC = { 222, 97, 16, 16 };
const SDL_Rect BUSH_MIDDLE_SRC = {239,97,16,16}; const SDL_Rect BUSH_MIDDLE_SRC = { 239, 97, 16, 16 };
const SDL_Rect BUSH_RIGHT_SRC = {256,97,16,16}; const SDL_Rect BUSH_RIGHT_SRC = { 256, 97, 16, 16 };
const SDL_Rect CLOUD_LEFT_BOTTOM_SRC = {222,80,16,16}; const SDL_Rect CLOUD_LEFT_BOTTOM_SRC = { 222, 80, 16, 16 };
const SDL_Rect CLOUD_MIDDLE_BOTTOM_SRC = {239,80,16,16}; const SDL_Rect CLOUD_MIDDLE_BOTTOM_SRC = { 239, 80, 16, 16 };
const SDL_Rect CLOUD_RIGHT_BOTTOM_SRC = {256,80,16,16}; const SDL_Rect CLOUD_RIGHT_BOTTOM_SRC = { 256, 80, 16, 16 };
const SDL_Rect CLOUD_LEFT_TOP_SRC = {222,63,16,16}; const SDL_Rect CLOUD_LEFT_TOP_SRC = { 222, 63, 16, 16 };
const SDL_Rect CLOUD_MIDDLE_TOP_SRC = {239,63,16,16}; const SDL_Rect CLOUD_MIDDLE_TOP_SRC = { 239, 63, 16, 16 };
const SDL_Rect CLOUD_RIGHT_TOP_SRC = {256,63,16,16}; const SDL_Rect CLOUD_RIGHT_TOP_SRC = { 256, 63, 16, 16 };
const SDL_Rect PIPE_LEFT_BOTTOM_SRC = {103, 63, 16, 16}; const SDL_Rect PIPE_LEFT_BOTTOM_SRC = { 103, 63, 16, 16 };
const SDL_Rect PIPE_LEFT_TOP_SRC = {103, 46, 16, 16}; const SDL_Rect PIPE_LEFT_TOP_SRC = { 103, 46, 16, 16 };
const SDL_Rect PIPE_RIGHT_BOTTOM_SRC = {120, 63, 16, 16}; const SDL_Rect PIPE_RIGHT_BOTTOM_SRC = { 120, 63, 16, 16 };
const SDL_Rect PIPE_RIGHT_TOP_SRC = {120, 46, 16, 16}; const SDL_Rect PIPE_RIGHT_TOP_SRC = { 120, 46, 16, 16 };
const SDL_Rect CASTLE_LEFT_SRC = {69, 131, 16, 16}; const SDL_Rect CASTLE_LEFT_SRC = { 69, 131, 16, 16 };
const SDL_Rect CASTLE_RIGHT_SRC = {103, 131, 16, 16}; const SDL_Rect CASTLE_RIGHT_SRC = { 103, 131, 16, 16 };
const SDL_Rect CASTLE_BLACK_SRC = {86, 131, 16, 16}; const SDL_Rect CASTLE_BLACK_SRC = { 86, 131, 16, 16 };
const SDL_Rect CASTLE_ENTRY_SRC = {86, 114, 16, 16}; const SDL_Rect CASTLE_ENTRY_SRC = { 86, 114, 16, 16 };
const SDL_Rect CASTLE_TOWER_SRC = {69, 114, 16, 16}; const SDL_Rect CASTLE_TOWER_SRC = { 69, 114, 16, 16 };
const SDL_Rect CASTLE_TOWER_FILLED_SRC = {103, 114, 16, 16}; const SDL_Rect CASTLE_TOWER_FILLED_SRC = { 103, 114, 16, 16 };
const SDL_Rect VINE_TOP_SRC = {69, 29, 16, 16}; const SDL_Rect VINE_TOP_SRC = { 69, 29, 16, 16 };
const SDL_Rect VINE_BOTTOM_SRC = {69, 46, 16, 16}; const SDL_Rect VINE_BOTTOM_SRC = { 69, 46, 16, 16 };
const SDL_Rect POLE_TOP_SRC = {86, 29, 16, 16}; const SDL_Rect POLE_TOP_SRC = { 86, 29, 16, 16 };
const SDL_Rect POLE_BOTTOM_SRC = {86, 46, 16, 16}; const SDL_Rect POLE_BOTTOM_SRC = { 86, 46, 16, 16 };
const SDL_Rect FLAG_SRC = {137, 46, 16, 16}; const SDL_Rect FLAG_SRC = { 137, 46, 16, 16 };
const SDL_Rect STEP_SRC = {86, 63, 16, 16}; const SDL_Rect STEP_SRC = { 86, 63, 16, 16 };
const SDL_Rect BRICK_SRC = {35, 97, 16, 16}; const SDL_Rect BRICK_SRC = { 35, 97, 16, 16 };
const SDL_Rect BRICK_TOP_SRC = {18, 97, 16, 16}; const SDL_Rect BRICK_TOP_SRC = { 18, 97, 16, 16 };
const SDL_Rect SIDEWAY_PIPE_END_TOP_SRC = {69, 80, 16, 16}; const SDL_Rect SIDEWAY_PIPE_END_TOP_SRC = { 69, 80, 16, 16 };
const SDL_Rect SIDEWAY_PIPE_END_BOTTOM_SRC = {69, 97, 16, 16}; const SDL_Rect SIDEWAY_PIPE_END_BOTTOM_SRC = { 69, 97, 16, 16 };
const SDL_Rect SIDEWAY_PIPE_MIDDLE_TOP_SRC = {86, 80, 16, 16}; const SDL_Rect SIDEWAY_PIPE_MIDDLE_TOP_SRC = { 86, 80, 16, 16 };
const SDL_Rect SIDEWAY_PIPE_MIDDLE_BOTTOM_SRC = {86, 97, 16, 16}; const SDL_Rect SIDEWAY_PIPE_MIDDLE_BOTTOM_SRC = { 86, 97, 16, 16 };
const SDL_Rect SIDEWAY_PIPE_CONNECTOR_TOP_SRC = {103, 80, 16, 16}; const SDL_Rect SIDEWAY_PIPE_CONNECTOR_TOP_SRC = { 103, 80, 16, 16 };
const SDL_Rect SIDEWAY_PIPE_CONNECTOR_BOTTOM_SRC = {103, 97, 16, 16}; const SDL_Rect SIDEWAY_PIPE_CONNECTOR_BOTTOM_SRC = { 103, 97, 16, 16 };
const SDL_Rect TREE_PLATFORM_TOP_LEFT_SRC = {137, 12, 16, 16}; const SDL_Rect TREE_PLATFORM_TOP_LEFT_SRC = { 137, 12, 16, 16 };
const SDL_Rect TREE_PLATFORM_TOP_MIDDLE_SRC = {154, 12, 16, 16}; const SDL_Rect TREE_PLATFORM_TOP_MIDDLE_SRC = { 154, 12, 16, 16 };
const SDL_Rect TREE_PLATFORM_TOP_RIGHT_SRC = {171, 12, 16, 16}; const SDL_Rect TREE_PLATFORM_TOP_RIGHT_SRC = { 171, 12, 16, 16 };
const SDL_Rect TREE_PLATFORM_BARK_SRC = {154, 46, 16, 16}; const SDL_Rect TREE_PLATFORM_BARK_SRC = { 154, 46, 16, 16 };
const SDL_Rect WATER_TOP_SRC = {171, 29, 16, 16}; const SDL_Rect WATER_TOP_SRC = { 171, 29, 16, 16 };
const SDL_Rect WATER_FILL_SRC = {171, 46, 16, 16}; const SDL_Rect WATER_FILL_SRC = { 171, 46, 16, 16 };
const SDL_Rect MUSHROOM_PLATFORM_TOP_LEFT_SRC = {188, 12, 16, 16}; const SDL_Rect MUSHROOM_PLATFORM_TOP_LEFT_SRC = { 188, 12, 16, 16 };
const SDL_Rect MUSHROOM_PLATFORM_TOP_MIDDLE_SRC = {205, 12, 16, 16}; const SDL_Rect MUSHROOM_PLATFORM_TOP_MIDDLE_SRC = { 205, 12, 16, 16 };
const SDL_Rect MUSHROOM_PLATFORM_TOP_RIGHT_SRC = {222, 12, 16, 16}; const SDL_Rect MUSHROOM_PLATFORM_TOP_RIGHT_SRC = { 222, 12, 16, 16 };
const SDL_Rect MUSHROOM_PLATFORM_BARK_TOP_SRC = {205, 29, 16, 16}; const SDL_Rect MUSHROOM_PLATFORM_BARK_TOP_SRC = { 205, 29, 16, 16 };
const SDL_Rect MUSHROOM_PLATFORM_BARK_BOTTOM_SRC = {205, 46, 16, 16}; const SDL_Rect MUSHROOM_PLATFORM_BARK_BOTTOM_SRC = { 205, 46, 16, 16 };
const SDL_Rect TREE_BARK_SRC = {222, 46, 16, 16}; const SDL_Rect TREE_BARK_SRC = { 222, 46, 16, 16 };
const SDL_Rect TREE_LEAVES_SMALL_SRC = {222, 29, 16, 16}; const SDL_Rect TREE_LEAVES_SMALL_SRC = { 222, 29, 16, 16 };
const SDL_Rect TREE_LEAVES_TOP_SRC = {239, 12, 16, 16}; const SDL_Rect TREE_LEAVES_TOP_SRC = { 239, 12, 16, 16 };
const SDL_Rect TREE_LEAVES_BOTTOM_SRC = {239, 29, 16, 16}; const SDL_Rect TREE_LEAVES_BOTTOM_SRC = { 239, 29, 16, 16 };
const SDL_Rect CANNON_TOWER_SRC = {256, 46, 16, 16}; const SDL_Rect CANNON_TOWER_SRC = { 256, 46, 16, 16 };
const SDL_Rect CANNON_PEDESTAL_SRC = {256, 29, 16, 16}; const SDL_Rect CANNON_PEDESTAL_SRC = { 256, 29, 16, 16 };
const SDL_Rect CANNON_SRC = {256, 12, 16, 16}; const SDL_Rect CANNON_SRC = { 256, 12, 16, 16 };
const SDL_Rect COIN_SRC = {549, 202, 16, 16}; const SDL_Rect COIN_SRC = { 549, 202, 16, 16 };
const SDL_Rect MUSHROOM_SRC = {69, 12, 16, 16}; const SDL_Rect MUSHROOM_SRC = { 69, 12, 16, 16 };
extern const SDL_Rect MOD_DESTRUCTIBLE_SRC = {0, 0, 16, 16}; extern const SDL_Rect MOD_DESTRUCTIBLE_SRC = { 0, 0, 16, 16 };
extern const SDL_Rect MOD_BACKGROUND_SRC = {16, 0, 16, 16}; extern const SDL_Rect MOD_BACKGROUND_SRC = { 16, 0, 16, 16 };
extern const SDL_Rect MOD_COIN_SRC = {32, 0, 16, 16}; extern const SDL_Rect MOD_COIN_SRC = { 32, 0, 16, 16 };
extern const SDL_Rect MOD_MUSHROOM_SRC = {48, 0, 16, 16}; extern const SDL_Rect MOD_MUSHROOM_SRC = { 48, 0, 16, 16 };
const SDLPP::Vec2D<uint64_t> OVERWORLD_SHIFT = {0, 0}; const SDLPP::Vec2D<uint64_t> OVERWORLD_SHIFT = { 0, 0 };
const SDLPP::Vec2D<uint64_t> UNDERWORLD_SHIFT = {274, 0}; const SDLPP::Vec2D<uint64_t> UNDERWORLD_SHIFT = { 274, 0 };
const SDLPP::Vec2D<uint64_t> WATER_SHIFT = {548, 0}; const SDLPP::Vec2D<uint64_t> WATER_SHIFT = { 548, 0 };
const SDLPP::Vec2D<uint64_t> BOWSER_SHIFT = {0, 173}; const SDLPP::Vec2D<uint64_t> BOWSER_SHIFT = { 0, 173 };
const std::vector< SDL_Rect > GOOMBA_WALK_ANIM = { { 1, 28, 16, 16 }, const std::vector<SDL_Rect> GOOMBA_WALK_ANIM = { { 1, 28, 16, 16 },
{ 18, 28, 16, 16 } }; { 18, 28, 16, 16 } };
const SDL_Rect GOOMBA_DEATH_SRC = {39, 28, 16, 16}; const SDL_Rect GOOMBA_DEATH_SRC = { 39, 28, 16, 16 };

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);
@ -11,14 +15,14 @@ ToolBox::ToolBox(int x, int y, double start_x, double start_y, std::shared_ptr<S
setColor("#FFFFFF88"); setColor("#FFFFFF88");
setPermanent(); setPermanent();
setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER); setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
if(coliders) if (coliders)
addCollision(SDLPP::RectColider(0,0,1,1)); addCollision(SDLPP::RectColider(0, 0, 1, 1));
} }
SDLPP::Vec2D<int> ToolBox::getIndexes() const { SDLPP::Vec2D<int> ToolBox::getIndexes() const {
return {_x, _y}; return { _x, _y };
} }
void ToolBox::visit( SDLPP::Visitor &visitor ) { void ToolBox::visit(SDLPP::Visitor &visitor) {
visitor.visit( *this ); visitor.visit(*this);
} }

View File

@ -5,15 +5,17 @@
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 {
return _type; return _type;
} }
void setType(uint64_t type) { void setType(uint64_t type) {
_type = type; _type = type;
} }
private: private:
int _x; int _x;
int _y; int _y;