git repos / saland

commit 838111ea

Poul Sander · 2020-10-11 11:52
838111ea200e4f78fd30dc7fd26282570aec1fed patch · browse files
parent 1bc1d335dc61b69fea77a476504823196b25e9d8

Add fireball to the spell slots

Changed files

M src/saland/Game.cpp before
A src/saland/model/spells.hpp
diff --git a/src/saland/Game.cpp b/src/saland/Game.cpp index 247457c..7e8950c 100644 --- a/src/saland/Game.cpp +++ b/src/saland/Game.cpp
@@ -34,6 +34,7 @@ https://github.com/sago007/saland
#include "../sago/SagoTextField.hpp"
#include "globals.hpp"
#include "model/placeables.hpp"
+#include "model/spells.hpp"
#include "model/Player.hpp"
#include "../os.hpp"
#include "SDL.h"
@@ -175,6 +176,7 @@ struct Game::GameImpl {
sago::SagoTextField middleField;
std::array<sago::SagoTextField,10> number_labels; //Label: 0,1...10
size_t slot_selected = 0;
+ std::array<Spell, 10> slot_spell;
std::shared_ptr<Console> console;
bool consoleActive = false;
};
@@ -244,6 +246,9 @@ Game::Game() {
data->number_labels.at(i).SetFontSize(20);
data->number_labels.at(i).SetText(std::to_string(i));
}
+ Spell& slot0 = data->slot_spell.at(0);
+ slot0.icon = "effect_fireball";
+ slot0.name = "spell_fireball";
}
Game::~Game() {
@@ -362,6 +367,10 @@ void Game::Draw(SDL_Renderer* target) {
}
int key_number = (i+1)%10;
data->number_labels.at(key_number).Draw(target, 10+i*56, 10);
+ const Spell& current_spell = data->slot_spell.at(i);
+ if (current_spell.icon.length() > 0) {
+ globalData.spriteHolder.get()->GetSprite(current_spell.icon).Draw(target, SDL_GetTicks(), 36+i*56, 36);
+ }
}
if (data->consoleActive && data->console) {
data->console->Draw(target);
@@ -604,17 +613,19 @@ void Game::Update() {
data->consoleActive = false;
}
if (SDL_GetMouseState(nullptr,nullptr) & 1 && !data->consoleActive) {
- if (data->human->castTimeRemaining == 0) {
- data->human->castTimeRemaining = data->human->castTime;
- std::shared_ptr<Projectile> projectile = std::make_shared<Projectile>();
- projectile->X = data->human->X;
- projectile->Y = data->human->Y;
- projectile->Radius = 8.0f;
- projectile->directionX = projectile->X - data->world_mouse_x;
- projectile->directionY = projectile->Y - data->world_mouse_y;
- SetLengthToOne(projectile->directionX, projectile->directionY);
- projectile->fired_by = data->human;
- data->gameRegion.placeables.push_back(projectile);
+ if (data->slot_spell.at(data->slot_selected).name == "spell_fireball") {
+ if (data->human->castTimeRemaining == 0) {
+ data->human->castTimeRemaining = data->human->castTime;
+ std::shared_ptr<Projectile> projectile = std::make_shared<Projectile>();
+ projectile->X = data->human->X;
+ projectile->Y = data->human->Y;
+ projectile->Radius = 8.0f;
+ projectile->directionX = projectile->X - data->world_mouse_x;
+ projectile->directionY = projectile->Y - data->world_mouse_y;
+ SetLengthToOne(projectile->directionX, projectile->directionY);
+ projectile->fired_by = data->human;
+ data->gameRegion.placeables.push_back(projectile);
+ }
}
}
data->middleField.SetText(middleText);
diff --git a/src/saland/model/spells.hpp b/src/saland/model/spells.hpp new file mode 100644 index 0000000..154faaf --- /dev/null +++ b/src/saland/model/spells.hpp
@@ -0,0 +1,34 @@
+/*
+===========================================================================
+ * Saland Adventures
+Copyright (C) 2014-2020 Poul Sander
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see http://www.gnu.org/licenses/
+
+Source information and contacts persons can be found at
+https://github.com/sago007/saland
+===========================================================================
+*/
+
+#ifndef MODEL_SPELLS_HPP
+#define MODEL_SPELLS_HPP
+
+#include <string>
+
+struct Spell {
+ std::string name;
+ std::string icon;
+};
+
+#endif //MODEL_SPELLS_HPP
\ No newline at end of file