git repos / saland

commit a2b3ade8

Poul Sander · 2019-04-14 15:59
a2b3ade8f49232d88e025993843e174b392140d4 patch · browse files
parent 2826127dbd2c3eb61a12dabc22f5ecc459957a69

Tile to draw can now be swithed with Page up and page down

Changed files

M src/saland/Game.cpp before
M src/saland/GameDraw.cpp before
M src/saland/GameDraw.hpp before
diff --git a/src/saland/Game.cpp b/src/saland/Game.cpp index 3a3f32a..aa855b5 100644 --- a/src/saland/Game.cpp +++ b/src/saland/Game.cpp
@@ -78,6 +78,7 @@ struct Game::GameImpl {
int world_mouse_y = 0;
char direction = 0;
Uint32 lastUpdate = 0;
+ uint32_t drawTile = 607;
bool isActive = true;
std::string worldName = "world1";
sago::SagoTextField bottomField;
@@ -218,6 +219,7 @@ void Game::Draw(SDL_Renderer* target) {
);
data->bottomField.SetText(buffer);
data->bottomField.Draw(target, 2, screen_height, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::bottom);
+ DrawTile(target, globalData.spriteHolder.get(), data->gameRegion.world.tm, data->drawTile, 1024-60, 768-60);
if (data->console) {
data->console->Draw(target);
}
@@ -242,7 +244,7 @@ void Game::Draw(SDL_Renderer* target) {
}
static bool reservedField(const sago::tiled::TileMap& tm, int x, int y) {
- if (x < 2 && y > tm.layers.at(0).height/2-6 && y < tm.layers.at(0).height/2+5) {
+ if (x < 2 && y > tm.layers.at(6070).height/2-6 && y < tm.layers.at(0).height/2+5) {
return true;
}
if (x > tm.layers.at(0).width-3 && y > tm.layers.at(0).height/2-6 && y < tm.layers.at(0).height/2+5) {
@@ -271,7 +273,7 @@ void Game::ProcessInput(const SDL_Event& event, bool& processed) {
&& sago::tiled::tileInBound(data->gameRegion.world.tm, tile_x, tile_y)
&& !reservedField(data->gameRegion.world.tm, tile_x, tile_y)) {
int layer_number = 2; // Do not hardcode
- uint32_t tile = 607;
+ uint32_t tile = data->drawTile;
sago::tiled::setTileOnLayerNumber(data->gameRegion.world.tm, layer_number, tile_x, tile_y, tile);
data->gameRegion.world.init_physics(data->gameRegion.physicsBox);
}
@@ -282,6 +284,12 @@ void Game::ProcessInput(const SDL_Event& event, bool& processed) {
sago::tiled::setTileOnLayerNumber(data->gameRegion.world.tm, layer_number, tile_x, tile_y, tile);
data->gameRegion.world.init_physics(data->gameRegion.physicsBox);
}
+ if (event.key.keysym.sym == SDLK_PAGEDOWN) {
+ data->drawTile--;
+ }
+ if (event.key.keysym.sym == SDLK_PAGEUP) {
+ data->drawTile++;
+ }
if (event.key.keysym.sym == SDLK_ESCAPE && event.key.keysym.mod & KMOD_LSHIFT) {
data->console = std::make_shared<Console>();
}
diff --git a/src/saland/GameDraw.cpp b/src/saland/GameDraw.cpp index 83b5e69..483c4d2 100644 --- a/src/saland/GameDraw.cpp +++ b/src/saland/GameDraw.cpp
@@ -54,6 +54,16 @@ void DrawOuterBorder(SDL_Renderer* renderer, SDL_Texture* texture, const sago::t
}
}
+void DrawTile(SDL_Renderer* renderer, sago::SagoSpriteHolder* sHolder, const sago::tiled::TileMap& tm, uint32_t gid, int x, int y) {
+ SDL_Rect part{};
+ std::string imageFile;
+ getTextureLocationFromGid(tm, gid, &imageFile, &part.x, &part.y, &part.w, &part.h);
+ imageFile = imageFile.substr(12);
+ imageFile = imageFile.substr(0, imageFile.length()-4);
+ SDL_Texture* texture = sHolder->GetDataHolder().getTexturePtr(imageFile);
+ Draw(renderer, texture, x, y, part);
+}
+
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) {
@@ -61,13 +71,7 @@ void DrawLayer(SDL_Renderer* renderer, sago::SagoSpriteHolder* sHolder, const sa
if (gid == 0) {
continue;
}
- SDL_Rect part{};
- std::string imageFile;
- getTextureLocationFromGid(tm, gid, &imageFile, &part.x, &part.y, &part.w, &part.h);
- imageFile = imageFile.substr(12);
- imageFile = imageFile.substr(0, imageFile.length()-4);
- SDL_Texture* texture = sHolder->GetDataHolder().getTexturePtr(imageFile);
- Draw(renderer, texture, 32 * i - topx, 32 * j - topy, part);
+ DrawTile(renderer, sHolder, tm, gid, 32 * i - topx, 32 * j - topy);
}
}
}
diff --git a/src/saland/GameDraw.hpp b/src/saland/GameDraw.hpp index b87e57d..b7ac9c3 100644 --- a/src/saland/GameDraw.hpp +++ b/src/saland/GameDraw.hpp
@@ -40,6 +40,7 @@ void DrawProjectile(SDL_Renderer* target, sago::SagoSpriteHolder* sHolder, const
void DrawRectWhite(SDL_Renderer* target, int topx, int topy, int height, int width);
void DrawRectYellow(SDL_Renderer* target, int topx, int topy, int height, int width);
+void DrawTile(SDL_Renderer* renderer, sago::SagoSpriteHolder* sHolder, const sago::tiled::TileMap& tm, uint32_t gid, int x, int y);
#endif /* GAMEDRAW_HPP */