diff --git a/src/saland/Game.cpp b/src/saland/Game.cpp index 7e8950c..39aec85 100644 --- a/src/saland/Game.cpp +++ b/src/saland/Game.cpp @@ -249,6 +249,15 @@ Game::Game() { Spell& slot0 = data->slot_spell.at(0); slot0.icon = "effect_fireball"; slot0.name = "spell_fireball"; + Spell& slot2 = data->slot_spell.at(2); + slot2.icon = ""; + slot2.name = "spell_create_block"; + slot2.tile = 607; + slot2.type = SpellCursorType::tile; + Spell& slot9 = data->slot_spell.at(9); + slot9.icon = ""; + slot9.name = "spell_clear_block"; + slot9.type = SpellCursorType::tile; } Game::~Game() { @@ -316,8 +325,10 @@ void Game::Draw(SDL_Renderer* target) { 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, + if (data->slot_spell.at(data->slot_selected).type == SpellCursorType::tile) { + 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) { @@ -371,6 +382,9 @@ void Game::Draw(SDL_Renderer* target) { if (current_spell.icon.length() > 0) { globalData.spriteHolder.get()->GetSprite(current_spell.icon).Draw(target, SDL_GetTicks(), 36+i*56, 36); } + if (current_spell.tile > 0) { + DrawTile(target, globalData.spriteHolder.get(), data->gameRegion.world.tm, current_spell.tile, 20+i*56, 20); + } } if (data->consoleActive && data->console) { data->console->Draw(target); @@ -627,6 +641,34 @@ void Game::Update() { data->gameRegion.placeables.push_back(projectile); } } + if (data->slot_spell.at(data->slot_selected).name == "spell_create_block") { + if (data->human->castTimeRemaining == 0) { + data->human->castTimeRemaining = data->human->castTime; + int tile_x = data->world_mouse_x/32; + int tile_y = data->world_mouse_y/32; + int tile = data->slot_spell.at(data->slot_selected).tile; + if (sago::tiled::tileInBound(data->gameRegion.world.tm, tile_x, tile_y) + && !(data->gameRegion.world.tile_protected(tile_x, tile_y)) ) { + int layer_number = 2; // Do not hardcode + sago::tiled::setTileOnLayerNumber(data->gameRegion.world.tm, layer_number, tile_x, tile_y, tile); + data->gameRegion.world.init_physics(data->gameRegion.physicsBox); + } + } + } + if (data->slot_spell.at(data->slot_selected).name == "spell_clear_block") { + if (data->human->castTimeRemaining == 0) { + data->human->castTimeRemaining = data->human->castTime; + int tile_x = data->world_mouse_x/32; + int tile_y = data->world_mouse_y/32; + if (sago::tiled::tileInBound(data->gameRegion.world.tm, tile_x, tile_y) + && !(data->gameRegion.world.tile_protected(tile_x, tile_y)) ) { + int layer_number = 2; // Do not hardcode + uint32_t tile = 0; + sago::tiled::setTileOnLayerNumber(data->gameRegion.world.tm, layer_number, tile_x, tile_y, tile); + data->gameRegion.world.init_physics(data->gameRegion.physicsBox); + } + } + } } data->middleField.SetText(middleText); } diff --git a/src/saland/model/spells.hpp b/src/saland/model/spells.hpp index 154faaf..a6abe98 100644 --- a/src/saland/model/spells.hpp +++ b/src/saland/model/spells.hpp @@ -26,9 +26,13 @@ https://github.com/sago007/saland #include +enum class SpellCursorType { dot = 0, tile=1, shpere = 2 }; + struct Spell { std::string name; std::string icon; + int tile = 0; //Number reference to a tile, we might also need a tileset at some point + SpellCursorType type = SpellCursorType::dot; }; #endif //MODEL_SPELLS_HPP \ No newline at end of file