From b05f9333dc8a8294585b10ec425c3e76a831746b Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Thu, 1 Mar 2018 19:37:57 +0100 Subject: [PATCH] Adds "speed lines" to charge skill --- src/item_builder.c | 4 ++-- src/particle_engine.c | 29 ++++++++++++++++++++++++++ src/particle_engine.h | 3 +++ src/position.c | 6 ++++++ src/position.h | 15 ++++++++++---- src/skill.c | 47 ++++++++++++++++++++++++++++++++++--------- 6 files changed, 89 insertions(+), 15 deletions(-) diff --git a/src/item_builder.c b/src/item_builder.c index f8f3918..cb2d329 100644 --- a/src/item_builder.c +++ b/src/item_builder.c @@ -164,13 +164,13 @@ item_builder_build_item(ItemKey key, int level) item = create_item(path_flesh, CLIP16(get_random(7) * 16, get_random(1) * 16), &eat_flesh); - item->value = 1 + get_random(level*2); + item->value = 1 + get_random(level); break; case HEALTH: item = create_item(path_potion, CLIP16(0, 0), &drink_health); - item->value = 1 + get_random(level*2); + item->value = 1 + get_random(level); break; default: fatal("in item_builder_build() : Unhandled item key %d", key); diff --git a/src/particle_engine.c b/src/particle_engine.c index a80bdac..0ab05f4 100644 --- a/src/particle_engine.c +++ b/src/particle_engine.c @@ -148,6 +148,35 @@ particle_engine_eldritch_explosion(Position pos, Dimension dim) create_explosion(pos, dim, 1, green); } +void +particle_engine_speed_lines(Position pos, Dimension dim, bool horizontal) +{ + static SDL_Color color = { 0, 0, 255, 200 }; + + for (unsigned int i = 0; i < 150; ++i) { + int x, y; + unsigned int lt; + Particle *p; + + x = get_random(dim.width) + pos.x; + y = get_random(dim.height) + pos.y; + + lt = get_random(10); + + p = ec_malloc(sizeof(Particle)); + p->pos = (Position) { x, y }; + p->velocity = (Vector2d) { 0, 0 }; + p->movetime = lt; + p->lifetime = lt; + if (horizontal) + p->dim = (Dimension) { 20, 1 }; + else + p->dim = (Dimension) { 2, 20 }; + p->color = color; + linkedlist_append(&engine->particles, p); + } +} + static void move_particle(Particle *particle, float deltaTime) { diff --git a/src/particle_engine.h b/src/particle_engine.h index 7c838cd..ac57f91 100644 --- a/src/particle_engine.h +++ b/src/particle_engine.h @@ -36,6 +36,9 @@ particle_engine_fire_explosion(Position, Dimension); void particle_engine_eldritch_explosion(Position, Dimension); +void +particle_engine_speed_lines(Position, Dimension, bool horizontal); + void particle_engine_update(float deltatime); diff --git a/src/position.c b/src/position.c index 78fd789..2092a70 100644 --- a/src/position.c +++ b/src/position.c @@ -74,3 +74,9 @@ bool position_in_room(Position *pos, Position *roomPos) return true; } + +bool +position_in_roommatrix(const Position *pos) +{ + return pos->x >= 0 && pos->x < MAP_ROOM_WIDTH && pos->y > 0 && pos->y < MAP_ROOM_HEIGHT; +} diff --git a/src/position.h b/src/position.h index bc66f48..4e20522 100644 --- a/src/position.h +++ b/src/position.h @@ -26,12 +26,19 @@ typedef struct { int y; } Position; -Position position_to_matrix_coords(Position*); +Position +position_to_matrix_coords(Position*); -Position position_to_room_coords(Position*); +Position +position_to_room_coords(Position*); -bool position_in_room(Position *pos, Position *roomPos); +bool +position_in_room(Position *pos, Position *roomPos); -bool position_equals(const Position*, const Position*); +bool +position_equals(const Position*, const Position*); + +bool +position_in_roommatrix(const Position*); #endif // POSITION_H_ diff --git a/src/skill.c b/src/skill.c index 77f737d..3a1b201 100644 --- a/src/skill.c +++ b/src/skill.c @@ -28,6 +28,7 @@ #include "mixer.h" #include "gui.h" #include "random.h" +#include "particle_engine.h" static void set_player_clip_for_direction(Player *player, Vector2d *direction) @@ -38,7 +39,7 @@ set_player_clip_for_direction(Player *player, Vector2d *direction) player->sprite->clip.y = 48; else if (direction->x < 0) // Left player->sprite->clip.y = 16; - else if (direction->x < 0) // Right + else if (direction->x > 0) // Right player->sprite->clip.y = 32; } @@ -69,6 +70,10 @@ skill_use_flurry(Skill *skill, SkillData *data) set_player_clip_for_direction(data->player, &data->direction); + if (!position_in_roommatrix(&targetPos)) { + return false; + } + Monster *monster = data->matrix->spaces[targetPos.x][targetPos.y].monster; mixer_play_effect(TRIPPLE_SWING); if (monster) { @@ -79,9 +84,9 @@ skill_use_flurry(Skill *skill, SkillData *data) unsigned int dmg = stats_fight(&data->player->stats, &monster->stats); if (dmg > 0 && originalHp > 0) { gui_log("You hit for %u damage", dmg); - monster_hit(monster, dmg); hitCount++; } + monster_hit(monster, dmg); } if (hitCount == 1) { mixer_play_effect(SWORD_HIT); @@ -151,21 +156,44 @@ skill_charge(Skill *skill, SkillData *data) unsigned int steps = 0; // Find collider - do { + destination.x += (int) data->direction.x; + destination.y += (int) data->direction.y; + while (position_in_roommatrix(&destination) + && !matrix->spaces[destination.x][destination.y].occupied) + { destination.x += (int) data->direction.x; destination.y += (int) data->direction.y; steps++; - } while (!matrix->spaces[destination.x][destination.y].occupied - || destination.x == MAP_ROOM_WIDTH || destination.x < 0 - || destination.y == MAP_ROOM_HEIGHT ||destination.y < 0); + } + + if (!position_in_roommatrix(&destination)) { + destination.x -= (int) data->direction.x; + destination.y -= (int) data->direction.y; + } // Move player - steps--; + Position playerOriginPos = player->sprite->pos; player->sprite->pos.x += (steps * TILE_DIMENSION) * (int) data->direction.x; player->sprite->pos.y += (steps * TILE_DIMENSION) * (int) data->direction.y; - + Position playerDestinationPos = player->sprite->pos; set_player_clip_for_direction(data->player, &data->direction); + // Add motion particles + bool horizontal = data->direction.x != 0; + Dimension particleArea; + if (horizontal) + particleArea = (Dimension) { steps * TILE_DIMENSION, TILE_DIMENSION }; + else + particleArea = (Dimension) { TILE_DIMENSION, steps * TILE_DIMENSION }; + + Position speedLinePos; + if (playerOriginPos.x < playerDestinationPos.x || playerOriginPos.y < playerDestinationPos.y) + speedLinePos = playerOriginPos; + else + speedLinePos = playerDestinationPos; + + particle_engine_speed_lines(speedLinePos, particleArea, horizontal); + if (matrix->spaces[destination.x][destination.y].monster) { Monster *monster = matrix->spaces[destination.x][destination.y].monster; Stats tmpStats = player->stats; @@ -174,9 +202,10 @@ skill_charge(Skill *skill, SkillData *data) unsigned int dmg = stats_fight(&tmpStats, &monster->stats); if (dmg > 0) { gui_log("You charged %s for %u damage", monster->lclabel, dmg); - monster_hit(monster, dmg); mixer_play_effect(SWORD_HIT); + data->player->hits += 1; } + monster_hit(monster, dmg); } return true;