commit 29403a16
Weapon now does damage
Changed files
| M | extra/scripts/python/create_human_sprite.py before |
| M | src/saland/Game.cpp before |
| M | src/saland/GameDraw.cpp before |
diff --git a/extra/scripts/python/create_human_sprite.py b/extra/scripts/python/create_human_sprite.py
index 78ad941..9ab9055 100644
--- a/extra/scripts/python/create_human_sprite.py
+++ b/extra/scripts/python/create_human_sprite.py
@@ -15,6 +15,19 @@ def print_male(race="male", file=sys.stdout):
common.directional_sprite.print_sprite_direction(race=race, animation="hurt", name=None, texture=race+"_slash", topY=0, number_of_frames=6, file=file)
+def print_weapon(texture, weapon_name, file=sys.stdout):
+ race = "human"
+ common.directional_sprite.print_sprite(race=race, animation="spellcast", name=weapon_name, texture=texture, topY=0, number_of_frames=8, file=file)
+ print(",", file=file)
+ common.directional_sprite.print_sprite(race=race, animation="standing", name=weapon_name, texture=texture, topY=256*2, number_of_frames=1, file=file)
+ print(",", file=file)
+ common.directional_sprite.print_sprite(race=race, animation="walkcycle", name=weapon_name, texture=texture, topX=64, topY=256*2, number_of_frames=8, file=file)
+ print(",", file=file)
+ common.directional_sprite.print_sprite(race=race, animation="slash", name=weapon_name, texture=texture, topY=256*3, number_of_frames=6, file=file)
+ print(",", file=file)
+ common.directional_sprite.print_sprite_direction(race=race, animation="hurt", name=weapon_name, texture=texture, topY=256*4, number_of_frames=6, file=file)
+
+
def main():
with open('../../../data/sprites/humans.sprite', 'w') as file:
print("{", file=file)
@@ -24,5 +37,11 @@ def main():
print(",", file=file)
print_male("female", file=file)
print("}", file=file)
+ with open('../../../data/sprites/weapons.sprite', 'w') as file:
+ print("{", file=file)
+ print("\"_comment\" : \"This file is generated with extra/scripts/build_sprites.sh. Do not edit.\"", file=file)
+ print(",", file=file)
+ print_weapon("weapons/long_knife", "long_knife", file=file)
+ print("}", file=file)
main()
\ No newline at end of file
diff --git a/src/saland/Game.cpp b/src/saland/Game.cpp
index b5481e4..7bb681e 100644
--- a/src/saland/Game.cpp
+++ b/src/saland/Game.cpp
@@ -518,6 +518,23 @@ static bool Intersect(const Placeable& p1, const Placeable& p2) {
return false;
}
+static std::pair<float,float> PairInFrontOfEntity(float entityX, float entityY, char direction) {
+ std::pair<float, float> ret(entityX, entityY+32.0f);
+ if (direction == 'N') {
+ ret.first = entityX;
+ ret.second = entityY-32.0f;
+ }
+ else if (direction == 'E') {
+ ret.first = entityX+32.0f;
+ ret.second = entityY;
+ }
+ else if (direction == 'W') {
+ ret.first = entityX-32.0f;
+ ret.second = entityY;
+ }
+ return ret;
+}
+
void Game::Update() {
std::string middleText = "";
if (data->consoleActive && data->console) {
@@ -686,6 +703,11 @@ void Game::Update() {
if (data->consoleActive && data->console && !data->console->IsActive()) {
data->consoleActive = false;
}
+ const Spell& selectedSpell = data->slot_spell.at(data->slot_selected);
+ data->human->weapon = "";
+ if (selectedSpell.name == "weapon_slash_long_knife") {
+ data->human->weapon = "long_knife";
+ }
if (SDL_GetMouseState(nullptr,nullptr) & 1 && !data->consoleActive) {
if (data->slot_spell.at(data->slot_selected).name == "spell_fireball") {
if (data->human->castTimeRemaining == 0) {
@@ -702,7 +724,6 @@ void Game::Update() {
data->gameRegion.placeables.push_back(projectile);
}
}
- const Spell& selectedSpell = data->slot_spell.at(data->slot_selected);
if (data->slot_spell.at(data->slot_selected).name == "spell_spawn_item") {
if (data->human->castTimeRemaining == 0) {
data->human->castTimeRemaining = data->human->castTime;
@@ -716,6 +737,18 @@ void Game::Update() {
if (data->human->castTimeRemaining == 0) {
data->human->castTimeRemaining = data->human->castTime;
data->human->animation = "slash";
+ // Now do the damage. We are currectly just creating a short lived projectile
+ const auto& target = PairInFrontOfEntity(data->human->X, data->human->Y, data->human->direction);
+ std::shared_ptr<Projectile> projectile = std::make_shared<Projectile>();
+ projectile->X = target.first;
+ projectile->Y = target.second;
+ 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);
+ projectile->timeToLive = 10.0f;
}
}
if (data->slot_spell.at(data->slot_selected).name == "spell_create_block") {
diff --git a/src/saland/GameDraw.cpp b/src/saland/GameDraw.cpp
index 4365cc9..6816460 100644
--- a/src/saland/GameDraw.cpp
+++ b/src/saland/GameDraw.cpp
@@ -211,7 +211,7 @@ void DrawHumanEntity(SDL_Renderer* target, sago::SagoSpriteHolder* sHolder, cons
}
}
if (entity->weapon.length() > 0) {
- const sago::SagoSprite& myWeapon = sHolder->GetSprite(entity->race + "_"+animation+"_"+entity->weapon+"_"+std::string(1,entity->direction));
+ const sago::SagoSprite& myWeapon = sHolder->GetSprite("human_"+animation+"_"+entity->weapon+"_"+std::string(1,entity->direction));
if (relativeAnimation) {
myWeapon.DrawProgressive(target, relativeAnimationState, std::round(entity->X) - offsetX, std::round(entity->Y) - offsetY);
}