git repos / saland

commit cc814c0e

sago007 · 2020-07-20 17:53
cc814c0e7397878dfe239b90c954ab3efdf7bb8d patch · browse files
parent 28ff111f3d4678b34833a86f6ed1c2a453d4c909

Now draws 10 slots in the top. Increased the outher border to make room for the slots.

Changed files

M src/sagotmx/tmx_struct.h before
M src/saland/Game.cpp before
M src/saland/GameDraw.cpp before
diff --git a/src/sagotmx/tmx_struct.h b/src/sagotmx/tmx_struct.h index af9d352..4401f99 100644 --- a/src/sagotmx/tmx_struct.h +++ b/src/sagotmx/tmx_struct.h
@@ -625,8 +625,9 @@ inline bool tileInBound(const TileMap& tm, int x, int y) {
inline uint32_t getTileFromLayer(const TileMap& m, const TileLayer& l, int x, int y) {
size_t tile_index = (m.height*y+x)*sizeof(uint32_t);
if (tile_index > l.data.payload.size()-sizeof(uint32_t) ) {
- throw SagoTiledException("ERROR: getTileFromLayer called with coordinates out-of-bound. Called with (%d, %d). Limit (%d, %d). Or the layer is corrupt. "
- "Reported number of tiles in layer: %ld", x, y, m.width-1, m.height-1, (long int)l.data.payload.size()/sizeof(uint32_t));
+ return 0;
+ /*throw SagoTiledException("ERROR: getTileFromLayer called with coordinates out-of-bound. Called with (%d, %d). Limit (%d, %d). Or the layer is corrupt. "
+ "Reported number of tiles in layer: %ld", x, y, m.width-1, m.height-1, (long int)l.data.payload.size()/sizeof(uint32_t));*/
}
const unsigned char *data = reinterpret_cast<const unsigned char*>(l.data.payload.data());
uint32_t global_tile_id = data[tile_index] |
diff --git a/src/saland/Game.cpp b/src/saland/Game.cpp index 818f48a..9d06004 100644 --- a/src/saland/Game.cpp +++ b/src/saland/Game.cpp
@@ -275,7 +275,7 @@ static std::string GetLayerInfoForTile(const World& w, int x, int y) {
void Game::Draw(SDL_Renderer* target) {
double screen_width = globalData.xsize;
double screen_height = globalData.ysize;
- int screen_boarder = 16;
+ int screen_boarder = 64;
data->topx = std::round(data->center_x - screen_width / 2.0);
data->topy = std::round(data->center_y - screen_height / 2.0);
if (data->topx < -screen_boarder) {
@@ -301,11 +301,12 @@ void Game::Draw(SDL_Renderer* target) {
for (size_t i = 0; i < data->gameRegion.world.tm.object_groups.size(); ++i) {
DrawOjbectGroup(target, data->gameRegion.world.tm, i, data->topx, data->topy);
}
- int mousebox_x = data->world_mouse_x - data->world_mouse_x % 32 - data->topx;
- int mousebox_y = data->world_mouse_y - data->world_mouse_y % 32 - data->topy;
- rectangleRGBA(globalData.screen, mousebox_x, mousebox_y,
- mousebox_x + 32, mousebox_y + 32, 255, 255, 0, 255);
-
+ if (data->world_mouse_x >= 0 && data->world_mouse_y >= 0) {
+ int mousebox_x = data->world_mouse_x - data->world_mouse_x % 32 - data->topx;
+ int mousebox_y = data->world_mouse_y - data->world_mouse_y % 32 - data->topy;
+ rectangleRGBA(globalData.screen, mousebox_x, mousebox_y,
+ mousebox_x + 32, mousebox_y + 32, 255, 255, 0, 255);
+ }
//Draw
for (const auto& p : data->gameRegion.placeables) {
MiscItem* m = dynamic_cast<MiscItem*> (p.get());
@@ -330,16 +331,24 @@ void Game::Draw(SDL_Renderer* target) {
DrawLayer(target, globalData.spriteHolder.get(), data->gameRegion.world.tm, i, data->topx, data->topy);
}
}
- char buffer[200];
- snprintf(buffer, sizeof(buffer), "world_x = %d, world_y = %d, layer_info:%s",
- data->world_mouse_x/32, data->world_mouse_y/32,
- GetLayerInfoForTile(data->gameRegion.world, data->world_mouse_x/32, data->world_mouse_y/32).c_str()
- );
- data->bottomField.SetText(buffer);
+ if (data->world_mouse_x >= 0 && data->world_mouse_y >= 0) {
+ char buffer[200];
+ snprintf(buffer, sizeof(buffer), "world_x = %d, world_y = %d, layer_info:%s",
+ data->world_mouse_x/32, data->world_mouse_y/32,
+ GetLayerInfoForTile(data->gameRegion.world, data->world_mouse_x/32, data->world_mouse_y/32).c_str()
+ );
+ data->bottomField.SetText(buffer);
+ }
+ else {
+ data->bottomField.SetText("outside world");
+ }
data->bottomField.Draw(target, 2, screen_height, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::bottom);
data->middleField.Draw(target, screen_width/2, screen_height/4, sago::SagoTextField::Alignment::center, sago::SagoTextField::VerticalAlignment::bottom);
DrawRectYellow(target, screen_width-70, screen_height-70, 52, 52);
DrawTile(target, globalData.spriteHolder.get(), data->gameRegion.world.tm, data->drawTile, screen_width-60, screen_height-60);
+ for (int i = 0; i < 10; ++i) {
+ DrawRectYellow(target, 10+i*56, 10, 52, 52);
+ }
if (data->consoleActive && data->console) {
data->console->Draw(target);
}
diff --git a/src/saland/GameDraw.cpp b/src/saland/GameDraw.cpp index a896ffe..1bd5791 100644 --- a/src/saland/GameDraw.cpp +++ b/src/saland/GameDraw.cpp
@@ -74,8 +74,22 @@ void DrawTile(SDL_Renderer* renderer, sago::SagoSpriteHolder* sHolder, const sag
}
void DrawLayer(SDL_Renderer* renderer, sago::SagoSpriteHolder* sHolder, const sago::tiled::TileMap& tm, size_t layer, int topx, int topy) {
- for (int i = topx/32; i < tm.width && i < (topx+globalData.xsize)/32+1; ++i) {
- for (int j = topy/32; j < tm.height && j < (topy+globalData.ysize)/32+1; ++j) {
+ int startX = topx/32;
+ int startY = topy/32;
+ if (startX < 0) {
+ startX = 0;
+ }
+ if (startY < 0) {
+ startY = 0;
+ }
+ for (int i = startX; i < tm.width && i < (topx+globalData.xsize)/32+1; ++i) {
+ /*if (i < 0) {
+ continue;
+ }*/
+ for (int j = startY; j < tm.height && j < (topy+globalData.ysize)/32+1; ++j) {
+ /*if (j < 0) {
+ continue;
+ }*/
uint32_t gid = sago::tiled::getTileFromLayer(tm, tm.layers.at(layer), i, j);
if (gid == 0) {
continue;