Continues #2: Adds charge skill impl

- Also adds an arti pickup sound
This commit is contained in:
Linus Probert 2018-08-09 13:58:16 +02:00
parent 736eb79996
commit a04f131c2d
8 changed files with 86 additions and 55 deletions

View File

@ -1,15 +1,4 @@
o Make things less difficult and more interesting
o Interesting items
x Daggers
- Bombs?
- Magical permanent items would be nice
- Piercing daggers
- Charge passthrough
- +1 atk / +1 def items
o Creat some nice room modifiers o Creat some nice room modifiers
x Windy room
x Liquid in rooms
- Falling floor tiles - Falling floor tiles
- Credit screen showing music and graphics guys: - Credit screen showing music and graphics guys:

Binary file not shown.

View File

@ -82,6 +82,7 @@ load_effects(void)
effects[FALL0] = load_effect("Sounds/FX/fall0.wav"); effects[FALL0] = load_effect("Sounds/FX/fall0.wav");
effects[FALL1] = load_effect("Sounds/FX/fall1.wav"); effects[FALL1] = load_effect("Sounds/FX/fall1.wav");
effects[SLAM] = load_effect("Sounds/FX/slam.wav"); effects[SLAM] = load_effect("Sounds/FX/slam.wav");
effects[MAGIC_PICKUP] = load_effect("Sounds/FX/magic_pickup.wav");
} }
void void

View File

@ -58,6 +58,7 @@ typedef enum Fx_t {
PLAYER_HIT2, PLAYER_HIT2,
DAGGER_PICKUP, DAGGER_PICKUP,
SLAM, SLAM,
MAGIC_PICKUP,
LAST_EFFECT LAST_EFFECT
} Fx; } Fx;

View File

@ -556,7 +556,7 @@ monster_drop_loot(Monster *monster, Map *map, Player *player)
// TODO: This should not occur every time // TODO: This should not occur every time
// Debug code. // Debug code.
Artifact *a = artifact_create(TRAP_AVOIDANCE); Artifact *a = artifact_create(CHARGE_THROUGH);
a->sprite->pos = monster->sprite->pos; a->sprite->pos = monster->sprite->pos;
linkedlist_append(&map->artifacts, a); linkedlist_append(&map->artifacts, a);
} }

View File

@ -629,6 +629,7 @@ player_add_artifact(Player *p, Artifact *a)
if (a->collected) if (a->collected)
return; return;
mixer_play_effect(MAGIC_PICKUP);
a->collected = true; a->collected = true;
ArtifactData *ad = &p->equipment.artifacts[a->effect]; ArtifactData *ad = &p->equipment.artifacts[a->effect];

View File

@ -95,5 +95,8 @@ position_in_room(Position *pos, Position *roomPos)
bool bool
position_in_roommatrix(const Position *pos) position_in_roommatrix(const Position *pos)
{ {
return pos->x >= 0 && pos->x < MAP_ROOM_WIDTH && pos->y >= 0 && pos->y < MAP_ROOM_HEIGHT; return pos->x >= 0
&& pos->x < MAP_ROOM_WIDTH
&& pos->y >= 0
&& pos->y < MAP_ROOM_HEIGHT;
} }

View File

@ -34,6 +34,7 @@
#include "item.h" #include "item.h"
#include "animation.h" #include "animation.h"
#include "artifact.h" #include "artifact.h"
#include "trap.h"
static Skill * static Skill *
create_default(const char *s_label, Sprite *s) create_default(const char *s_label, Sprite *s)
@ -271,76 +272,23 @@ create_sip_health(void)
return skill; return skill;
} }
static bool static void
skill_charge(Skill *skill, SkillData *data) skill_charge_check_path(SkillData *data,
Position origin,
Position dest)
{ {
UNUSED(skill);
Player *player = data->player;
RoomMatrix *matrix = data->matrix; RoomMatrix *matrix = data->matrix;
Player *player = data->player;
Position playerPos = position_to_matrix_coords(&player->sprite->pos); Position itPos = origin;
Position destination = playerPos; Position lastPos = dest;
lastPos.x += (int) data->direction.x * 2;
unsigned int steps = 0; lastPos.y += (int) data->direction.y * 2;
Uint8 steps = 1;
// Find collider while (position_in_roommatrix(&itPos) && !position_equals(&itPos, &lastPos)) {
destination.x += (int) data->direction.x; RoomSpace *space = &matrix->spaces[itPos.x][itPos.y];
destination.y += (int) data->direction.y; if (space->monster) {
RoomSpace *space = &matrix->spaces[destination.x][destination.y]; Monster *monster = matrix->spaces[itPos.x][itPos.y].monster;
while (position_in_roommatrix(&destination) && !space->occupied)
{
destination.x += (int) data->direction.x;
destination.y += (int) data->direction.y;
if (space->items != NULL) {
LinkedList *items = space->items;
while (items != NULL) {
Item *item = items->data;
items = items->next;
item_collected(item, player);
}
LinkedList *artifacts = space->artifacts;
while (artifacts != NULL) {
Artifact *artifact = artifacts->data;
artifacts = artifacts->next;
player_add_artifact(player, artifact);
}
}
space = &matrix->spaces[destination.x][destination.y];
steps++;
}
if (!position_in_roommatrix(&destination)) {
destination.x -= (int) data->direction.x;
destination.y -= (int) data->direction.y;
}
// Move player
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;
player_turn(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);
mixer_play_effect(SWOOSH);
if (matrix->spaces[destination.x][destination.y].monster) {
Monster *monster = matrix->spaces[destination.x][destination.y].monster;
Stats tmpStats = player->stats; Stats tmpStats = player->stats;
tmpStats.dmg *= steps > 0 ? steps : 1; tmpStats.dmg *= steps > 0 ? steps : 1;
mixer_play_effect(SWING0 + get_random(3) - 1); mixer_play_effect(SWING0 + get_random(3) - 1);
@ -354,6 +302,94 @@ skill_charge(Skill *skill, SkillData *data)
player_monster_kill_check(data->player, monster); player_monster_kill_check(data->player, monster);
} }
// Pick up items in the path
LinkedList *items = space->items;
while (items != NULL) {
Item *item = items->data;
items = items->next;
item_collected(item, player);
}
LinkedList *artifacts = space->artifacts;
while (artifacts != NULL) {
Artifact *artifact = artifacts->data;
artifacts = artifacts->next;
player_add_artifact(player, artifact);
}
if (space->trap)
space->trap->sprite->animate = true;
itPos.x += (int) data->direction.x;
itPos.y += (int) data->direction.y;
steps++;
}
}
static bool
skill_charge(Skill *skill, SkillData *data)
{
UNUSED(skill);
Player *player = data->player;
RoomMatrix *matrix = data->matrix;
Position playerStartPos = position_to_matrix_coords(&player->sprite->pos);
Position destination = playerStartPos;
// Find collider
destination.x += (int) data->direction.x;
destination.y += (int) data->direction.y;
RoomSpace *space = &matrix->spaces[destination.x][destination.y];
Uint32 passThroughCount = 0;
Uint32 chargeThroughLvl = player_has_artifact(data->player, CHARGE_THROUGH);
Position lastAvailableDest = playerStartPos;
while (position_in_roommatrix(&destination))
{
if (space->occupied) {
if (!space->monster || passThroughCount >= chargeThroughLvl)
break;
else
passThroughCount++;
} else {
lastAvailableDest = destination;
}
destination.x += (int) data->direction.x;
destination.y += (int) data->direction.y;
space = &matrix->spaces[destination.x][destination.y];
}
destination = lastAvailableDest;
// Move player
Position playerOriginPos = player->sprite->pos;
Sint32 xdiff = destination.x - playerStartPos.x;
Sint32 ydiff = destination.y - playerStartPos.y;
player->sprite->pos.x += xdiff * TILE_DIMENSION;
player->sprite->pos.y += ydiff * TILE_DIMENSION;
Position playerDestinationPos = player->sprite->pos;
player_turn(data->player, &data->direction);
// Add motion particles
bool horizontal = data->direction.x != 0;
Dimension particleArea;
if (horizontal)
particleArea = (Dimension) { abs(xdiff) * TILE_DIMENSION, TILE_DIMENSION };
else
particleArea = (Dimension) { TILE_DIMENSION, abs(ydiff) * 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);
mixer_play_effect(SWOOSH);
skill_charge_check_path(data, playerStartPos, destination);
return true; return true;
} }