66 lines
2.6 KiB
C++
66 lines
2.6 KiB
C++
|
#include "blocks.hpp"
|
||
|
#include "global_vars.hpp"
|
||
|
#include "objectids.hpp"
|
||
|
#include "sprites.hpp"
|
||
|
#include <bits/stdint-uintn.h>
|
||
|
|
||
|
std::shared_ptr< SDLPP::RectangleRender >
|
||
|
createBlock( std::shared_ptr< SDLPP::Renderer > &renderer, double x, double y,
|
||
|
std::shared_ptr< SDLPP::Texture > &texture, const SDL_Rect &src,
|
||
|
uint64_t id, bool collision = false ) {
|
||
|
auto block = std::make_shared< SDLPP::RectangleRender >(
|
||
|
x, y, BLOCK_SIZE, BLOCK_SIZE, renderer, texture, src );
|
||
|
block->setId( id );
|
||
|
block->centerX();
|
||
|
block->setStatic();
|
||
|
if ( collision )
|
||
|
block->addCollision( SDLPP::RectColider( 0, 0, 1, 1 ) );
|
||
|
return block;
|
||
|
}
|
||
|
|
||
|
SDL_Rect getSourceRectByID(uint64_t id) {
|
||
|
switch(id) {
|
||
|
case FLOOR_OVERWORLD_ID:
|
||
|
return FLOOR_OVERWORLD_SRC;
|
||
|
case HILL_OVERWORLD_INCLINE_ID:
|
||
|
return HILL_OVERWORLD_INCLINE_SRC;
|
||
|
case HILL_OVERWORLD_DECLINE_ID:
|
||
|
return HILL_OVERWORLD_DECLINE_SRC;
|
||
|
case HILL_OVERWORLD_DOTS_RIGHT_ID:
|
||
|
return HILL_OVERWORLD_DOTS_RIGHT_SRC;
|
||
|
case HILL_OVERWORLD_DOTS_LEFT_ID:
|
||
|
return HILL_OVERWORLD_DOTS_LEFT_SRC;
|
||
|
case HILL_OVERWORLD_FILL_ID:
|
||
|
return HILL_OVERWORLD_FILL_SRC;
|
||
|
case HILL_OVERWORLD_TOP_ID:
|
||
|
return HILL_OVERWORLD_TOP_SRC;
|
||
|
case BUSH_OVERWORLD_LEFT_ID:
|
||
|
return BUSH_OVERWORLD_LEFT_SRC;
|
||
|
case BUSH_OVERWORLD_MIDDLE_ID:
|
||
|
return BUSH_OVERWORLD_MIDDLE_SRC;
|
||
|
case BUSH_OVERWORLD_RIGHT_ID:
|
||
|
return BUSH_OVERWORLD_RIGHT_SRC;
|
||
|
case CLOUD_OVERWORLD_LEFT_BOTTOM_ID:
|
||
|
return CLOUD_OVERWORLD_LEFT_BOTTOM_SRC;
|
||
|
case CLOUD_OVERWORLD_MIDDLE_BOTTOM_ID:
|
||
|
return CLOUD_OVERWORLD_MIDDLE_BOTTOM_SRC;
|
||
|
case CLOUD_OVERWORLD_RIGHT_BOTTOM_ID:
|
||
|
return CLOUD_OVERWORLD_RIGHT_BOTTOM_SRC;
|
||
|
case CLOUD_OVERWORLD_LEFT_TOP_ID:
|
||
|
return CLOUD_OVERWORLD_LEFT_TOP_SRC;
|
||
|
case CLOUD_OVERWORLD_MIDDLE_TOP_ID:
|
||
|
return CLOUD_OVERWORLD_MIDDLE_TOP_SRC;
|
||
|
case CLOUD_OVERWORLD_RIGHT_TOP_ID:
|
||
|
return CLOUD_OVERWORLD_RIGHT_TOP_SRC;
|
||
|
}
|
||
|
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, bool collision ) {
|
||
|
return createTerrainBlock(block_id, renderer, 0, 0, collision);
|
||
|
}
|