Adds "speed lines" to charge skill

This commit is contained in:
Linus Probert 2018-03-01 19:37:57 +01:00
parent 7e596a251e
commit b05f9333dc
6 changed files with 89 additions and 15 deletions

View File

@ -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);

View File

@ -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)
{

View File

@ -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);

View File

@ -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;
}

View File

@ -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_

View File

@ -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;