Adds "speed lines" to charge skill
This commit is contained in:
parent
7e596a251e
commit
b05f9333dc
|
@ -164,13 +164,13 @@ item_builder_build_item(ItemKey key, int level)
|
||||||
item = create_item(path_flesh,
|
item = create_item(path_flesh,
|
||||||
CLIP16(get_random(7) * 16, get_random(1) * 16),
|
CLIP16(get_random(7) * 16, get_random(1) * 16),
|
||||||
&eat_flesh);
|
&eat_flesh);
|
||||||
item->value = 1 + get_random(level*2);
|
item->value = 1 + get_random(level);
|
||||||
break;
|
break;
|
||||||
case HEALTH:
|
case HEALTH:
|
||||||
item = create_item(path_potion,
|
item = create_item(path_potion,
|
||||||
CLIP16(0, 0),
|
CLIP16(0, 0),
|
||||||
&drink_health);
|
&drink_health);
|
||||||
item->value = 1 + get_random(level*2);
|
item->value = 1 + get_random(level);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fatal("in item_builder_build() : Unhandled item key %d", key);
|
fatal("in item_builder_build() : Unhandled item key %d", key);
|
||||||
|
|
|
@ -148,6 +148,35 @@ particle_engine_eldritch_explosion(Position pos, Dimension dim)
|
||||||
create_explosion(pos, dim, 1, green);
|
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
|
static void
|
||||||
move_particle(Particle *particle, float deltaTime)
|
move_particle(Particle *particle, float deltaTime)
|
||||||
{
|
{
|
||||||
|
|
|
@ -36,6 +36,9 @@ particle_engine_fire_explosion(Position, Dimension);
|
||||||
void
|
void
|
||||||
particle_engine_eldritch_explosion(Position, Dimension);
|
particle_engine_eldritch_explosion(Position, Dimension);
|
||||||
|
|
||||||
|
void
|
||||||
|
particle_engine_speed_lines(Position, Dimension, bool horizontal);
|
||||||
|
|
||||||
void
|
void
|
||||||
particle_engine_update(float deltatime);
|
particle_engine_update(float deltatime);
|
||||||
|
|
||||||
|
|
|
@ -74,3 +74,9 @@ bool position_in_room(Position *pos, Position *roomPos)
|
||||||
|
|
||||||
return true;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -26,12 +26,19 @@ typedef struct {
|
||||||
int y;
|
int y;
|
||||||
} Position;
|
} 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_
|
#endif // POSITION_H_
|
||||||
|
|
47
src/skill.c
47
src/skill.c
|
@ -28,6 +28,7 @@
|
||||||
#include "mixer.h"
|
#include "mixer.h"
|
||||||
#include "gui.h"
|
#include "gui.h"
|
||||||
#include "random.h"
|
#include "random.h"
|
||||||
|
#include "particle_engine.h"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_player_clip_for_direction(Player *player, Vector2d *direction)
|
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;
|
player->sprite->clip.y = 48;
|
||||||
else if (direction->x < 0) // Left
|
else if (direction->x < 0) // Left
|
||||||
player->sprite->clip.y = 16;
|
player->sprite->clip.y = 16;
|
||||||
else if (direction->x < 0) // Right
|
else if (direction->x > 0) // Right
|
||||||
player->sprite->clip.y = 32;
|
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);
|
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;
|
Monster *monster = data->matrix->spaces[targetPos.x][targetPos.y].monster;
|
||||||
mixer_play_effect(TRIPPLE_SWING);
|
mixer_play_effect(TRIPPLE_SWING);
|
||||||
if (monster) {
|
if (monster) {
|
||||||
|
@ -79,9 +84,9 @@ skill_use_flurry(Skill *skill, SkillData *data)
|
||||||
unsigned int dmg = stats_fight(&data->player->stats, &monster->stats);
|
unsigned int dmg = stats_fight(&data->player->stats, &monster->stats);
|
||||||
if (dmg > 0 && originalHp > 0) {
|
if (dmg > 0 && originalHp > 0) {
|
||||||
gui_log("You hit for %u damage", dmg);
|
gui_log("You hit for %u damage", dmg);
|
||||||
monster_hit(monster, dmg);
|
|
||||||
hitCount++;
|
hitCount++;
|
||||||
}
|
}
|
||||||
|
monster_hit(monster, dmg);
|
||||||
}
|
}
|
||||||
if (hitCount == 1) {
|
if (hitCount == 1) {
|
||||||
mixer_play_effect(SWORD_HIT);
|
mixer_play_effect(SWORD_HIT);
|
||||||
|
@ -151,21 +156,44 @@ skill_charge(Skill *skill, SkillData *data)
|
||||||
unsigned int steps = 0;
|
unsigned int steps = 0;
|
||||||
|
|
||||||
// Find collider
|
// 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.x += (int) data->direction.x;
|
||||||
destination.y += (int) data->direction.y;
|
destination.y += (int) data->direction.y;
|
||||||
steps++;
|
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
|
// Move player
|
||||||
steps--;
|
Position playerOriginPos = player->sprite->pos;
|
||||||
player->sprite->pos.x += (steps * TILE_DIMENSION) * (int) data->direction.x;
|
player->sprite->pos.x += (steps * TILE_DIMENSION) * (int) data->direction.x;
|
||||||
player->sprite->pos.y += (steps * TILE_DIMENSION) * (int) data->direction.y;
|
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);
|
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) {
|
if (matrix->spaces[destination.x][destination.y].monster) {
|
||||||
Monster *monster = matrix->spaces[destination.x][destination.y].monster;
|
Monster *monster = matrix->spaces[destination.x][destination.y].monster;
|
||||||
Stats tmpStats = player->stats;
|
Stats tmpStats = player->stats;
|
||||||
|
@ -174,9 +202,10 @@ skill_charge(Skill *skill, SkillData *data)
|
||||||
unsigned int dmg = stats_fight(&tmpStats, &monster->stats);
|
unsigned int dmg = stats_fight(&tmpStats, &monster->stats);
|
||||||
if (dmg > 0) {
|
if (dmg > 0) {
|
||||||
gui_log("You charged %s for %u damage", monster->lclabel, dmg);
|
gui_log("You charged %s for %u damage", monster->lclabel, dmg);
|
||||||
monster_hit(monster, dmg);
|
|
||||||
mixer_play_effect(SWORD_HIT);
|
mixer_play_effect(SWORD_HIT);
|
||||||
|
data->player->hits += 1;
|
||||||
}
|
}
|
||||||
|
monster_hit(monster, dmg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue