This commit is contained in:
parent
f3062464d2
commit
8ca70fa11e
497
mario/blocks.cpp
497
mario/blocks.cpp
@ -17,88 +17,91 @@
|
||||
#define CAN_BE_DESTROYED_FLAG 0x0000000000000001
|
||||
#define HAS_COLLISION 0x0000000000000002
|
||||
|
||||
MarioBlock::MarioBlock( int x, int y,
|
||||
const std::shared_ptr< SDLPP::Renderer > &renderer,
|
||||
std::shared_ptr< SDLPP::Texture > texture, SDL_Rect src,
|
||||
bool can_be_destroyed, bool destructible )
|
||||
: RectangleRender( x * BLOCK_SIZE, 1 - ( 16 - y ) * BLOCK_SIZE,
|
||||
BLOCK_SIZE, BLOCK_SIZE, renderer, texture, src ) {
|
||||
MarioBlock::MarioBlock(int x, int y,
|
||||
const std::shared_ptr<SDLPP::Renderer> &renderer,
|
||||
std::shared_ptr<SDLPP::Texture> texture, SDL_Rect src,
|
||||
bool can_be_destroyed, bool destructible)
|
||||
: RectangleRender(x * BLOCK_SIZE, 1 - (16 - y) * BLOCK_SIZE, BLOCK_SIZE,
|
||||
BLOCK_SIZE, renderer, texture, src) {
|
||||
_can_be_destroyed = can_be_destroyed;
|
||||
_destructible = can_be_destroyed && destructible;
|
||||
setMovementSpeed( 1 );
|
||||
setMovementSpeed(1);
|
||||
_coins = 0;
|
||||
_mushroom = false;
|
||||
_base_src = src;
|
||||
}
|
||||
void MarioBlock::visit( SDLPP::Visitor &visitor ) {
|
||||
void MarioBlock::visit(SDLPP::Visitor &visitor) {
|
||||
#ifdef EDITOR
|
||||
if ( !_tool && _terrain &&
|
||||
visitor.getVisitorType() == VisitorType::Terrain ) {
|
||||
if (!_tool && _terrain &&
|
||||
visitor.getVisitorType() == VisitorType::Terrain) {
|
||||
destroy();
|
||||
}
|
||||
if ( !_tool && !_terrain &&
|
||||
(visitor.getVisitorType() == VisitorType::Modifier ||
|
||||
visitor.getVisitorType() == VisitorType::Character)) {
|
||||
if (!_tool && !_terrain &&
|
||||
(visitor.getVisitorType() == VisitorType::Modifier ||
|
||||
visitor.getVisitorType() == VisitorType::Character)) {
|
||||
destroy();
|
||||
}
|
||||
#else
|
||||
if ( visitor.getFromId() == MARIO_TOP_DETECT &&
|
||||
dynamic_cast< MarioVisitor & >( visitor ).canDestroy() ) {
|
||||
if (visitor.getFromId() == MARIO_TOP_DETECT &&
|
||||
dynamic_cast<MarioVisitor &>(visitor).canDestroy()) {
|
||||
// TODO if big mario and _can_be_destroyed
|
||||
if ( _destructible && !hasCoin() ) {
|
||||
if (_destructible && !hasCoin()) {
|
||||
destroy();
|
||||
} else {
|
||||
BounceVisitor bv;
|
||||
bv.setVisitorType( VisitorType::Terrain );
|
||||
bv.setVisitorType(VisitorType::Terrain);
|
||||
|
||||
setPos( getPos() - SDLPP::Vec2D< double >( 0, BLOCK_SIZE ) );
|
||||
if ( getCollisions().size() < 2 )
|
||||
addCollision( SDLPP::RectColider( 0.1, 0.1, 0.8, 0.8, BOUNCE_COLLISION ) );
|
||||
setPos(getPos() - SDLPP::Vec2D<double>(0, BLOCK_SIZE));
|
||||
if (getCollisions().size() < 2)
|
||||
addCollision(
|
||||
SDLPP::RectColider(0.1, 0.1, 0.8, 0.8, BOUNCE_COLLISION));
|
||||
updateSizeAndPosition();
|
||||
g_playground->visitCollisions( *this, bv );
|
||||
setPos( getPos() + SDLPP::Vec2D< double >( 0, BLOCK_SIZE ) );
|
||||
g_playground->visitCollisions(*this, bv);
|
||||
setPos(getPos() + SDLPP::Vec2D<double>(0, BLOCK_SIZE));
|
||||
updateSizeAndPosition();
|
||||
if ( bv.canBounce() )
|
||||
if (bv.canBounce())
|
||||
bounce();
|
||||
}
|
||||
if ( hasCoin() ) {
|
||||
if (hasCoin()) {
|
||||
removeCoin();
|
||||
auto coin = createTerrainBlock(COIN_ID, LandType::OVERWORLD, renderer);
|
||||
auto coin =
|
||||
createTerrainBlock(COIN_ID, LandType::OVERWORLD, renderer);
|
||||
coin->setPos(getPos());
|
||||
std::dynamic_pointer_cast<CoinBlock>(coin)->setParent(this);
|
||||
dynamic_cast< MarioVisitor & >( visitor ).setCoin();
|
||||
dynamic_cast< MarioVisitor & >( visitor ).setCoinBlock(coin);
|
||||
dynamic_cast<MarioVisitor &>(visitor).setCoin();
|
||||
dynamic_cast<MarioVisitor &>(visitor).setCoinBlock(coin);
|
||||
}
|
||||
if ( hasMushroom() ) {
|
||||
if (hasMushroom()) {
|
||||
removeMushroom();
|
||||
auto mushroom = createTerrainBlock(MUSHROOM_ID, LandType::OVERWORLD, renderer);
|
||||
auto mushroom =
|
||||
createTerrainBlock(MUSHROOM_ID, LandType::OVERWORLD, renderer);
|
||||
mushroom->setPos(getPos());
|
||||
std::dynamic_pointer_cast<MushroomBlock>(mushroom)->setParent(this);
|
||||
dynamic_cast< MarioVisitor & >( visitor ).setMushroomBlock(mushroom);
|
||||
dynamic_cast<MarioVisitor &>(visitor).setMushroomBlock(mushroom);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
visitor.visit( *this );
|
||||
visitor.visit(*this);
|
||||
}
|
||||
void MarioBlock::setTool( bool tool ) {
|
||||
void MarioBlock::setTool(bool tool) {
|
||||
_tool = tool;
|
||||
}
|
||||
void MarioBlock::setTerrain( bool terrain ) {
|
||||
void MarioBlock::setTerrain(bool terrain) {
|
||||
_terrain = terrain;
|
||||
}
|
||||
|
||||
void MarioBlock::bounce() {
|
||||
if ( _bouncing ) {
|
||||
if (_bouncing) {
|
||||
return;
|
||||
}
|
||||
_bouncing = true;
|
||||
og_pos = getPos();
|
||||
ticks_to_bounce = bounce_ticks;
|
||||
setMovement( 0, -bounce_speed );
|
||||
setMovement(0, -bounce_speed);
|
||||
}
|
||||
|
||||
void MarioBlock::travelToPos(const SDLPP::Vec2D<double> &target) {
|
||||
if(_traveling) {
|
||||
if (_traveling) {
|
||||
return;
|
||||
}
|
||||
_traveling = true;
|
||||
@ -106,11 +109,11 @@ void MarioBlock::travelToPos(const SDLPP::Vec2D<double> &target) {
|
||||
|
||||
auto movement = (_target - getPos());
|
||||
auto abs_mov_x = movement.getX();
|
||||
if(abs_mov_x < 0) {
|
||||
if (abs_mov_x < 0) {
|
||||
abs_mov_x *= -1;
|
||||
}
|
||||
auto abs_mov_y = movement.getY();
|
||||
if(abs_mov_y < 0) {
|
||||
if (abs_mov_y < 0) {
|
||||
abs_mov_y *= -1;
|
||||
}
|
||||
|
||||
@ -120,11 +123,11 @@ void MarioBlock::travelToPos(const SDLPP::Vec2D<double> &target) {
|
||||
}
|
||||
|
||||
void MarioBlock::gravity(int ticks) {
|
||||
if(_on_ground) {
|
||||
if (_on_ground) {
|
||||
return;
|
||||
}
|
||||
_ticks_till_gravity -= ticks;
|
||||
if(_ticks_till_gravity < 0) {
|
||||
if (_ticks_till_gravity < 0) {
|
||||
addMovement(0, _gravity_acceleration);
|
||||
_ticks_till_gravity = _base_gravity_ticks;
|
||||
}
|
||||
@ -138,51 +141,49 @@ bool MarioBlock::isTraveling() const {
|
||||
return _traveling;
|
||||
}
|
||||
|
||||
void MarioBlock::custom_move( int ticks ) {
|
||||
if ( !_bouncing && !_traveling ) {
|
||||
void MarioBlock::custom_move(int ticks) {
|
||||
if (!_bouncing && !_traveling) {
|
||||
return;
|
||||
}
|
||||
if( _bouncing ) {
|
||||
if ( getMovement().getY() < 0 ) {
|
||||
if (_bouncing) {
|
||||
if (getMovement().getY() < 0) {
|
||||
ticks_to_bounce -= ticks;
|
||||
if ( ticks_to_bounce < 0 ) {
|
||||
setMovement( 0, bounce_speed );
|
||||
if (ticks_to_bounce < 0) {
|
||||
setMovement(0, bounce_speed);
|
||||
ticks_to_bounce = bounce_ticks;
|
||||
}
|
||||
} else {
|
||||
if ( getPos().getY() >= og_pos.getY() ) {
|
||||
setMovement( 0, 0 );
|
||||
setPos( getPos().getX(), og_pos.getY() );
|
||||
if (getPos().getY() >= og_pos.getY()) {
|
||||
setMovement(0, 0);
|
||||
setPos(getPos().getX(), og_pos.getY());
|
||||
_bouncing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(_traveling) {
|
||||
bool overshot_x = (getMovement().getX() < 0 &&
|
||||
getPos().getX() <= _target.getX()) ||
|
||||
(getMovement().getX() > 0 &&
|
||||
getPos().getX() >= _target.getX());
|
||||
bool overshot_y = (getMovement().getY() < 0 &&
|
||||
getPos().getY() <= _target.getY()) ||
|
||||
(getMovement().getY() > 0 &&
|
||||
getPos().getY() >= _target.getY());
|
||||
if(overshot_x) {
|
||||
if (_traveling) {
|
||||
bool overshot_x =
|
||||
(getMovement().getX() < 0 && getPos().getX() <= _target.getX()) ||
|
||||
(getMovement().getX() > 0 && getPos().getX() >= _target.getX());
|
||||
bool overshot_y =
|
||||
(getMovement().getY() < 0 && getPos().getY() <= _target.getY()) ||
|
||||
(getMovement().getY() > 0 && getPos().getY() >= _target.getY());
|
||||
if (overshot_x) {
|
||||
setPos(_target.getX(), getPos().getY());
|
||||
setMovement(0, getMovement().getY());
|
||||
}
|
||||
if(overshot_y) {
|
||||
if (overshot_y) {
|
||||
setPos(getPos().getX(), _target.getY());
|
||||
setMovement(getMovement().getX(), 0);
|
||||
}
|
||||
if(getMovement() == SDLPP::Vec2D<double>(0,0)) {
|
||||
if (getMovement() == SDLPP::Vec2D<double>(0, 0)) {
|
||||
_traveling = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MarioBlock::setType( LandType::Value type ) {
|
||||
void MarioBlock::setType(LandType::Value type) {
|
||||
_type = type;
|
||||
setWorldTypeSrc( _type );
|
||||
setWorldTypeSrc(_type);
|
||||
}
|
||||
LandType::Value MarioBlock::getType() const {
|
||||
return _type;
|
||||
@ -203,20 +204,20 @@ void MarioBlock::removeMushroom() {
|
||||
void MarioBlock::addMushroom() {
|
||||
_mushroom = true;
|
||||
}
|
||||
void MarioBlock::setCoinCount( int coins ) {
|
||||
void MarioBlock::setCoinCount(int coins) {
|
||||
_coins = coins;
|
||||
}
|
||||
void MarioBlock::setDestructible( bool destructible ) {
|
||||
void MarioBlock::setDestructible(bool destructible) {
|
||||
_destructible = destructible;
|
||||
}
|
||||
void MarioBlock::ensureCollision() {
|
||||
if ( getCollisions().size() == 0 ) {
|
||||
addCollision( SDLPP::RectColider( 0, 0, 1, 1 ) );
|
||||
if (getCollisions().size() == 0) {
|
||||
addCollision(SDLPP::RectColider(0, 0, 1, 1));
|
||||
}
|
||||
}
|
||||
void MarioBlock::setWorldTypeSrc( LandType::Value world ) {
|
||||
void MarioBlock::setWorldTypeSrc(LandType::Value world) {
|
||||
auto rect = _base_src;
|
||||
switch ( world ) {
|
||||
switch (world) {
|
||||
case LandType::OVERWORLD:
|
||||
rect.x += OVERWORLD_SHIFT.getX();
|
||||
rect.y += OVERWORLD_SHIFT.getY();
|
||||
@ -234,10 +235,10 @@ void MarioBlock::setWorldTypeSrc( LandType::Value world ) {
|
||||
rect.y += BOWSER_SHIFT.getY();
|
||||
break;
|
||||
}
|
||||
setTextureSourceRect( rect );
|
||||
setTextureSourceRect(rect);
|
||||
}
|
||||
|
||||
const std::vector< uint64_t > possibleBlocks = {
|
||||
const std::vector<uint64_t> possibleBlocks = {
|
||||
FLOOR_ID,
|
||||
STEP_ID,
|
||||
HILL_TOP_ID,
|
||||
@ -298,362 +299,354 @@ const std::vector< uint64_t > possibleBlocks = {
|
||||
CANNON_ID,
|
||||
};
|
||||
|
||||
const std::vector< uint64_t > possibleMods = {
|
||||
const std::vector<uint64_t> possibleMods = {
|
||||
DESTRUCTIBLE_MODIFIER_ID,
|
||||
BACKGROUND_MODIFIER_ID,
|
||||
COIN_MODIFIER_ID,
|
||||
MUSHROOM_MODIFIER_ID,
|
||||
};
|
||||
|
||||
const std::vector< uint64_t > possibleCharacters = {
|
||||
const std::vector<uint64_t> possibleCharacters = {
|
||||
MARIO_ID,
|
||||
GOOMBA_ID,
|
||||
};
|
||||
|
||||
const std::vector< LandType::Value > possibleLands = {
|
||||
const std::vector<LandType::Value> possibleLands = {
|
||||
LandType::OVERWORLD, LandType::UNDERWORLD, LandType::WATER, LandType::BOWSER
|
||||
};
|
||||
|
||||
std::shared_ptr< MarioBlock >
|
||||
createBlockById( uint64_t id, int x, int y,
|
||||
std::shared_ptr< SDLPP::Renderer > &renderer ) {
|
||||
std::shared_ptr< MarioBlock > result = nullptr;
|
||||
switch ( id ) {
|
||||
std::shared_ptr<MarioBlock>
|
||||
createBlockById(uint64_t id, int x, int y,
|
||||
std::shared_ptr<SDLPP::Renderer> &renderer) {
|
||||
std::shared_ptr<MarioBlock> result = nullptr;
|
||||
switch (id) {
|
||||
case FLOOR_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< FloorBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<FloorBlock>(x, y, renderer));
|
||||
break;
|
||||
case HILL_INCLINE_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< HillInclineBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<HillInclineBlock>(x, y, renderer));
|
||||
break;
|
||||
case HILL_DECLINE_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< HillDeclineBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<HillDeclineBlock>(x, y, renderer));
|
||||
break;
|
||||
case HILL_DOTS_RIGHT_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< HillDotsRightBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<HillDotsRightBlock>(x, y, renderer));
|
||||
break;
|
||||
case HILL_DOTS_LEFT_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< HillDotsLeftBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<HillDotsLeftBlock>(x, y, renderer));
|
||||
break;
|
||||
case HILL_FILL_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< HillFillBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<HillFillBlock>(x, y, renderer));
|
||||
break;
|
||||
case HILL_TOP_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< HillTopBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<HillTopBlock>(x, y, renderer));
|
||||
break;
|
||||
case BUSH_LEFT_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< BushLeftBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<BushLeftBlock>(x, y, renderer));
|
||||
break;
|
||||
case BUSH_MIDDLE_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< BushMiddleBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<BushMiddleBlock>(x, y, renderer));
|
||||
break;
|
||||
case BUSH_RIGHT_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< BushRightBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<BushRightBlock>(x, y, renderer));
|
||||
break;
|
||||
case CLOUD_LEFT_BOTTOM_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< CloudLeftBottomBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<CloudLeftBottomBlock>(x, y, renderer));
|
||||
break;
|
||||
case CLOUD_MIDDLE_BOTTOM_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< CloudMiddleBottomBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<CloudMiddleBottomBlock>(x, y, renderer));
|
||||
break;
|
||||
case CLOUD_RIGHT_BOTTOM_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< CloudRightBottomBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<CloudRightBottomBlock>(x, y, renderer));
|
||||
break;
|
||||
case CLOUD_LEFT_TOP_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< CloudLeftTopBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<CloudLeftTopBlock>(x, y, renderer));
|
||||
break;
|
||||
case CLOUD_MIDDLE_TOP_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< CloudMiddleTopBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<CloudMiddleTopBlock>(x, y, renderer));
|
||||
break;
|
||||
case CLOUD_RIGHT_TOP_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< CloudRightTopBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<CloudRightTopBlock>(x, y, renderer));
|
||||
break;
|
||||
case PIPE_LEFT_BOTTOM_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< PipeLeftBottomBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<PipeLeftBottomBlock>(x, y, renderer));
|
||||
break;
|
||||
case PIPE_RIGHT_BOTTOM_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< PipeRightBottomBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<PipeRightBottomBlock>(x, y, renderer));
|
||||
break;
|
||||
case PIPE_LEFT_TOP_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< PipeLeftTopBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<PipeLeftTopBlock>(x, y, renderer));
|
||||
break;
|
||||
case PIPE_RIGHT_TOP_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< PipeRightTopBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<PipeRightTopBlock>(x, y, renderer));
|
||||
break;
|
||||
case CASTLE_LEFT_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< CastleLeftBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<CastleLeftBlock>(x, y, renderer));
|
||||
break;
|
||||
case CASTLE_RIGHT_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< CastleRightBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<CastleRightBlock>(x, y, renderer));
|
||||
break;
|
||||
case CASTLE_BLACK_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< CastleBlackBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<CastleBlackBlock>(x, y, renderer));
|
||||
break;
|
||||
case CASTLE_ENTRY_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< CastleEntryBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<CastleEntryBlock>(x, y, renderer));
|
||||
break;
|
||||
case CASTLE_TOWER_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< CastleTowerBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<CastleTowerBlock>(x, y, renderer));
|
||||
break;
|
||||
case CASTLE_TOWER_FILLED_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< CastleTowerFilledBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<CastleTowerFilledBlock>(x, y, renderer));
|
||||
break;
|
||||
case VINE_TOP_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< VineTopBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<VineTopBlock>(x, y, renderer));
|
||||
break;
|
||||
case VINE_BOTTOM_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< VineBottomBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<VineBottomBlock>(x, y, renderer));
|
||||
break;
|
||||
case POLE_TOP_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< PoleTopBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<PoleTopBlock>(x, y, renderer));
|
||||
break;
|
||||
case POLE_BOTTOM_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< PoleBottomBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<PoleBottomBlock>(x, y, renderer));
|
||||
break;
|
||||
case FLAG_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< FlagBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<FlagBlock>(x, y, renderer));
|
||||
break;
|
||||
case STEP_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< StepBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<StepBlock>(x, y, renderer));
|
||||
break;
|
||||
case BRICK_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< BrickBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<BrickBlock>(x, y, renderer));
|
||||
break;
|
||||
case BRICK_TOP_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< BrickTopBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<BrickTopBlock>(x, y, renderer));
|
||||
break;
|
||||
case SIDEWAY_PIPE_END_TOP_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< SidewayPipeEndTopBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<SidewayPipeEndTopBlock>(x, y, renderer));
|
||||
break;
|
||||
case SIDEWAY_PIPE_END_BOTTOM_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< SidewayPipeEndBottomBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<SidewayPipeEndBottomBlock>(x, y, renderer));
|
||||
break;
|
||||
case SIDEWAY_PIPE_MIDDLE_TOP_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< SidewayPipeMiddleTopBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<SidewayPipeMiddleTopBlock>(x, y, renderer));
|
||||
break;
|
||||
case SIDEWAY_PIPE_MIDDLE_BOTTOM_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< SidewayPipeMiddleBottomBlock >( x, y,
|
||||
renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<SidewayPipeMiddleBottomBlock>(x, y, renderer));
|
||||
break;
|
||||
case SIDEWAY_PIPE_CONNECTOR_TOP_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< SidewayPipeConnectorTopBlock >( x, y,
|
||||
renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<SidewayPipeConnectorTopBlock>(x, y, renderer));
|
||||
break;
|
||||
case SIDEWAY_PIPE_CONNECTOR_BOTTOM_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< SidewayPipeConnectorBottomBlock >( x, y,
|
||||
renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<SidewayPipeConnectorBottomBlock>(x, y, renderer));
|
||||
break;
|
||||
case TREE_PLATFORM_TOP_LEFT_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< TreePlatformTopLeftBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<TreePlatformTopLeftBlock>(x, y, renderer));
|
||||
break;
|
||||
case TREE_PLATFORM_TOP_MIDDLE_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< TreePlatformTopMiddleBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<TreePlatformTopMiddleBlock>(x, y, renderer));
|
||||
break;
|
||||
case TREE_PLATFORM_TOP_RIGHT_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< TreePlatformTopRightBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<TreePlatformTopRightBlock>(x, y, renderer));
|
||||
break;
|
||||
case TREE_PLATFORM_BARK_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< TreePlatformBarkBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<TreePlatformBarkBlock>(x, y, renderer));
|
||||
break;
|
||||
case WATER_TOP_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< WaterTopBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<WaterTopBlock>(x, y, renderer));
|
||||
break;
|
||||
case WATER_FILL_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< WaterFillBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<WaterFillBlock>(x, y, renderer));
|
||||
break;
|
||||
case MUSHROOM_PLATFORM_TOP_LEFT_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< MushroomPlatformTopLeftBlock >( x, y,
|
||||
renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<MushroomPlatformTopLeftBlock>(x, y, renderer));
|
||||
break;
|
||||
case MUSHROOM_PLATFORM_TOP_MIDDLE_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< MushroomPlatformTopMiddleBlock >( x, y,
|
||||
renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<MushroomPlatformTopMiddleBlock>(x, y, renderer));
|
||||
break;
|
||||
case MUSHROOM_PLATFORM_TOP_RIGHT_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< MushroomPlatformTopRightBlock >( x, y,
|
||||
renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<MushroomPlatformTopRightBlock>(x, y, renderer));
|
||||
break;
|
||||
case MUSHROOM_PLATFORM_BARK_TOP_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< MushroomPlatformBarkTopBlock >( x, y,
|
||||
renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<MushroomPlatformBarkTopBlock>(x, y, renderer));
|
||||
break;
|
||||
case MUSHROOM_PLATFORM_BARK_BOTTOM_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< MushroomPlatformBarkBottomBlock >( x, y,
|
||||
renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<MushroomPlatformBarkBottomBlock>(x, y, renderer));
|
||||
break;
|
||||
case TREE_BARK_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< TreeBarkBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<TreeBarkBlock>(x, y, renderer));
|
||||
break;
|
||||
case TREE_LEAVES_SMALL_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< TreeLeavesSmallBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<TreeLeavesSmallBlock>(x, y, renderer));
|
||||
break;
|
||||
case TREE_LEAVES_TOP_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< TreeLeavesTopBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<TreeLeavesTopBlock>(x, y, renderer));
|
||||
break;
|
||||
case TREE_LEAVES_BOTTOM_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< TreeLeavesBottomBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<TreeLeavesBottomBlock>(x, y, renderer));
|
||||
break;
|
||||
case CANNON_TOWER_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< CannonTowerBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<CannonTowerBlock>(x, y, renderer));
|
||||
break;
|
||||
case CANNON_PEDESTAL_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< CannonPedestalBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<CannonPedestalBlock>(x, y, renderer));
|
||||
break;
|
||||
case CANNON_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< CannonBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<CannonBlock>(x, y, renderer));
|
||||
break;
|
||||
case MARIO_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< Mario >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<Mario>(x, y, renderer));
|
||||
break;
|
||||
case GOOMBA_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< GoombaBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<GoombaBlock>(x, y, renderer));
|
||||
break;
|
||||
case DESTRUCTIBLE_MODIFIER_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< DestructibleModifierBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<DestructibleModifierBlock>(x, y, renderer));
|
||||
break;
|
||||
case BACKGROUND_MODIFIER_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< BackgroundModifierBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<BackgroundModifierBlock>(x, y, renderer));
|
||||
break;
|
||||
#ifdef EDITOR
|
||||
case COIN_MODIFIER_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< CoinEditorBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<CoinEditorBlock>(x, y, renderer));
|
||||
break;
|
||||
#endif
|
||||
case MUSHROOM_MODIFIER_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< MushroomModifierBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<MushroomModifierBlock>(x, y, renderer));
|
||||
break;
|
||||
#ifndef EDITOR
|
||||
case COIN_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< CoinBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<CoinBlock>(x, y, renderer));
|
||||
break;
|
||||
case MUSHROOM_ID:
|
||||
result = std::static_pointer_cast< MarioBlock >(
|
||||
std::make_shared< MushroomBlock >( x, y, renderer ) );
|
||||
result = std::static_pointer_cast<MarioBlock>(
|
||||
std::make_shared<MushroomBlock>(x, y, renderer));
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::shared_ptr< MarioBlock >
|
||||
createBlock( std::shared_ptr< SDLPP::Renderer > &renderer, int x, int y,
|
||||
uint64_t id, LandType::Value land_type, bool destructible,
|
||||
bool editor ) {
|
||||
auto block = createBlockById( id, x, y, renderer );
|
||||
if ( block == nullptr ) {
|
||||
std::shared_ptr<MarioBlock>
|
||||
createBlock(std::shared_ptr<SDLPP::Renderer> &renderer, int x, int y,
|
||||
uint64_t id, LandType::Value land_type, bool destructible,
|
||||
bool editor) {
|
||||
auto block = createBlockById(id, x, y, renderer);
|
||||
if (block == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
block->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||
block->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
|
||||
block->setStatic();
|
||||
block->setType( land_type );
|
||||
if ( destructible ) {
|
||||
block->setType(land_type);
|
||||
if (destructible) {
|
||||
block->setDestructible();
|
||||
}
|
||||
if ( editor ) {
|
||||
if (editor) {
|
||||
block->ensureCollision();
|
||||
}
|
||||
return block;
|
||||
}
|
||||
|
||||
// TODO coin count
|
||||
std::shared_ptr< MarioBlock >
|
||||
createTerrainBlock( uint64_t block_id, LandType::Value type,
|
||||
std::shared_ptr< SDLPP::Renderer > &renderer, int x, int y,
|
||||
bool destructible, bool editor ) {
|
||||
return createBlock( renderer, x, y, block_id, type, destructible, editor );
|
||||
std::shared_ptr<MarioBlock>
|
||||
createTerrainBlock(uint64_t block_id, LandType::Value type,
|
||||
std::shared_ptr<SDLPP::Renderer> &renderer, int x, int y,
|
||||
bool destructible, bool editor) {
|
||||
return createBlock(renderer, x, y, block_id, type, destructible, editor);
|
||||
}
|
||||
|
||||
std::shared_ptr< MarioBlock >
|
||||
createTerrainBlock( uint64_t block_id, LandType::Value type,
|
||||
std::shared_ptr< SDLPP::Renderer > &renderer,
|
||||
bool destructible, bool editor ) {
|
||||
return createTerrainBlock( block_id, type, renderer, 0, 0, destructible,
|
||||
editor );
|
||||
std::shared_ptr<MarioBlock>
|
||||
createTerrainBlock(uint64_t block_id, LandType::Value type,
|
||||
std::shared_ptr<SDLPP::Renderer> &renderer,
|
||||
bool destructible, bool editor) {
|
||||
return createTerrainBlock(block_id, type, renderer, 0, 0, destructible,
|
||||
editor);
|
||||
}
|
||||
|
||||
std::shared_ptr< MarioBlock >
|
||||
createMario( LandType::Value type, std::shared_ptr< SDLPP::Renderer > &renderer,
|
||||
int x, int y, bool editor ) {
|
||||
std::shared_ptr<MarioBlock>
|
||||
createMario(LandType::Value type, std::shared_ptr<SDLPP::Renderer> &renderer,
|
||||
int x, int y, bool editor) {
|
||||
// TODO add type additions
|
||||
auto mario = createBlock( renderer, x, y, MARIO_ID, type, false, true );
|
||||
if ( editor ) {
|
||||
mario->setTerrain( false );
|
||||
auto mario = createBlock(renderer, x, y, MARIO_ID, type, false, true);
|
||||
if (editor) {
|
||||
mario->setTerrain(false);
|
||||
mario->removeCollisions();
|
||||
mario->ensureCollision();
|
||||
}
|
||||
return mario;
|
||||
}
|
||||
|
||||
enum BlockRole::Value getBlockRole( uint64_t id ) {
|
||||
if ( id >= 0x7000 )
|
||||
enum BlockRole::Value getBlockRole(uint64_t id) {
|
||||
if (id >= 0x7000)
|
||||
return BlockRole::TERRAIN;
|
||||
if ( id == MARIO_ID )
|
||||
if (id == MARIO_ID)
|
||||
return BlockRole::MARIO;
|
||||
if ( id < MARIO_ID )
|
||||
if (id < MARIO_ID)
|
||||
return BlockRole::CHARACTER;
|
||||
return BlockRole::MODIFIER;
|
||||
}
|
||||
@ -662,12 +655,14 @@ void MarioBlock::setBaseRect(SDL_Rect rect) {
|
||||
_base_src = rect;
|
||||
setType(getType());
|
||||
}
|
||||
|
||||
void MarioBlock::checkVisibility(double rightmost_x) {
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
bool MarioBlock::wasVisible() const {
|
||||
return _was_visible;
|
||||
}
|
||||
|
@ -11,24 +11,23 @@ struct LandType {
|
||||
|
||||
class MarioBlock : public SDLPP::RectangleRender {
|
||||
public:
|
||||
MarioBlock( int x, int y,
|
||||
const std::shared_ptr< SDLPP::Renderer > &renderer,
|
||||
std::shared_ptr< SDLPP::Texture > texture, SDL_Rect src,
|
||||
bool can_be_destroyed = false, bool destructible = false );
|
||||
void visit( SDLPP::Visitor &visitor ) override;
|
||||
void setTool( bool tool = true );
|
||||
void setTerrain( bool terrain = true );
|
||||
MarioBlock(int x, int y, const std::shared_ptr<SDLPP::Renderer> &renderer,
|
||||
std::shared_ptr<SDLPP::Texture> texture, SDL_Rect src,
|
||||
bool can_be_destroyed = false, bool destructible = false);
|
||||
void visit(SDLPP::Visitor &visitor) override;
|
||||
void setTool(bool tool = true);
|
||||
void setTerrain(bool terrain = true);
|
||||
void bounce();
|
||||
void travelToPos(const SDLPP::Vec2D<double> &target);
|
||||
void custom_move( int ticks ) override;
|
||||
void setType( LandType::Value type );
|
||||
void custom_move(int ticks) override;
|
||||
void setType(LandType::Value type);
|
||||
LandType::Value getType() const;
|
||||
virtual void onScrollUp() {}
|
||||
virtual void onScrollDown() {}
|
||||
virtual uint8_t getData() const {
|
||||
return 0;
|
||||
}
|
||||
virtual void setData( uint8_t /*UNUSED*/ ) {}
|
||||
virtual void setData(uint8_t /*UNUSED*/) {}
|
||||
// handle own visitor
|
||||
virtual void handleVisitor(SDLPP::Visitor &visitor) {}
|
||||
bool hasCoin();
|
||||
@ -36,8 +35,8 @@ public:
|
||||
void removeCoin();
|
||||
void removeMushroom();
|
||||
void addMushroom();
|
||||
void setCoinCount( int coins );
|
||||
void setDestructible( bool destructible = true );
|
||||
void setCoinCount(int coins);
|
||||
void setDestructible(bool destructible = true);
|
||||
void ensureCollision();
|
||||
bool isBouncing() const;
|
||||
bool isTraveling() const;
|
||||
@ -52,7 +51,7 @@ protected:
|
||||
void gravity(int ticks);
|
||||
void setOnGround(bool on_ground = true) {
|
||||
_on_ground = on_ground;
|
||||
if(on_ground) {
|
||||
if (on_ground) {
|
||||
setMovement(getMovement().getX(), 0);
|
||||
}
|
||||
}
|
||||
@ -63,7 +62,7 @@ protected:
|
||||
_base_gravity_ticks = ticks;
|
||||
}
|
||||
|
||||
virtual void setWorldTypeSrc( LandType::Value world );
|
||||
virtual void setWorldTypeSrc(LandType::Value world);
|
||||
|
||||
private:
|
||||
bool _tool = false;
|
||||
@ -76,22 +75,22 @@ private:
|
||||
bool _mushroom = false;
|
||||
bool _release_coin = false;
|
||||
int ticks_to_bounce = 0;
|
||||
SDLPP::Vec2D< double > og_pos = {};
|
||||
SDLPP::Vec2D<double> og_pos = {};
|
||||
LandType::Value _type;
|
||||
SDL_Rect _base_src;
|
||||
SDLPP::Vec2D<double> _target = {0,0};
|
||||
SDLPP::Vec2D<double> _target = { 0, 0 };
|
||||
|
||||
bool _on_ground = true;
|
||||
int _base_gravity_ticks = 1000 / 60;
|
||||
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;
|
||||
};
|
||||
|
||||
extern const std::vector< uint64_t > possibleBlocks;
|
||||
extern const std::vector< uint64_t > possibleMods;
|
||||
extern const std::vector< uint64_t > possibleCharacters;
|
||||
extern const std::vector< LandType::Value > possibleLands;
|
||||
extern const std::vector<uint64_t> possibleBlocks;
|
||||
extern const std::vector<uint64_t> possibleMods;
|
||||
extern const std::vector<uint64_t> possibleCharacters;
|
||||
extern const std::vector<LandType::Value> possibleLands;
|
||||
|
||||
struct BlockRole {
|
||||
enum Value {
|
||||
@ -102,18 +101,18 @@ struct BlockRole {
|
||||
};
|
||||
};
|
||||
|
||||
std::shared_ptr< MarioBlock >
|
||||
createTerrainBlock( uint64_t block_id, LandType::Value type,
|
||||
std::shared_ptr< SDLPP::Renderer > &renderer,
|
||||
bool destructible = false, bool editor = false );
|
||||
std::shared_ptr< MarioBlock >
|
||||
createTerrainBlock( uint64_t block_id, LandType::Value type,
|
||||
std::shared_ptr< SDLPP::Renderer > &renderer, int x, int y,
|
||||
bool destructible = false, bool editor = false );
|
||||
std::shared_ptr< MarioBlock >
|
||||
createMario( LandType::Value type, std::shared_ptr< SDLPP::Renderer > &renderer,
|
||||
int x, int y, bool editor = false );
|
||||
std::shared_ptr<MarioBlock>
|
||||
createTerrainBlock(uint64_t block_id, LandType::Value type,
|
||||
std::shared_ptr<SDLPP::Renderer> &renderer,
|
||||
bool destructible = false, bool editor = false);
|
||||
std::shared_ptr<MarioBlock>
|
||||
createTerrainBlock(uint64_t block_id, LandType::Value type,
|
||||
std::shared_ptr<SDLPP::Renderer> &renderer, int x, int y,
|
||||
bool destructible = false, bool editor = false);
|
||||
std::shared_ptr<MarioBlock>
|
||||
createMario(LandType::Value type, std::shared_ptr<SDLPP::Renderer> &renderer,
|
||||
int x, int y, bool editor = false);
|
||||
|
||||
enum BlockRole::Value getBlockRole( uint64_t id );
|
||||
enum BlockRole::Value getBlockRole(uint64_t id);
|
||||
|
||||
#endif
|
||||
|
@ -3,20 +3,24 @@
|
||||
#include "blocks.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;
|
||||
_y = y;
|
||||
setId(EDITOR_EDIT_SQUARE);
|
||||
setColiderColor("#FF00AA");
|
||||
setPermanent();
|
||||
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 {
|
||||
return {_x, _y};
|
||||
return { _x, _y };
|
||||
}
|
||||
|
||||
void EditBox::visit( SDLPP::Visitor &visitor ) {
|
||||
visitor.visit( *this );
|
||||
void EditBox::visit(SDLPP::Visitor &visitor) {
|
||||
visitor.visit(*this);
|
||||
}
|
||||
|
@ -5,9 +5,11 @@
|
||||
|
||||
class EditBox : public SDLPP::RectangleRender {
|
||||
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 void visit( SDLPP::Visitor &visitor ) override;
|
||||
virtual void visit(SDLPP::Visitor &visitor) override;
|
||||
|
||||
private:
|
||||
int _x;
|
||||
int _y;
|
||||
|
970
mario/editor.cpp
970
mario/editor.cpp
File diff suppressed because it is too large
Load Diff
@ -16,9 +16,9 @@
|
||||
#define SELECTED_RIGHT_CHARACTER 0x00000100
|
||||
#define SELECTED_LEFT_CHARACTER 0x00000200
|
||||
|
||||
void MouseVisitor::visit( const SDLPP::RenderObject &obj ) {
|
||||
void MouseVisitor::visit(const SDLPP::RenderObject &obj) {
|
||||
auto id = obj.getId();
|
||||
switch ( id ) {
|
||||
switch (id) {
|
||||
case EDITOR_LEFT_MAP_ID:
|
||||
select_flags |= SELECTED_LEFT_MAP;
|
||||
break;
|
||||
@ -45,72 +45,72 @@ void MouseVisitor::visit( const SDLPP::RenderObject &obj ) {
|
||||
break;
|
||||
case EDITOR_EDIT_SQUARE:
|
||||
edit_box = true;
|
||||
edit_box_location = dynamic_cast< const EditBox & >( obj ).getIndexes();
|
||||
edit_box_location = dynamic_cast<const EditBox &>(obj).getIndexes();
|
||||
break;
|
||||
case EDITOR_TOOL_ID:
|
||||
tool_box = true;
|
||||
tool_box_location = dynamic_cast< const ToolBox & >( obj ).getIndexes();
|
||||
tool_box_type = dynamic_cast< const ToolBox & >( obj ).getType();
|
||||
tool_box_location = dynamic_cast<const ToolBox &>(obj).getIndexes();
|
||||
tool_box_type = dynamic_cast<const ToolBox &>(obj).getType();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool MouseVisitor::moveMapLeft( uint64_t flags ) {
|
||||
bool MouseVisitor::moveMapLeft(uint64_t flags) {
|
||||
return flags & SELECTED_LEFT_MAP;
|
||||
}
|
||||
|
||||
bool MouseVisitor::moveMapRight( uint64_t flags ) {
|
||||
bool MouseVisitor::moveMapRight(uint64_t flags) {
|
||||
return flags & SELECTED_RIGHT_MAP;
|
||||
}
|
||||
|
||||
bool MouseVisitor::moveToolsLeft( uint64_t flags ) {
|
||||
bool MouseVisitor::moveToolsLeft(uint64_t flags) {
|
||||
return flags & SELECTED_LEFT_TOOL;
|
||||
}
|
||||
|
||||
bool MouseVisitor::moveToolsRight( uint64_t flags ) {
|
||||
bool MouseVisitor::moveToolsRight(uint64_t flags) {
|
||||
return flags & SELECTED_RIGHT_TOOL;
|
||||
}
|
||||
|
||||
bool MouseVisitor::moveModsLeft( uint64_t flags ) {
|
||||
bool MouseVisitor::moveModsLeft(uint64_t flags) {
|
||||
return flags & SELECTED_LEFT_MOD;
|
||||
}
|
||||
|
||||
bool MouseVisitor::moveModsRight( uint64_t flags ) {
|
||||
bool MouseVisitor::moveModsRight(uint64_t flags) {
|
||||
return flags & SELECTED_RIGHT_MOD;
|
||||
}
|
||||
|
||||
bool MouseVisitor::moveCharactersLeft( uint64_t flags ) {
|
||||
bool MouseVisitor::moveCharactersLeft(uint64_t flags) {
|
||||
return flags & SELECTED_LEFT_CHARACTER;
|
||||
}
|
||||
|
||||
bool MouseVisitor::moveCharactersRight( uint64_t flags ) {
|
||||
bool MouseVisitor::moveCharactersRight(uint64_t flags) {
|
||||
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();
|
||||
switch ( id ) {
|
||||
switch (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;
|
||||
if ( obj.getId() == source_id &&
|
||||
((m_obj.getType() == source_type &&
|
||||
getVisitorType() == VisitorType::Terrain) || ( m_obj.getData() == _data && getVisitorType() == VisitorType::Modifier))) {
|
||||
if (obj.getId() == source_id &&
|
||||
((m_obj.getType() == source_type &&
|
||||
getVisitorType() == VisitorType::Terrain) ||
|
||||
(m_obj.getData() == _data &&
|
||||
getVisitorType() == VisitorType::Modifier))) {
|
||||
add_block = false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
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;
|
||||
if ( obj.getId() == source_id &&
|
||||
m_obj.getType() == source_type &&
|
||||
getVisitorType() == VisitorType::Character ) {
|
||||
if (obj.getId() == source_id && m_obj.getType() == source_type &&
|
||||
getVisitorType() == VisitorType::Character) {
|
||||
add_block = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -17,8 +17,8 @@ struct VisitorType {
|
||||
class MouseVisitor : public SDLPP::Visitor {
|
||||
public:
|
||||
MouseVisitor() = default;
|
||||
void visit( const SDLPP::RenderObject &obj ) override;
|
||||
void setFromId( uint64_t /*UNUSED*/ ) override {}
|
||||
void visit(const SDLPP::RenderObject &obj) override;
|
||||
void setFromId(uint64_t /*UNUSED*/) override {}
|
||||
uint64_t getFromId() const override {
|
||||
return 0;
|
||||
}
|
||||
@ -28,16 +28,16 @@ public:
|
||||
bool foundEditBox() const {
|
||||
return edit_box;
|
||||
}
|
||||
const SDLPP::Vec2D< int > &getEditBoxIndexes() const {
|
||||
const SDLPP::Vec2D<int> &getEditBoxIndexes() const {
|
||||
return edit_box_location;
|
||||
}
|
||||
bool foundToolBox() const {
|
||||
return tool_box;
|
||||
}
|
||||
const SDLPP::Vec2D< int > &getToolBoxIndexes() const {
|
||||
const SDLPP::Vec2D<int> &getToolBoxIndexes() const {
|
||||
return tool_box_location;
|
||||
}
|
||||
void setVisitorType( uint64_t type ) override {
|
||||
void setVisitorType(uint64_t type) override {
|
||||
_type = type;
|
||||
}
|
||||
uint64_t getVisitorType() const override {
|
||||
@ -47,21 +47,21 @@ public:
|
||||
return tool_box_type;
|
||||
}
|
||||
|
||||
static bool moveMapLeft( uint64_t flags );
|
||||
static bool moveMapRight( uint64_t flags );
|
||||
static bool moveToolsLeft( uint64_t flags );
|
||||
static bool moveToolsRight( uint64_t flags );
|
||||
static bool moveModsLeft( uint64_t flags );
|
||||
static bool moveModsRight( uint64_t flags );
|
||||
static bool moveCharactersLeft( uint64_t flags );
|
||||
static bool moveCharactersRight( uint64_t flags );
|
||||
static bool moveMapLeft(uint64_t flags);
|
||||
static bool moveMapRight(uint64_t flags);
|
||||
static bool moveToolsLeft(uint64_t flags);
|
||||
static bool moveToolsRight(uint64_t flags);
|
||||
static bool moveModsLeft(uint64_t flags);
|
||||
static bool moveModsRight(uint64_t flags);
|
||||
static bool moveCharactersLeft(uint64_t flags);
|
||||
static bool moveCharactersRight(uint64_t flags);
|
||||
|
||||
private:
|
||||
uint64_t select_flags = 0;
|
||||
bool edit_box = false;
|
||||
bool tool_box = false;
|
||||
SDLPP::Vec2D< int > edit_box_location = { -1, -1 };
|
||||
SDLPP::Vec2D< int > tool_box_location = { -1, -1 };
|
||||
SDLPP::Vec2D<int> edit_box_location = { -1, -1 };
|
||||
SDLPP::Vec2D<int> tool_box_location = { -1, -1 };
|
||||
uint64_t _type{};
|
||||
uint64_t tool_box_type = 0;
|
||||
};
|
||||
@ -69,14 +69,14 @@ private:
|
||||
class ToolVisitor : public SDLPP::Visitor {
|
||||
public:
|
||||
ToolVisitor() = default;
|
||||
void visit( const SDLPP::RenderObject &obj ) override;
|
||||
void setFromId( uint64_t id ) override {
|
||||
void visit(const SDLPP::RenderObject &obj) override;
|
||||
void setFromId(uint64_t id) override {
|
||||
source_id = id;
|
||||
}
|
||||
uint64_t getFromId() const override {
|
||||
return source_id;
|
||||
}
|
||||
void setVisitorType( uint64_t type ) override {
|
||||
void setVisitorType(uint64_t type) override {
|
||||
_type = type;
|
||||
}
|
||||
uint64_t getVisitorType() const override {
|
||||
|
@ -1,12 +1,12 @@
|
||||
#include "global_vars.hpp"
|
||||
#include "../sdlpp/sdlpp_texture.hpp"
|
||||
|
||||
std::shared_ptr< SDLPP::Texture > g_terrain_texture{};
|
||||
std::shared_ptr< SDLPP::Texture > g_mario_texture{};
|
||||
std::shared_ptr< SDLPP::Texture > g_mod_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_mod_texture{};
|
||||
std::shared_ptr< SDLPP::Texture > g_translucent_enemies_texture;
|
||||
std::shared_ptr< SDLPP::Scene > g_playground{};
|
||||
std::shared_ptr< SDLPP::FontConfiguration > g_text_config{};
|
||||
std::shared_ptr<SDLPP::Texture> g_terrain_texture{};
|
||||
std::shared_ptr<SDLPP::Texture> g_mario_texture{};
|
||||
std::shared_ptr<SDLPP::Texture> g_mod_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_mod_texture{};
|
||||
std::shared_ptr<SDLPP::Texture> g_translucent_enemies_texture;
|
||||
std::shared_ptr<SDLPP::Scene> g_playground{};
|
||||
std::shared_ptr<SDLPP::FontConfiguration> g_text_config{};
|
||||
|
@ -3,14 +3,14 @@
|
||||
|
||||
#include "../sdlpp/sdlpp.hpp"
|
||||
|
||||
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_mod_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_mod_texture;
|
||||
extern std::shared_ptr< SDLPP::Texture > g_translucent_enemies_texture;
|
||||
extern std::shared_ptr< SDLPP::Scene > g_playground;
|
||||
extern std::shared_ptr< SDLPP::FontConfiguration > g_text_config;
|
||||
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_mod_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_mod_texture;
|
||||
extern std::shared_ptr<SDLPP::Texture> g_translucent_enemies_texture;
|
||||
extern std::shared_ptr<SDLPP::Scene> g_playground;
|
||||
extern std::shared_ptr<SDLPP::FontConfiguration> g_text_config;
|
||||
|
||||
#endif
|
||||
|
248
mario/main.cpp
248
mario/main.cpp
@ -22,20 +22,20 @@
|
||||
|
||||
bool quit = false;
|
||||
bool update = false;
|
||||
std::shared_ptr< Mario > mario = nullptr;
|
||||
std::shared_ptr< SDLPP::RectangleRender > leftStop = nullptr;
|
||||
std::shared_ptr< SDLPP::Renderer > renderer = nullptr;
|
||||
std::shared_ptr< SDLPP::TextRenderer > fps = nullptr;
|
||||
std::shared_ptr< SDLPP::TextRenderer > coins = nullptr;
|
||||
std::shared_ptr<Mario> mario = nullptr;
|
||||
std::shared_ptr<SDLPP::RectangleRender> leftStop = nullptr;
|
||||
std::shared_ptr<SDLPP::Renderer> renderer = nullptr;
|
||||
std::shared_ptr<SDLPP::TextRenderer> fps = nullptr;
|
||||
std::shared_ptr<SDLPP::TextRenderer> coins = nullptr;
|
||||
int coin_count = 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;
|
||||
|
||||
void handleKeyDown( SDL_Keycode key, SDLPP::Scene &scene ) {
|
||||
switch ( key ) {
|
||||
void handleKeyDown(SDL_Keycode key, SDLPP::Scene &scene) {
|
||||
switch (key) {
|
||||
case SDLK_ESCAPE:
|
||||
quit = true;
|
||||
break;
|
||||
@ -53,19 +53,19 @@ void handleKeyDown( SDL_Keycode key, SDLPP::Scene &scene ) {
|
||||
break;
|
||||
case SDLK_r:
|
||||
scene.getRenderer().setRenderColiders(
|
||||
!scene.getRenderer().getRenderColiders() );
|
||||
!scene.getRenderer().getRenderColiders());
|
||||
break;
|
||||
case SDLK_f:
|
||||
if ( fps ) {
|
||||
fps->setHidden( !fps->getHidden() );
|
||||
if (fps) {
|
||||
fps->setHidden(!fps->getHidden());
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void handleKeyUp( SDL_Keycode key ) {
|
||||
switch ( key ) {
|
||||
void handleKeyUp(SDL_Keycode key) {
|
||||
switch (key) {
|
||||
case SDLK_a:
|
||||
mario->walkRight();
|
||||
break;
|
||||
@ -80,52 +80,53 @@ void handleKeyUp( SDL_Keycode key ) {
|
||||
}
|
||||
}
|
||||
|
||||
void moveToMarioPosition( SDLPP::Scene &scene,
|
||||
SDLPP::Vec2D< double > &prev_mario ) {
|
||||
void moveToMarioPosition(SDLPP::Scene &scene,
|
||||
SDLPP::Vec2D<double> &prev_mario) {
|
||||
auto rendDims = renderer->getDoubleDimensions();
|
||||
if ( leftStop ) {
|
||||
if (leftStop) {
|
||||
auto left =
|
||||
rendDims.getX() < 2.0 ? -( rendDims.getX() - 1 ) / 2.0 - 0.1 : -0.5;
|
||||
leftStop->setPos( left, 0 );
|
||||
rendDims.getX() < 2.0 ? -(rendDims.getX() - 1) / 2.0 - 0.1 : -0.5;
|
||||
leftStop->setPos(left, 0);
|
||||
}
|
||||
auto mario_pos_difference = prev_mario - mario->getAbsolutePos();
|
||||
// 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
|
||||
// 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
|
||||
scene.moveEverything(-(mario->getAbsolutePos().getX() - 0.01), 0);
|
||||
} else {
|
||||
scene.moveEverything( mario_pos_difference.getX(), 0 );
|
||||
scene.moveEverything(mario_pos_difference.getX(), 0);
|
||||
}
|
||||
scene.updateSizeAndPosition();
|
||||
auto left_stop_rightmost = leftStop->getDoubleRect().first.getX() +
|
||||
leftStop->getDoubleRect().second.getX();
|
||||
if ( mario->getPos().getX() < left_stop_rightmost ) {
|
||||
mario->setPos( left_stop_rightmost, mario->getPos().getY() );
|
||||
if (mario->getPos().getX() < left_stop_rightmost) {
|
||||
mario->setPos(left_stop_rightmost, mario->getPos().getY());
|
||||
}
|
||||
}
|
||||
|
||||
void pollEvents( SDLPP::Scene &scene ) {
|
||||
void pollEvents(SDLPP::Scene &scene) {
|
||||
SDL_Event event;
|
||||
while ( SDLPP::getSDLEvent( event ) ) {
|
||||
switch ( event.type ) {
|
||||
while (SDLPP::getSDLEvent(event)) {
|
||||
switch (event.type) {
|
||||
case SDL_QUIT:
|
||||
quit = true;
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
if ( !event.key.repeat ) {
|
||||
handleKeyDown( event.key.keysym.sym, scene );
|
||||
if (!event.key.repeat) {
|
||||
handleKeyDown(event.key.keysym.sym, scene);
|
||||
}
|
||||
break;
|
||||
case SDL_KEYUP:
|
||||
handleKeyUp( event.key.keysym.sym );
|
||||
handleKeyUp(event.key.keysym.sym);
|
||||
break;
|
||||
case SDL_WINDOWEVENT:
|
||||
if ( event.window.event == SDL_WINDOWEVENT_RESIZED ) {
|
||||
if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
|
||||
auto prev_mario_pos = mario->getAbsolutePos();
|
||||
scene.updateSizeAndPosition();
|
||||
moveToMarioPosition( scene, prev_mario_pos );
|
||||
moveToMarioPosition(scene, prev_mario_pos);
|
||||
update = true;
|
||||
}
|
||||
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;
|
||||
SDL_initFramerate( &gFPS );
|
||||
SDL_setFramerate( &gFPS, 200 );
|
||||
while ( !quit ) {
|
||||
SDL_framerateDelay( &gFPS );
|
||||
pollEvents( *scene );
|
||||
std::lock_guard< std::mutex > lock( render_mutex );
|
||||
SDL_initFramerate(&gFPS);
|
||||
SDL_setFramerate(&gFPS, 200);
|
||||
while (!quit) {
|
||||
SDL_framerateDelay(&gFPS);
|
||||
pollEvents(*scene);
|
||||
std::lock_guard<std::mutex> lock(render_mutex);
|
||||
scene->updateScene();
|
||||
auto prev_coin_count = coin_count;
|
||||
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);
|
||||
if(!moving_objects[i]->wasVisible()) {
|
||||
if (!moving_objects[i]->wasVisible()) {
|
||||
continue;
|
||||
}
|
||||
auto visitor =
|
||||
getVisitor( *moving_objects[i], *scene, quit, coin_count, moving_objects );
|
||||
scene->visitCollisions( *moving_objects[i], *visitor );
|
||||
moving_objects[i]->handleVisitor( *visitor );
|
||||
auto rightmost_pos = moving_objects[i]->getAbsolutePos().getX() +
|
||||
moving_objects[i]->getDoubleRect().second.getX();
|
||||
if(rightmost_pos < 0 && moving_objects[i] != mario) {
|
||||
auto visitor = getVisitor(*moving_objects[i], *scene, quit,
|
||||
coin_count, moving_objects);
|
||||
scene->visitCollisions(*moving_objects[i], *visitor);
|
||||
moving_objects[i]->handleVisitor(*visitor);
|
||||
auto rightmost_pos =
|
||||
moving_objects[i]->getAbsolutePos().getX() +
|
||||
moving_objects[i]->getDoubleRect().second.getX();
|
||||
if (rightmost_pos < 0 && moving_objects[i] != mario) {
|
||||
moving_objects[i]->destroy();
|
||||
}
|
||||
}
|
||||
std::vector<uint64_t> killed_indices{};
|
||||
for(size_t i = 0; i < moving_objects.size(); i++) {
|
||||
if(moving_objects[i]->getKilled()) {
|
||||
for (size_t i = 0; i < moving_objects.size(); i++) {
|
||||
if (moving_objects[i]->getKilled()) {
|
||||
killed_indices.push_back(i);
|
||||
}
|
||||
}
|
||||
std::reverse( killed_indices.begin(), killed_indices.end() );
|
||||
for(auto &index : killed_indices) {
|
||||
std::reverse(killed_indices.begin(), killed_indices.end());
|
||||
for (auto &index : killed_indices) {
|
||||
moving_objects.erase(moving_objects.begin() + index);
|
||||
}
|
||||
|
||||
if ( coin_count != prev_coin_count ) {
|
||||
coins->changeText( std::to_string( coin_count ) + " COINS" );
|
||||
if (coin_count != prev_coin_count) {
|
||||
coins->changeText(std::to_string(coin_count) + " COINS");
|
||||
}
|
||||
// if player is > 0.7 of playground, move everything left
|
||||
auto playerX = mario->getRect().x;
|
||||
@ -180,108 +182,110 @@ void doInput( std::shared_ptr< SDLPP::Scene > scene ) {
|
||||
auto rightBarrier = width * 0.5;
|
||||
auto rightmostX =
|
||||
scene->rightmost()->getRect().x + scene->rightmost()->getRect().w;
|
||||
scene->moveEverything(
|
||||
( playerX > rightBarrier && rightmostX > width ) *
|
||||
( rightBarrier - playerX ) / width,
|
||||
0 );
|
||||
scene->moveEverything((playerX > rightBarrier && rightmostX > width) *
|
||||
(rightBarrier - playerX) / width,
|
||||
0);
|
||||
update = update || (playerX > rightBarrier && rightmostX > width);
|
||||
global_frames++;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
||||
PWSTR szCmdLine, int nCmdShow ) {
|
||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
||||
PWSTR szCmdLine, int nCmdShow) {
|
||||
#else
|
||||
int main() {
|
||||
#endif
|
||||
SDLPP::init();
|
||||
SDLPP::Window w( "Mario clone!" );
|
||||
w.setResizable( true );
|
||||
SDLPP::Window w("Mario clone!");
|
||||
w.setResizable(true);
|
||||
|
||||
renderer = std::make_shared< SDLPP::Renderer >( w );
|
||||
renderer->setBlendMode( SDL_BLENDMODE_BLEND );
|
||||
renderer = std::make_shared<SDLPP::Renderer>(w);
|
||||
renderer->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||
|
||||
// prepare global vars
|
||||
g_terrain_texture = std::make_shared< SDLPP::Texture >(
|
||||
renderer, "sprites/terrain.png", MARIO_OVERWORLD_COLORKEY );
|
||||
g_enemies_texture = std::make_shared< SDLPP::Texture >(
|
||||
renderer, "sprites/enemies.png", MARIO_OVERWORLD_COLORKEY );
|
||||
g_terrain_texture = std::make_shared<SDLPP::Texture>(
|
||||
renderer, "sprites/terrain.png", MARIO_OVERWORLD_COLORKEY);
|
||||
g_enemies_texture = std::make_shared<SDLPP::Texture>(
|
||||
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;
|
||||
auto bg = std::make_shared< SDLPP::RectangleRender >(
|
||||
0, 0, 10, 10, renderer, MARIO_OVERWORLD_COLORKEY, true );
|
||||
auto bg = std::make_shared<SDLPP::RectangleRender>(
|
||||
0, 0, 10, 10, renderer, MARIO_OVERWORLD_COLORKEY, true);
|
||||
bg->setPermanent();
|
||||
bg->setStatic();
|
||||
bg->setId( 1 );
|
||||
scene->addObject( bg );
|
||||
g_mario_texture = std::make_shared< SDLPP::Texture >(
|
||||
renderer, "sprites/mario.png", MARIO_OVERWORLD_COLORKEY );
|
||||
g_translucent_terrain_texture = std::make_shared< SDLPP::Texture >(
|
||||
renderer, "sprites/terrain.png", MARIO_OVERWORLD_COLORKEY );
|
||||
g_translucent_terrain_texture->setAlpha( 100 );
|
||||
mario = std::make_shared< Mario >( renderer );
|
||||
scene->addObject( mario );
|
||||
bg->setId(1);
|
||||
scene->addObject(bg);
|
||||
g_mario_texture = std::make_shared<SDLPP::Texture>(
|
||||
renderer, "sprites/mario.png", MARIO_OVERWORLD_COLORKEY);
|
||||
g_translucent_terrain_texture = std::make_shared<SDLPP::Texture>(
|
||||
renderer, "sprites/terrain.png", MARIO_OVERWORLD_COLORKEY);
|
||||
g_translucent_terrain_texture->setAlpha(100);
|
||||
mario = std::make_shared<Mario>(renderer);
|
||||
scene->addObject(mario);
|
||||
|
||||
auto defeat =
|
||||
std::make_shared< SDLPP::RectangleRender >( 0, 1.01, 0, 0, renderer );
|
||||
defeat->setId( DEATH_ID );
|
||||
defeat->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||
std::make_shared<SDLPP::RectangleRender>(0, 1.01, 0, 0, renderer);
|
||||
defeat->setId(DEATH_ID);
|
||||
defeat->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
|
||||
defeat->setPermanent();
|
||||
auto defeatCol = SDLPP::RectColider( -1, 0, -1, -1 );
|
||||
auto defeatCol = SDLPP::RectColider(-1, 0, -1, -1);
|
||||
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,
|
||||
renderer );
|
||||
leftStop->setId( STOP_MOVEMENT );
|
||||
leftStop->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||
leftStop =
|
||||
std::make_shared<SDLPP::RectangleRender>(-0.1, 0, 0.11, 0, renderer);
|
||||
leftStop->setId(STOP_MOVEMENT);
|
||||
leftStop->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
|
||||
leftStop->setPermanent();
|
||||
auto leftStopCol = SDLPP::RectColider( 0, -1, 1, -1 );
|
||||
auto leftStopCol = SDLPP::RectColider(0, -1, 1, -1);
|
||||
leftStopCol.setInfinite();
|
||||
leftStop->addCollision( leftStopCol );
|
||||
leftStop->setColiderColor( "#FF00FF" );
|
||||
scene->addObject( leftStop );
|
||||
leftStop->addCollision(leftStopCol);
|
||||
leftStop->setColiderColor("#FF00FF");
|
||||
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 );
|
||||
fps = std::make_shared< SDLPP::TextRenderer >(
|
||||
auto font = std::make_shared<SDLPP::Font>("testfont.ttf", 36);
|
||||
fps = std::make_shared<SDLPP::TextRenderer>(
|
||||
0.2, 0, 0.78, 0.1, renderer, font, "0fps", "#FFFFFF", "#000000", 0.1,
|
||||
SDLPP_TEXT_RIGHT );
|
||||
fps->setAlignment( SDLPP::OBJ_END, SDLPP::OBJ_START );
|
||||
fps->setId( 0 );
|
||||
SDLPP_TEXT_RIGHT);
|
||||
fps->setAlignment(SDLPP::OBJ_END, SDLPP::OBJ_START);
|
||||
fps->setId(0);
|
||||
fps->setPermanent();
|
||||
fps->setHidden( true );
|
||||
scene->addObject( fps );
|
||||
fps->setHidden(true);
|
||||
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,
|
||||
SDLPP_TEXT_RIGHT );
|
||||
coins->setAlignment( SDLPP::OBJ_START, SDLPP::OBJ_START );
|
||||
coins->setId( 0 );
|
||||
SDLPP_TEXT_RIGHT);
|
||||
coins->setAlignment(SDLPP::OBJ_START, SDLPP::OBJ_START);
|
||||
coins->setId(0);
|
||||
coins->setPermanent();
|
||||
scene->addObject( coins );
|
||||
scene->addObject(coins);
|
||||
|
||||
FPSmanager gFPS;
|
||||
SDL_initFramerate( &gFPS );
|
||||
SDL_setFramerate( &gFPS, 60 );
|
||||
SDL_initFramerate(&gFPS);
|
||||
SDL_setFramerate(&gFPS, 60);
|
||||
|
||||
auto base = SDL_GetTicks();
|
||||
int frames = 0;
|
||||
scene->moveEverything( -mario->getDoubleRect().first.getX() + 0.2, 0 );
|
||||
scene->moveEverything(-mario->getDoubleRect().first.getX() + 0.2, 0);
|
||||
update = true;
|
||||
|
||||
std::unordered_set<uint64_t> background_ids = {
|
||||
HILL_INCLINE_ID, HILL_DECLINE_ID, HILL_DOTS_RIGHT_ID, HILL_DOTS_LEFT_ID,
|
||||
HILL_FILL_ID, HILL_TOP_ID, BUSH_LEFT_ID, BUSH_MIDDLE_ID, BUSH_RIGHT_ID,
|
||||
HILL_INCLINE_ID, HILL_DECLINE_ID, HILL_DOTS_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_TOP_ID, CLOUD_MIDDLE_TOP_ID, CLOUD_RIGHT_TOP_ID,
|
||||
CASTLE_LEFT_ID, CASTLE_RIGHT_ID, CASTLE_BLACK_ID, CASTLE_ENTRY_ID,
|
||||
CASTLE_TOWER_ID, CASTLE_TOWER_FILLED_ID, WATER_TOP_ID, WATER_FILL_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_TOWER_ID, CASTLE_TOWER_FILLED_ID,
|
||||
WATER_TOP_ID, WATER_FILL_ID
|
||||
};
|
||||
scene->setBackgroundObjectIDs(background_ids);
|
||||
scene->updateBackgroundObjectZIndex();
|
||||
|
||||
@ -290,35 +294,35 @@ int main() {
|
||||
std::unordered_set<int> moving_object_ids = {
|
||||
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));
|
||||
}
|
||||
|
||||
std::thread inputThread( doInput, scene );
|
||||
std::thread inputThread(doInput, scene);
|
||||
SDL_PumpEvents();
|
||||
scene->updateSizeAndPosition();
|
||||
scene->renderScene();
|
||||
renderer->presentRenderer();
|
||||
|
||||
update = true;
|
||||
while ( !quit ) {
|
||||
SDL_framerateDelay( &gFPS );
|
||||
while (!quit) {
|
||||
SDL_framerateDelay(&gFPS);
|
||||
SDL_PumpEvents();
|
||||
std::lock_guard< std::mutex > lock( render_mutex );
|
||||
std::lock_guard<std::mutex> lock(render_mutex);
|
||||
mario->setStanding();
|
||||
if ( update ) {
|
||||
if (update) {
|
||||
scene->updateSizeAndPosition();
|
||||
update = false;
|
||||
}
|
||||
scene->renderScene();
|
||||
renderer->presentRenderer();
|
||||
frames++;
|
||||
if ( SDL_GetTicks() - base >= 1000 ) {
|
||||
if ( global_frames < frames ) {
|
||||
if (SDL_GetTicks() - base >= 1000) {
|
||||
if (global_frames < frames) {
|
||||
frames = global_frames;
|
||||
}
|
||||
global_frames = 0;
|
||||
fps->changeText( std::to_string( frames ) + " fps" );
|
||||
fps->changeText(std::to_string(frames) + " fps");
|
||||
frames = 0;
|
||||
base = SDL_GetTicks();
|
||||
}
|
||||
|
@ -11,213 +11,212 @@
|
||||
#define WIDE_TERRAIN_HAS_ADDITIONAL 0x8000
|
||||
#define ADDITIONAL_IS_MOD 0x80
|
||||
|
||||
void loadMap( std::shared_ptr< SDLPP::Scene > &scene,
|
||||
std::shared_ptr< SDLPP::RenderObject > mario,
|
||||
const std::string &file ) {
|
||||
std::vector< mapColumnType > tmp = {};
|
||||
loadMap( scene, mario, file, tmp, false );
|
||||
scene->moveZTop( mario );
|
||||
void loadMap(std::shared_ptr<SDLPP::Scene> &scene,
|
||||
std::shared_ptr<SDLPP::RenderObject> mario,
|
||||
const std::string &file) {
|
||||
std::vector<mapColumnType> tmp = {};
|
||||
loadMap(scene, mario, file, tmp, false);
|
||||
scene->moveZTop(mario);
|
||||
}
|
||||
|
||||
uint8_t read8Bits( std::ifstream &file ) {
|
||||
uint8_t read8Bits(std::ifstream &file) {
|
||||
uint8_t data;
|
||||
file.read( ( char * )&data, sizeof( uint8_t ) / sizeof( char ) );
|
||||
file.read((char *)&data, sizeof(uint8_t) / sizeof(char));
|
||||
return data;
|
||||
}
|
||||
void write8Bits( std::ofstream &file, uint8_t data ) {
|
||||
file.write( ( char * )&data, sizeof( uint8_t ) / sizeof( char ) );
|
||||
void write8Bits(std::ofstream &file, uint8_t data) {
|
||||
file.write((char *)&data, sizeof(uint8_t) / sizeof(char));
|
||||
}
|
||||
|
||||
uint16_t read16Bits( std::ifstream &file ) {
|
||||
uint16_t read16Bits(std::ifstream &file) {
|
||||
uint16_t data;
|
||||
file.read( ( char * )&data, sizeof( uint16_t ) / sizeof( char ) );
|
||||
file.read((char *)&data, sizeof(uint16_t) / sizeof(char));
|
||||
return data;
|
||||
}
|
||||
void write16Bits( std::ofstream &file, uint16_t data ) {
|
||||
file.write( ( char * )&data, sizeof( uint16_t ) / sizeof( char ) );
|
||||
void write16Bits(std::ofstream &file, uint16_t data) {
|
||||
file.write((char *)&data, sizeof(uint16_t) / sizeof(char));
|
||||
}
|
||||
|
||||
std::pair< uint16_t, uint8_t > separateWideTerrain( uint16_t wide_terrain ) {
|
||||
uint8_t terrain_type = ( wide_terrain & 0xF000 ) >> 12;
|
||||
uint16_t terrain_id = ( wide_terrain & 0x0FFF ) | BLOCK_PREFIX;
|
||||
std::pair<uint16_t, uint8_t> separateWideTerrain(uint16_t wide_terrain) {
|
||||
uint8_t terrain_type = (wide_terrain & 0xF000) >> 12;
|
||||
uint16_t terrain_id = (wide_terrain & 0x0FFF) | BLOCK_PREFIX;
|
||||
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 type = ( data & 0xF0 ) >> 4;
|
||||
auto type = (data & 0xF0) >> 4;
|
||||
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;
|
||||
wide_terrain = wide_terrain << 12;
|
||||
wide_terrain |= 0x0FFF & id;
|
||||
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;
|
||||
}
|
||||
|
||||
MapObject parseBlock( std::ifstream &map_file ) {
|
||||
MapObject parseBlock(std::ifstream &map_file) {
|
||||
uint8_t character_type = 0;
|
||||
uint8_t character_id = 0;
|
||||
uint32_t modifier_id = 0;
|
||||
uint8_t modifier_data = 0;
|
||||
uint16_t wide_terrain = read16Bits( map_file );
|
||||
auto terrain = separateWideTerrain( wide_terrain );
|
||||
uint16_t wide_terrain = read16Bits(map_file);
|
||||
auto terrain = separateWideTerrain(wide_terrain);
|
||||
uint16_t terrain_id = terrain.first;
|
||||
uint8_t terrain_type = terrain.second;
|
||||
if ( terrain_type & TERRAIN_TYPE_HAS_ADDITIONAL ) {
|
||||
uint8_t additional_data = read8Bits( map_file );
|
||||
if (terrain_type & TERRAIN_TYPE_HAS_ADDITIONAL) {
|
||||
uint8_t additional_data = read8Bits(map_file);
|
||||
terrain_type &= ~TERRAIN_TYPE_HAS_ADDITIONAL;
|
||||
if ( additional_data & ADDITIONAL_IS_MOD ) {
|
||||
if (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
|
||||
modifier_id = modifier.second | 0x6000;
|
||||
modifier_data = modifier.first;
|
||||
} else {
|
||||
// character
|
||||
auto character = separateAdditionalData( additional_data );
|
||||
auto character = separateAdditionalData(additional_data);
|
||||
character_id = character.first;
|
||||
character_type = character.second;
|
||||
}
|
||||
}
|
||||
return MapObject( terrain_id, terrain_type, character_id, character_type,
|
||||
modifier_id, modifier_data );
|
||||
return MapObject(terrain_id, terrain_type, character_id, character_type,
|
||||
modifier_id, modifier_data);
|
||||
}
|
||||
|
||||
// editor loader
|
||||
void loadMap( std::shared_ptr< SDLPP::Scene > &scene,
|
||||
std::shared_ptr< SDLPP::RenderObject > &mario,
|
||||
const std::string &file,
|
||||
std::vector< mapColumnType > &objects, bool editor,
|
||||
size_t editor_width ) {
|
||||
void loadMap(std::shared_ptr<SDLPP::Scene> &scene,
|
||||
std::shared_ptr<SDLPP::RenderObject> &mario,
|
||||
const std::string &file, std::vector<mapColumnType> &objects,
|
||||
bool editor, size_t editor_width) {
|
||||
auto renderer = scene->getRendererShared();
|
||||
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;
|
||||
map_file.read( ( char * )&cols, sizeof( uint16_t ) / sizeof( char ) );
|
||||
if ( editor ) {
|
||||
objects.resize( cols );
|
||||
map_file.read((char *)&cols, sizeof(uint16_t) / sizeof(char));
|
||||
if (editor) {
|
||||
objects.resize(cols);
|
||||
}
|
||||
|
||||
mapColumnType *col = nullptr;
|
||||
for ( uint16_t i = 0; i < cols; i++ ) {
|
||||
if ( editor ) {
|
||||
for (uint16_t i = 0; i < cols; i++) {
|
||||
if (editor) {
|
||||
col = &objects[i];
|
||||
}
|
||||
for ( int j = 0; j < 16; j++ ) {
|
||||
auto block = parseBlock( map_file );
|
||||
if ( editor ) {
|
||||
col->at( j ) = block;
|
||||
for (int j = 0; j < 16; j++) {
|
||||
auto block = parseBlock(map_file);
|
||||
if (editor) {
|
||||
col->at(j) = block;
|
||||
}
|
||||
bool destructible = false;
|
||||
bool removeCollisions = false;
|
||||
int coinCount = 0;
|
||||
bool mushroom = false;
|
||||
if ( !editor &&
|
||||
block.getModifierId() == DESTRUCTIBLE_MODIFIER_ID ) {
|
||||
if (!editor && block.getModifierId() == DESTRUCTIBLE_MODIFIER_ID) {
|
||||
destructible = true;
|
||||
}
|
||||
if ( !editor &&
|
||||
block.getModifierId() == BACKGROUND_MODIFIER_ID ) {
|
||||
if (!editor && block.getModifierId() == BACKGROUND_MODIFIER_ID) {
|
||||
destructible = false;
|
||||
removeCollisions = true;
|
||||
}
|
||||
if ( !editor &&
|
||||
block.getModifierId() == COIN_MODIFIER_ID ) {
|
||||
if (!editor && block.getModifierId() == COIN_MODIFIER_ID) {
|
||||
coinCount = block.getModifierData();
|
||||
}
|
||||
if ( !editor && block.getModifierId() == MUSHROOM_MODIFIER_ID ) {
|
||||
if (!editor && block.getModifierId() == MUSHROOM_MODIFIER_ID) {
|
||||
mushroom = true;
|
||||
}
|
||||
// TODO add modifiers to createTerrainBlock
|
||||
if(block.getTerrainId() != 0) {
|
||||
auto obj = createTerrainBlock(
|
||||
block.getTerrainId(), block.getTerrainType(),
|
||||
renderer, i, j, destructible, editor );
|
||||
if(obj != nullptr) {
|
||||
if (block.getTerrainId() != 0) {
|
||||
auto obj = createTerrainBlock(block.getTerrainId(),
|
||||
block.getTerrainType(), renderer,
|
||||
i, j, destructible, editor);
|
||||
if (obj != nullptr) {
|
||||
obj->setCoinCount(coinCount);
|
||||
if(mushroom) {
|
||||
if (mushroom) {
|
||||
obj->addMushroom();
|
||||
}
|
||||
if(removeCollisions) {
|
||||
if (removeCollisions) {
|
||||
obj->removeCollisions();
|
||||
}
|
||||
if ( obj != nullptr ) {
|
||||
if ( editor ) {
|
||||
obj->getCollisions()[0]->setId( EDITOR_TERRAIN_ID );
|
||||
if (obj != nullptr) {
|
||||
if (editor) {
|
||||
obj->getCollisions()[0]->setId(EDITOR_TERRAIN_ID);
|
||||
}
|
||||
scene->addObject( obj );
|
||||
scene->addObject(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( block.hasCharacter() ) {
|
||||
if ( block.getCharacterId() == MARIO_ID ) {
|
||||
if ( editor ) {
|
||||
scene->addObject( createMario(
|
||||
block.getCharacterType(),
|
||||
renderer, i, j, true ) );
|
||||
if (block.hasCharacter()) {
|
||||
if (block.getCharacterId() == MARIO_ID) {
|
||||
if (editor) {
|
||||
scene->addObject(createMario(block.getCharacterType(),
|
||||
renderer, i, j, true));
|
||||
mario =
|
||||
scene->getObject( scene->getObjects().size() - 1 );
|
||||
scene->getObject(scene->getObjects().size() - 1);
|
||||
} else {
|
||||
mario->setPos( i * BLOCK_SIZE,
|
||||
1 - ( 16 - j ) * BLOCK_SIZE );
|
||||
mario->setPos(i * BLOCK_SIZE,
|
||||
1 - (16 - j) * BLOCK_SIZE);
|
||||
}
|
||||
} else {
|
||||
auto obj = createTerrainBlock(
|
||||
block.getCharacterId(), block.getCharacterType(),
|
||||
renderer, i, j, destructible, editor);
|
||||
dynamic_cast< MarioBlock * >( obj.get() )->setTerrain( false );
|
||||
if ( editor ) {
|
||||
obj->getCollisions()[0]->setId( EDITOR_CHARACTER_ID );
|
||||
block.getCharacterId(), block.getCharacterType(),
|
||||
renderer, i, j, destructible, editor);
|
||||
dynamic_cast<MarioBlock *>(obj.get())->setTerrain(false);
|
||||
if (editor) {
|
||||
obj->getCollisions()[0]->setId(EDITOR_CHARACTER_ID);
|
||||
}
|
||||
scene->addObject(obj);
|
||||
}
|
||||
}
|
||||
if ( editor && block.hasModifier() ) {
|
||||
if (editor && block.hasModifier()) {
|
||||
// TODO createModifierBlock with data
|
||||
auto mod = createTerrainBlock(
|
||||
block.getModifierId(), LandType::OVERWORLD, renderer, i, j,
|
||||
false, editor );
|
||||
auto mod = createTerrainBlock(block.getModifierId(),
|
||||
LandType::OVERWORLD, renderer, i,
|
||||
j, false, editor);
|
||||
mod->setData(block.getModifierData());
|
||||
mod->setTextureKeepSRC(g_translucent_mod_texture);
|
||||
mod->getCollisions()[0]->setId( EDITOR_TERRAIN_ID );
|
||||
dynamic_cast< MarioBlock * >( mod.get() )->setTerrain( false );
|
||||
scene->addObject( mod );
|
||||
mod->getCollisions()[0]->setId(EDITOR_TERRAIN_ID);
|
||||
dynamic_cast<MarioBlock *>(mod.get())->setTerrain(false);
|
||||
scene->addObject(mod);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( editor && objects.size() < editor_width ) {
|
||||
objects.resize( editor_width );
|
||||
if (editor && objects.size() < 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;
|
||||
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();
|
||||
output_file.write( ( char * )&cols, sizeof( uint16_t ) / sizeof( char ) );
|
||||
for ( auto &col : objects ) {
|
||||
for ( int i = 0; i < 16; i++ ) {
|
||||
output_file.write((char *)&cols, sizeof(uint16_t) / sizeof(char));
|
||||
for (auto &col : objects) {
|
||||
for (int i = 0; i < 16; 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.hasCharacter() || block.hasModifier() ) {
|
||||
if (block.hasCharacter() || block.hasModifier()) {
|
||||
wide_terrain |= WIDE_TERRAIN_HAS_ADDITIONAL;
|
||||
}
|
||||
write16Bits(output_file, wide_terrain);
|
||||
uint8_t additional_data = 0;
|
||||
if ( block.hasCharacter() ) {
|
||||
additional_data = combineAdditionalData(block.getCharacterId(), block.getCharacterType());
|
||||
} else if ( block.hasModifier() ) {
|
||||
if (block.hasCharacter()) {
|
||||
additional_data = combineAdditionalData(
|
||||
block.getCharacterId(), block.getCharacterType());
|
||||
} else if (block.hasModifier()) {
|
||||
// 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
|
||||
additional_data = combineAdditionalData(block.getModifierData(), block.getModifierId() & 0x000F);
|
||||
// we have IDs like 0x600X but only X is useful data, the 0x6 at
|
||||
// the beginning is to differentiate mods from characters
|
||||
additional_data = combineAdditionalData(
|
||||
block.getModifierData(), block.getModifierId() & 0x000F);
|
||||
additional_data |= ADDITIONAL_IS_MOD;
|
||||
}
|
||||
if ( additional_data ) {
|
||||
if (additional_data) {
|
||||
write8Bits(output_file, additional_data);
|
||||
}
|
||||
}
|
||||
|
@ -5,15 +5,15 @@
|
||||
#include "../sdlpp/sdlpp_rectrenderer.hpp"
|
||||
#include "mapobject.hpp"
|
||||
|
||||
typedef std::array< MapObject, 16 > mapColumnType;
|
||||
typedef std::array<MapObject, 16> mapColumnType;
|
||||
|
||||
void loadMap( std::shared_ptr< SDLPP::Scene > &scene,
|
||||
std::shared_ptr< SDLPP::RenderObject > mario,
|
||||
const std::string &file );
|
||||
void loadMap( std::shared_ptr< SDLPP::Scene > &scene,
|
||||
std::shared_ptr< SDLPP::RenderObject > &mario,
|
||||
const std::string &file,
|
||||
std::vector< mapColumnType > &objects, bool editor = false, size_t editor_width = 0 );
|
||||
void saveMap( const std::string &file, std::vector< mapColumnType > &objects );
|
||||
void loadMap(std::shared_ptr<SDLPP::Scene> &scene,
|
||||
std::shared_ptr<SDLPP::RenderObject> mario,
|
||||
const std::string &file);
|
||||
void loadMap(std::shared_ptr<SDLPP::Scene> &scene,
|
||||
std::shared_ptr<SDLPP::RenderObject> &mario,
|
||||
const std::string &file, std::vector<mapColumnType> &objects,
|
||||
bool editor = false, size_t editor_width = 0);
|
||||
void saveMap(const std::string &file, std::vector<mapColumnType> &objects);
|
||||
|
||||
#endif
|
||||
|
@ -1,49 +1,48 @@
|
||||
#include "mapobject.hpp"
|
||||
|
||||
MapObject::MapObject( uint16_t terrain_id, LandType::Value terrain_type,
|
||||
uint8_t character_id, LandType::Value character_type,
|
||||
uint32_t modifier_id, uint8_t modifier_data ) {
|
||||
MapObject::MapObject(uint16_t terrain_id, LandType::Value terrain_type,
|
||||
uint8_t character_id, LandType::Value character_type,
|
||||
uint32_t modifier_id, uint8_t modifier_data) {
|
||||
setTerrain(terrain_id, terrain_type);
|
||||
if(character_id != 0)
|
||||
if (character_id != 0)
|
||||
setCharacter(character_id, character_type);
|
||||
if(modifier_id != 0)
|
||||
if (modifier_id != 0)
|
||||
setModifier(modifier_id, modifier_data);
|
||||
}
|
||||
|
||||
MapObject::MapObject( uint16_t terrain_id, uint8_t terrain_type,
|
||||
uint8_t character_id, uint8_t character_type,
|
||||
uint32_t modifier_id, uint8_t modifier_data )
|
||||
: MapObject( terrain_id, static_cast< LandType::Value >( terrain_type ),
|
||||
character_id,
|
||||
static_cast< LandType::Value >( character_type ),
|
||||
modifier_id, modifier_data ) {}
|
||||
MapObject::MapObject(uint16_t terrain_id, uint8_t terrain_type,
|
||||
uint8_t character_id, uint8_t character_type,
|
||||
uint32_t modifier_id, uint8_t modifier_data)
|
||||
: MapObject(terrain_id, static_cast<LandType::Value>(terrain_type),
|
||||
character_id, static_cast<LandType::Value>(character_type),
|
||||
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_type = land_type;
|
||||
}
|
||||
|
||||
void MapObject::setTerrain( uint16_t id, uint8_t land_type ) {
|
||||
setTerrain( id, static_cast< LandType::Value >( land_type ) );
|
||||
void MapObject::setTerrain(uint16_t id, uint8_t 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_type = land_type;
|
||||
if(hasModifier()) {
|
||||
if (hasModifier()) {
|
||||
modifier_id = 0;
|
||||
modifier_data = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void MapObject::setCharacter( uint8_t id, uint8_t land_type ) {
|
||||
setCharacter( id, static_cast< LandType::Value >( land_type ) );
|
||||
void MapObject::setCharacter(uint8_t id, uint8_t 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_data = data;
|
||||
if(hasCharacter()) {
|
||||
if (hasCharacter()) {
|
||||
character_id = 0;
|
||||
character_type = LandType::OVERWORLD;
|
||||
}
|
||||
@ -54,14 +53,14 @@ void MapObject::unsetTerrain() {
|
||||
}
|
||||
|
||||
void MapObject::unsetModifier() {
|
||||
if ( hasModifier() ) {
|
||||
setModifier( 0, 0 );
|
||||
if (hasModifier()) {
|
||||
setModifier(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void MapObject::unsetCharacter() {
|
||||
if ( hasCharacter() ) {
|
||||
setCharacter( 0, 0 );
|
||||
if (hasCharacter()) {
|
||||
setCharacter(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,17 +6,17 @@
|
||||
class MapObject {
|
||||
public:
|
||||
MapObject() = default;
|
||||
MapObject( uint16_t terrain_id, uint8_t terrain_type, uint8_t character_id,
|
||||
uint8_t character_type, uint32_t modifier_id,
|
||||
uint8_t modifier_data );
|
||||
MapObject( uint16_t terrain_id, LandType::Value terrain_type,
|
||||
uint8_t character_id, LandType::Value character_type,
|
||||
uint32_t modifier_id, uint8_t modifier_data );
|
||||
void setTerrain( uint16_t id, LandType::Value 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, uint8_t land_type );
|
||||
void setModifier( uint32_t id, uint8_t data );
|
||||
MapObject(uint16_t terrain_id, uint8_t terrain_type, uint8_t character_id,
|
||||
uint8_t character_type, uint32_t modifier_id,
|
||||
uint8_t modifier_data);
|
||||
MapObject(uint16_t terrain_id, LandType::Value terrain_type,
|
||||
uint8_t character_id, LandType::Value character_type,
|
||||
uint32_t modifier_id, uint8_t modifier_data);
|
||||
void setTerrain(uint16_t id, LandType::Value 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, uint8_t land_type);
|
||||
void setModifier(uint32_t id, uint8_t data);
|
||||
void unsetTerrain();
|
||||
void unsetModifier();
|
||||
void unsetCharacter();
|
||||
|
122
mario/mario.cpp
122
mario/mario.cpp
@ -4,40 +4,40 @@
|
||||
#include "sprites.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) {
|
||||
setAnimationFrames( MARIO_WALK_ANIM );
|
||||
setId( MARIO_ID );
|
||||
setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||
setAnimationSpeed( 12.5 );
|
||||
Mario::Mario(int x, int y, const std::shared_ptr<SDLPP::Renderer> &renderer)
|
||||
: MarioBlock(x, y, renderer, g_mario_texture, MARIO_STANDING_SRC) {
|
||||
setAnimationFrames(MARIO_WALK_ANIM);
|
||||
setId(MARIO_ID);
|
||||
setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
|
||||
setAnimationSpeed(12.5);
|
||||
pauseAnimation();
|
||||
setMovement( 0, 0 );
|
||||
setMovementSpeed( 1 );
|
||||
auto bottom_detect = SDLPP::RectColider( 0.2, 1, 0.6, 0, MARIO_FLOOR_DETECT );
|
||||
setMovement(0, 0);
|
||||
setMovementSpeed(1);
|
||||
auto bottom_detect = SDLPP::RectColider(0.2, 1, 0.6, 0, MARIO_FLOOR_DETECT);
|
||||
bottom_detect.setColor("#FF0000");
|
||||
bottom_detect.setOutlineColor("#FF0000");
|
||||
bottom_detect.setMinHeight(1);
|
||||
addCollision(bottom_detect);
|
||||
addCollision(SDLPP::RectColider(0, 0.25, 0.1, 0.6, MARIO_LEFT_SIDE_DETECT));
|
||||
addCollision(
|
||||
SDLPP::RectColider( 0, 0.25, 0.1, 0.6, MARIO_LEFT_SIDE_DETECT ) );
|
||||
addCollision(
|
||||
SDLPP::RectColider( 0.9, 0.25, 0.1, 0.6, MARIO_RIGHT_SIDE_DETECT ) );
|
||||
addCollision(
|
||||
SDLPP::RectColider( 0, 0, 0.1, 0.1, MARIO_TOP_LEFT_DETECT ) );
|
||||
addCollision(
|
||||
SDLPP::RectColider( 0.9, 0, 0.1, 0.1, MARIO_TOP_LEFT_DETECT ) );
|
||||
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 ) );
|
||||
SDLPP::RectColider(0.9, 0.25, 0.1, 0.6, MARIO_RIGHT_SIDE_DETECT));
|
||||
addCollision(SDLPP::RectColider(0, 0, 0.1, 0.1, MARIO_TOP_LEFT_DETECT));
|
||||
addCollision(SDLPP::RectColider(0.9, 0, 0.1, 0.1, MARIO_TOP_LEFT_DETECT));
|
||||
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");
|
||||
setStatic( false );
|
||||
setStatic(false);
|
||||
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() {
|
||||
if(on_ground)
|
||||
if (on_ground)
|
||||
resumeAnimation();
|
||||
addMovement( -side_movement, 0 );
|
||||
if ( getMovement().getX() < 0 && faces_right ) {
|
||||
addMovement(-side_movement, 0);
|
||||
if (getMovement().getX() < 0 && faces_right) {
|
||||
flipHorizontally();
|
||||
top_collision->setPos(0.3, 0);
|
||||
updateSizeAndPosition();
|
||||
@ -46,10 +46,10 @@ void Mario::walkLeft() {
|
||||
}
|
||||
|
||||
void Mario::walkRight() {
|
||||
if(on_ground)
|
||||
if (on_ground)
|
||||
resumeAnimation();
|
||||
addMovement( side_movement, 0 );
|
||||
if ( getMovement().getX() > 0 && !faces_right ) {
|
||||
addMovement(side_movement, 0);
|
||||
if (getMovement().getX() > 0 && !faces_right) {
|
||||
flipHorizontally();
|
||||
top_collision->setPos(0.5, 0);
|
||||
updateSizeAndPosition();
|
||||
@ -58,70 +58,80 @@ void Mario::walkRight() {
|
||||
}
|
||||
|
||||
void Mario::setStanding() {
|
||||
if ( getMovement().getX() == 0 ) {
|
||||
if (getMovement().getX() == 0) {
|
||||
pauseAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
void Mario::handleVisitor(SDLPP::Visitor &visitor) {
|
||||
#ifndef EDITOR
|
||||
// TODO - https://web.archive.org/web/20130807122227/http://i276.photobucket.com/albums/kk21/jdaster64/smb_playerphysics.png
|
||||
auto &m_visitor = dynamic_cast<MarioVisitor&>(visitor);
|
||||
// TODO -
|
||||
// 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
|
||||
on_ground = m_visitor.isOnGround();
|
||||
if(!jumping && on_ground) {
|
||||
if (!jumping && on_ground) {
|
||||
resetMovementY();
|
||||
setBaseRect(MARIO_STANDING_SRC);
|
||||
if(getMovement().getX() != 0)
|
||||
if (getMovement().getX() != 0)
|
||||
resumeAnimation();
|
||||
// for some reason falling of the edge causes on_ground to be true, but
|
||||
// visitor ground_y is 0
|
||||
if(m_visitor.getGroundY() != 0) {
|
||||
if (m_visitor.getGroundY() != 0) {
|
||||
setPos(getPos().getX(), m_visitor.getGroundY() - BLOCK_SIZE);
|
||||
}
|
||||
}
|
||||
// if we just left ground gravity didn't work in custom_move
|
||||
if(!on_ground && !jumping && getMovement().getY() == 0) {
|
||||
addMovement(0, 2*gravity_add_falling);
|
||||
if (!on_ground && !jumping && getMovement().getY() == 0) {
|
||||
addMovement(0, 2 * gravity_add_falling);
|
||||
}
|
||||
if(m_visitor.topBlock() && getMovement().getY() < 0) {
|
||||
if (m_visitor.topBlock() && getMovement().getY() < 0) {
|
||||
resetMovementY();
|
||||
stop_jump = true;
|
||||
}
|
||||
if(m_visitor.shouldBounce()) {
|
||||
if (m_visitor.shouldBounce()) {
|
||||
addMovement(0, -bounce_speed);
|
||||
}
|
||||
// make sure Mario isn't stuck inside a wall
|
||||
// TODO more readable function names
|
||||
if ( m_visitor.isStopped() ) {
|
||||
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) ) {
|
||||
// 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() };
|
||||
if (m_visitor.isStopped()) {
|
||||
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)) {
|
||||
// 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);
|
||||
} else if (m_visitor.moveTop() && jumping && !stop_jump) {
|
||||
auto objPos = m_visitor.getRightLeftPos();
|
||||
if(objPos.getX() < getPos().getX()) {
|
||||
setPos( objPos.getX() + BLOCK_SIZE, getPos().getY() );
|
||||
if (objPos.getX() < getPos().getX()) {
|
||||
setPos(objPos.getX() + BLOCK_SIZE, getPos().getY());
|
||||
} 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);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Mario::jump() {
|
||||
if(!on_ground)
|
||||
if (!on_ground)
|
||||
return;
|
||||
jumping = true;
|
||||
stop_jump = false;
|
||||
max_jump = getPos().getY() - 3*BLOCK_SIZE;
|
||||
min_jump = getPos().getY() - 1*BLOCK_SIZE;
|
||||
slow_jump = getPos().getY() - 2*BLOCK_SIZE;
|
||||
addMovement( 0, -jump_movement );
|
||||
max_jump = getPos().getY() - 3 * BLOCK_SIZE;
|
||||
min_jump = getPos().getY() - 1 * BLOCK_SIZE;
|
||||
slow_jump = getPos().getY() - 2 * BLOCK_SIZE;
|
||||
addMovement(0, -jump_movement);
|
||||
ticks_till_gravity = base_gravity_ticks;
|
||||
setBaseRect(MARIO_JUMP_SRC);
|
||||
pauseAnimation();
|
||||
@ -131,19 +141,19 @@ void Mario::stopJump() {
|
||||
stop_jump = true;
|
||||
}
|
||||
|
||||
void Mario::custom_move( int ticks ) {
|
||||
void Mario::custom_move(int ticks) {
|
||||
MarioBlock::custom_move(ticks);
|
||||
if(!jumping && on_ground)
|
||||
if (!jumping && on_ground)
|
||||
return;
|
||||
if(getMovement().getY() >= 1.0625 * jump_movement)
|
||||
if (getMovement().getY() >= 1.0625 * jump_movement)
|
||||
return;
|
||||
ticks_till_gravity -= ticks;
|
||||
if(ticks_till_gravity < 0) {
|
||||
if(getMovement().getY() > 0) {
|
||||
if (ticks_till_gravity < 0) {
|
||||
if (getMovement().getY() > 0) {
|
||||
jumping = false;
|
||||
addMovement(0, gravity_add_jumping);
|
||||
} else {
|
||||
if(stop_jump) {
|
||||
if (stop_jump) {
|
||||
addMovement(0, gravity_add_falling);
|
||||
} else {
|
||||
addMovement(0, gravity_add_jumping);
|
||||
|
@ -7,16 +7,16 @@
|
||||
|
||||
class Mario : public MarioBlock {
|
||||
public:
|
||||
Mario( int x, int y, const std::shared_ptr< SDLPP::Renderer > &renderer );
|
||||
Mario( 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);
|
||||
void walkLeft();
|
||||
void walkRight();
|
||||
void setStanding();
|
||||
void handleVisitor( SDLPP::Visitor &visitor ) override;
|
||||
void handleVisitor(SDLPP::Visitor &visitor) override;
|
||||
void jump();
|
||||
void stopJump();
|
||||
void custom_move( int ticks ) override;
|
||||
void visit( SDLPP::Visitor &visitor ) override;
|
||||
void custom_move(int ticks) override;
|
||||
void visit(SDLPP::Visitor &visitor) override;
|
||||
|
||||
private:
|
||||
bool faces_right = true;
|
||||
@ -32,9 +32,9 @@ private:
|
||||
// gravity should be added every frame in 60fps game
|
||||
const int base_gravity_ticks = 1000 / 60;
|
||||
const double gravity_add_jumping = jump_movement / 32.0;
|
||||
const double gravity_add_falling = jump_movement / ( 64.0 / 7.0 );
|
||||
std::shared_ptr< SDLPP::RectColider > top_collision = nullptr;
|
||||
void setWorldTypeSrc( LandType::Value world ) override;
|
||||
const double gravity_add_falling = jump_movement / (64.0 / 7.0);
|
||||
std::shared_ptr<SDLPP::RectColider> top_collision = nullptr;
|
||||
void setWorldTypeSrc(LandType::Value world) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -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_DEATH_SRC = { 22, 9, 16, 16 };
|
||||
const std::vector< SDL_Rect > MARIO_WALK_ANIM = { { 43, 9, 16, 16 },
|
||||
{ 60, 9, 16, 16 },
|
||||
{ 77, 9, 16, 16 } };
|
||||
const std::vector<SDL_Rect> MARIO_WALK_ANIM = { { 43, 9, 16, 16 },
|
||||
{ 60, 9, 16, 16 },
|
||||
{ 77, 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_STANDING_BIG_SRC = { 1, 26, 16, 32 };
|
||||
const SDL_Rect MARIO_DEATH_BIG_SRC = { 22, 26, 16, 32 };
|
||||
const std::vector< SDL_Rect > MARIO_WALK_BIG_ANIM = {
|
||||
{ 43, 26, 16, 32 }, { 60, 9, 16, 32 }, { 77, 9, 16, 32 }
|
||||
};
|
||||
const std::vector<SDL_Rect> MARIO_WALK_BIG_ANIM = { { 43, 26, 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_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_LEFT_SRC = { 188, 97, 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_MIDDLE_SRC = {239,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_MIDDLE_BOTTOM_SRC = {239,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_MIDDLE_TOP_SRC = {239,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_TOP_SRC = {103, 46, 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 CASTLE_LEFT_SRC = {69, 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_ENTRY_SRC = {86, 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 VINE_TOP_SRC = {69, 29, 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_BOTTOM_SRC = {86, 46, 16, 16};
|
||||
const SDL_Rect FLAG_SRC = {137, 46, 16, 16};
|
||||
const SDL_Rect STEP_SRC = {86, 63, 16, 16};
|
||||
const SDL_Rect BRICK_SRC = {35, 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_BOTTOM_SRC = {69, 97, 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_CONNECTOR_TOP_SRC = {103, 80, 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_MIDDLE_SRC = {154, 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 WATER_TOP_SRC = {171, 29, 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_MIDDLE_SRC = {205, 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_BOTTOM_SRC = {205, 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_TOP_SRC = {239, 12, 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_PEDESTAL_SRC = {256, 29, 16, 16};
|
||||
const SDL_Rect CANNON_SRC = {256, 12, 16, 16};
|
||||
const SDL_Rect COIN_SRC = {549, 202, 16, 16};
|
||||
const SDL_Rect MUSHROOM_SRC = {69, 12, 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_RIGHT_SRC = { 256, 97, 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_RIGHT_BOTTOM_SRC = { 256, 80, 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_RIGHT_TOP_SRC = { 256, 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_RIGHT_BOTTOM_SRC = { 120, 63, 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_RIGHT_SRC = { 103, 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_TOWER_SRC = { 69, 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_BOTTOM_SRC = { 69, 46, 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 FLAG_SRC = { 137, 46, 16, 16 };
|
||||
const SDL_Rect STEP_SRC = { 86, 63, 16, 16 };
|
||||
const SDL_Rect BRICK_SRC = { 35, 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_BOTTOM_SRC = { 69, 97, 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_CONNECTOR_TOP_SRC = { 103, 80, 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_MIDDLE_SRC = { 154, 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 WATER_TOP_SRC = { 171, 29, 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_MIDDLE_SRC = { 205, 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_BOTTOM_SRC = { 205, 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_TOP_SRC = { 239, 12, 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_PEDESTAL_SRC = { 256, 29, 16, 16 };
|
||||
const SDL_Rect CANNON_SRC = { 256, 12, 16, 16 };
|
||||
const SDL_Rect COIN_SRC = { 549, 202, 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_BACKGROUND_SRC = {16, 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_DESTRUCTIBLE_SRC = { 0, 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_MUSHROOM_SRC = { 48, 0, 16, 16 };
|
||||
|
||||
const SDLPP::Vec2D<uint64_t> OVERWORLD_SHIFT = {0, 0};
|
||||
const SDLPP::Vec2D<uint64_t> UNDERWORLD_SHIFT = {274, 0};
|
||||
const SDLPP::Vec2D<uint64_t> WATER_SHIFT = {548, 0};
|
||||
const SDLPP::Vec2D<uint64_t> BOWSER_SHIFT = {0, 173};
|
||||
const SDLPP::Vec2D<uint64_t> OVERWORLD_SHIFT = { 0, 0 };
|
||||
const SDLPP::Vec2D<uint64_t> UNDERWORLD_SHIFT = { 274, 0 };
|
||||
const SDLPP::Vec2D<uint64_t> WATER_SHIFT = { 548, 0 };
|
||||
const SDLPP::Vec2D<uint64_t> BOWSER_SHIFT = { 0, 173 };
|
||||
|
||||
const std::vector< SDL_Rect > GOOMBA_WALK_ANIM = { { 1, 28, 16, 16 },
|
||||
{ 18, 28, 16, 16 } };
|
||||
const SDL_Rect GOOMBA_DEATH_SRC = {39, 28, 16, 16};
|
||||
const std::vector<SDL_Rect> GOOMBA_WALK_ANIM = { { 1, 28, 16, 16 },
|
||||
{ 18, 28, 16, 16 } };
|
||||
const SDL_Rect GOOMBA_DEATH_SRC = { 39, 28, 16, 16 };
|
||||
|
@ -3,7 +3,11 @@
|
||||
#include "blocks.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;
|
||||
_y = y;
|
||||
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");
|
||||
setPermanent();
|
||||
setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
|
||||
if(coliders)
|
||||
addCollision(SDLPP::RectColider(0,0,1,1));
|
||||
if (coliders)
|
||||
addCollision(SDLPP::RectColider(0, 0, 1, 1));
|
||||
}
|
||||
|
||||
SDLPP::Vec2D<int> ToolBox::getIndexes() const {
|
||||
return {_x, _y};
|
||||
return { _x, _y };
|
||||
}
|
||||
|
||||
void ToolBox::visit( SDLPP::Visitor &visitor ) {
|
||||
visitor.visit( *this );
|
||||
void ToolBox::visit(SDLPP::Visitor &visitor) {
|
||||
visitor.visit(*this);
|
||||
}
|
||||
|
@ -5,15 +5,17 @@
|
||||
|
||||
class ToolBox : public SDLPP::RectangleRender {
|
||||
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 void visit( SDLPP::Visitor &visitor ) override;
|
||||
virtual void visit(SDLPP::Visitor &visitor) override;
|
||||
uint64_t getType() const {
|
||||
return _type;
|
||||
}
|
||||
void setType(uint64_t type) {
|
||||
_type = type;
|
||||
}
|
||||
|
||||
private:
|
||||
int _x;
|
||||
int _y;
|
||||
|
Loading…
Reference in New Issue
Block a user