Mario: use object alignment
This commit is contained in:
parent
e5d0610f6d
commit
7c38e122d0
@ -10,15 +10,15 @@ createBlock( std::shared_ptr< SDLPP::Renderer > &renderer, double x, double y,
|
||||
auto block = std::make_shared< SDLPP::RectangleRender >(
|
||||
x, y, BLOCK_SIZE, BLOCK_SIZE, renderer, texture, src );
|
||||
block->setId( id );
|
||||
block->centerX();
|
||||
block->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||
block->setStatic();
|
||||
if ( collision )
|
||||
block->addCollision( SDLPP::RectColider( 0, 0, 1, 1 ) );
|
||||
return block;
|
||||
}
|
||||
|
||||
SDL_Rect getSourceRectByID(uint64_t id) {
|
||||
switch(id) {
|
||||
SDL_Rect getSourceRectByID( uint64_t id ) {
|
||||
switch ( id ) {
|
||||
case FLOOR_OVERWORLD_ID:
|
||||
return FLOOR_OVERWORLD_SRC;
|
||||
case HILL_OVERWORLD_INCLINE_ID:
|
||||
@ -55,10 +55,17 @@ SDL_Rect getSourceRectByID(uint64_t id) {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::shared_ptr<SDLPP::RectangleRender> createTerrainBlock( uint64_t block_id, std::shared_ptr<SDLPP::Renderer> &renderer, double x, double y, bool collision ) {
|
||||
return createBlock(renderer, x, y, g_terrain_texture, getSourceRectByID(block_id), block_id, collision);
|
||||
std::shared_ptr< SDLPP::RectangleRender >
|
||||
createTerrainBlock( uint64_t block_id,
|
||||
std::shared_ptr< SDLPP::Renderer > &renderer, double x,
|
||||
double y, bool collision ) {
|
||||
return createBlock( renderer, x, y, g_terrain_texture,
|
||||
getSourceRectByID( block_id ), block_id, collision );
|
||||
}
|
||||
|
||||
std::shared_ptr<SDLPP::RectangleRender> createTerrainBlock( uint64_t block_id, std::shared_ptr<SDLPP::Renderer> &renderer, bool collision ) {
|
||||
return createTerrainBlock(block_id, renderer, 0, 0, collision);
|
||||
std::shared_ptr< SDLPP::RectangleRender >
|
||||
createTerrainBlock( uint64_t block_id,
|
||||
std::shared_ptr< SDLPP::Renderer > &renderer,
|
||||
bool collision ) {
|
||||
return createTerrainBlock( block_id, renderer, 0, 0, collision );
|
||||
}
|
||||
|
@ -93,15 +93,10 @@ void pollEvents( SDLPP::Scene &scene ) {
|
||||
scene.updateSizeAndPosition();
|
||||
if ( leftStop ) {
|
||||
auto rendDimsInt = renderer->getDimensions();
|
||||
std::cout << "RENDER DIMENSIONS: " << rendDimsInt.getX()
|
||||
<< ", " << rendDimsInt.getY() << std::endl;
|
||||
auto rendDims = renderer->getDoubleDimensions();
|
||||
std::cout << "RENDER DIMENSIONS: " << rendDims.getX()
|
||||
<< ", " << rendDims.getY() << std::endl;
|
||||
auto left = rendDims.getX() < 2.0
|
||||
? -( rendDims.getX() - 1 ) / 2.0 - 0.1
|
||||
: -0.5;
|
||||
std::cout << left << std::endl;
|
||||
leftStop->setPos( left, 0 );
|
||||
}
|
||||
auto dimensions = renderer->getDoubleDimensions();
|
||||
@ -193,7 +188,7 @@ int main() {
|
||||
MARIO_OVERWORLD_STANDING_SRC );
|
||||
mario->setAnimationFrames( MARIO_OVERWORLD_WALK_ANIM );
|
||||
mario->setId( 2 );
|
||||
mario->centerX();
|
||||
mario->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||
mario->setAnimationSpeed( 12.5 );
|
||||
mario->pauseAnimation();
|
||||
mario->setMovement( 0, 0 );
|
||||
@ -210,7 +205,7 @@ int main() {
|
||||
auto defeat =
|
||||
std::make_shared< SDLPP::RectangleRender >( 0, 1.01, 0, 0, renderer );
|
||||
defeat->setId( DEATH_ID );
|
||||
defeat->centerX();
|
||||
defeat->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||
defeat->setPermanent();
|
||||
auto defeatCol = SDLPP::RectColider( -1, 0, -1, -1 );
|
||||
defeatCol.setInfinite();
|
||||
@ -221,7 +216,7 @@ int main() {
|
||||
leftStop = std::make_shared< SDLPP::RectangleRender >( -0.1, 0, 0.11, 0,
|
||||
renderer );
|
||||
leftStop->setId( STOP_MOVEMENT );
|
||||
leftStop->centerX();
|
||||
leftStop->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||
leftStop->setPermanent();
|
||||
auto leftStopCol = SDLPP::RectColider( 0, -1, 1, -1 );
|
||||
leftStopCol.setInfinite();
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
void MarioVisitor::visit( const SDLPP::RenderObject &obj ) {
|
||||
auto id = obj.getId();
|
||||
std::cout << from << std::endl;
|
||||
switch ( id ) {
|
||||
case FLOOR_OVERWORLD_ID:
|
||||
if ( from == MARIO_FLOOR_DETECT )
|
||||
|
Loading…
Reference in New Issue
Block a user