Fixes working explosions and artifacts

Artifacts:
- Explosive daggers
- Explosive kills
This commit is contained in:
Linus Probert 2019-05-25 13:11:24 +02:00
parent 68f4e152d3
commit 1d988d7f2f
9 changed files with 88 additions and 39 deletions

Binary file not shown.

View File

@ -77,6 +77,9 @@ artifact_set_effect(Artifact *a, MagicalEffect effect)
a->info.name = "Stick of dynamite"; a->info.name = "Stick of dynamite";
a->info.desc = "You are an explosive slayer"; a->info.desc = "You are an explosive slayer";
break; break;
case VOLATILE_DAGGERS:
a->info.name = "Glowing dagger";
a->info.desc = "Your daggers are volatile";
default: default:
break; break;
} }
@ -92,7 +95,8 @@ static int WarriorArtifacts[] = {
INCREASED_STUN, // 6 INCREASED_STUN, // 6
DAGGER_BOUNCE, // 7 DAGGER_BOUNCE, // 7
EXPLOSIVE_KILLS, // 8 EXPLOSIVE_KILLS, // 8
CHARGE_THROUGH // 9 VOLATILE_DAGGERS, // 9
CHARGE_THROUGH // 10
}; };
static int RogueArtifacts[] = { static int RogueArtifacts[] = {
@ -105,7 +109,8 @@ static int RogueArtifacts[] = {
INCREASED_STUN, // 6 INCREASED_STUN, // 6
DAGGER_BOUNCE, // 7 DAGGER_BOUNCE, // 7
EXPLOSIVE_KILLS, // 8 EXPLOSIVE_KILLS, // 8
PHASE_IMPROVEMENT // 9 VOLATILE_DAGGERS, // 9
PHASE_IMPROVEMENT // 10
}; };
static int MageArtifacts[] = { static int MageArtifacts[] = {
@ -118,7 +123,8 @@ static int MageArtifacts[] = {
INCREASED_STUN, // 6 INCREASED_STUN, // 6
DAGGER_BOUNCE, // 7 DAGGER_BOUNCE, // 7
EXPLOSIVE_KILLS, // 8 EXPLOSIVE_KILLS, // 8
SKILL_RADIUS // 9 VOLATILE_DAGGERS, // 9
SKILL_RADIUS // 10
}; };
/* Not in play yet */ /* Not in play yet */
@ -132,7 +138,8 @@ static int PaladinArtifacts[] = {
INCREASED_STUN, // 6 INCREASED_STUN, // 6
DAGGER_BOUNCE, // 7 DAGGER_BOUNCE, // 7
EXPLOSIVE_KILLS, // 8 EXPLOSIVE_KILLS, // 8
SKILL_RADIUS // 9 VOLATILE_DAGGERS, // 9
SKILL_RADIUS // 10
}; };
/* Not in play yet */ /* Not in play yet */
@ -146,7 +153,8 @@ static int EngineerArtifacts[] = {
INCREASED_STUN, // 6 INCREASED_STUN, // 6
DAGGER_BOUNCE, // 7 DAGGER_BOUNCE, // 7
EXPLOSIVE_KILLS, // 8 EXPLOSIVE_KILLS, // 8
PHASE_IMPROVEMENT // 9 VOLATILE_DAGGERS, // 9
PHASE_IMPROVEMENT // 10
}; };
static void static void
@ -268,6 +276,11 @@ artifact_sprite_for(MagicalEffect effect)
sprite_set_texture(sprite, t, 0); sprite_set_texture(sprite, t, 0);
sprite->clip = CLIP16(32, 0); sprite->clip = CLIP16(32, 0);
break; break;
case VOLATILE_DAGGERS:
t = texturecache_add("Extras/Artifacts.png");
sprite_set_texture(sprite, t, 0);
sprite->clip = CLIP16(16, 0);
break;
default: default:
break; break;
} }

View File

@ -33,6 +33,7 @@ typedef enum MagicalEffect {
SKILL_RADIUS, SKILL_RADIUS,
DAGGER_BOUNCE, DAGGER_BOUNCE,
EXPLOSIVE_KILLS, EXPLOSIVE_KILLS,
VOLATILE_DAGGERS,
LAST_ARTIFACT_EFFECT // Sentinel LAST_ARTIFACT_EFFECT // Sentinel
} MagicalEffect; } MagicalEffect;

View File

@ -24,6 +24,7 @@
void void
effect_damage_surroundings(Position *pos, effect_damage_surroundings(Position *pos,
RoomMatrix *rm, RoomMatrix *rm,
Player *player,
Stats *attackerStats, Stats *attackerStats,
unsigned int radius, unsigned int radius,
unsigned int pushRadius, unsigned int pushRadius,
@ -48,7 +49,7 @@ effect_damage_surroundings(Position *pos,
Vector2d dir = vector2d_to_direction(&VEC2D((float) i, (float) j)); Vector2d dir = vector2d_to_direction(&VEC2D((float) i, (float) j));
for (unsigned int k = 0; k < pushRadius; ++k) { for (unsigned int k = 0; k < pushRadius; ++k) {
monster_push(r->monster, monster_push(r->monster,
roommatrix_get_player(rm), player,
rm, rm,
dir); dir);
} }

View File

@ -24,6 +24,7 @@
void void
effect_damage_surroundings(Position *pos, effect_damage_surroundings(Position *pos,
RoomMatrix *rm, RoomMatrix *rm,
Player *player,
Stats *attackerStats, Stats *attackerStats,
unsigned int radius, unsigned int radius,
unsigned int pushRadius, unsigned int pushRadius,

View File

@ -92,6 +92,7 @@ load_effects(void)
effects[KEY_PICKUP] = load_effect("Sounds/FX/key_pickup.wav"); effects[KEY_PICKUP] = load_effect("Sounds/FX/key_pickup.wav");
effects[BLINK_EFFECT] = load_effect("Sounds/FX/blink.wav"); effects[BLINK_EFFECT] = load_effect("Sounds/FX/blink.wav");
effects[BLAST_EFFECT] = load_effect("Sounds/FX/blast.wav"); effects[BLAST_EFFECT] = load_effect("Sounds/FX/blast.wav");
effects[EXPLOSION_EFFECT] = load_effect("Sounds/FX/explosion.wav");
} }
void void

View File

@ -68,6 +68,7 @@ typedef enum Fx_t {
KEY_PICKUP, KEY_PICKUP,
BLINK_EFFECT, BLINK_EFFECT,
BLAST_EFFECT, BLAST_EFFECT,
EXPLOSION_EFFECT,
LAST_EFFECT LAST_EFFECT
} Fx; } Fx;

View File

@ -37,6 +37,7 @@
#include "trap.h" #include "trap.h"
#include "gamecontroller.h" #include "gamecontroller.h"
#include "event.h" #include "event.h"
#include "effect_util.h"
#ifdef STEAM_BUILD #ifdef STEAM_BUILD
#include "steam/steamworks_api_wrapper.h" #include "steam/steamworks_api_wrapper.h"
@ -150,6 +151,17 @@ on_monster_collision(Player *player,
player->stat_data.misses += 1; player->stat_data.misses += 1;
} }
player_monster_kill_check(player, monster); player_monster_kill_check(player, monster);
if (monster->stats.hp <= 0 && (player_has_artifact(player, EXPLOSIVE_KILLS))) {
mixer_play_effect(EXPLOSION_EFFECT);
particle_engine_fire_explosion(monster->sprite->pos, DIM(32, 32));
effect_damage_surroundings(&monster->sprite->pos,
matrix,
player,
&player->stats,
player_has_artifact(player, EXPLOSIVE_KILLS),
0,
false);
}
if (monster->stats.hp > 0) { if (monster->stats.hp > 0) {
if (get_random(10) < player_has_artifact(player, PUSH_BACK)) { if (get_random(10) < player_has_artifact(player, PUSH_BACK)) {
@ -169,7 +181,7 @@ on_monster_collision(Player *player,
action_spent(player); action_spent(player);
} }
static void static void
player_pickup_artifacts(Player *player, RoomSpace *space) player_pickup_artifacts(Player *player, RoomSpace *space)
{ {
LinkedList *artifacts = space->artifacts; LinkedList *artifacts = space->artifacts;
@ -179,7 +191,7 @@ player_pickup_artifacts(Player *player, RoomSpace *space)
} }
} }
static void static void
player_interact_objects(Player *player, RoomSpace *space) player_interact_objects(Player *player, RoomSpace *space)
{ {
LinkedList *objects = space->objects; LinkedList *objects = space->objects;
@ -189,7 +201,7 @@ player_interact_objects(Player *player, RoomSpace *space)
} }
} }
static void static void
player_collect_items(Player *player, RoomSpace *space) player_collect_items(Player *player, RoomSpace *space)
{ {
LinkedList *items = space->items; LinkedList *items = space->items;
@ -200,7 +212,7 @@ player_collect_items(Player *player, RoomSpace *space)
} }
} }
static void static void
player_interact_traps_and_pits(Player *player, RoomSpace *space) player_interact_traps_and_pits(Player *player, RoomSpace *space)
{ {
if (space->lethal) { if (space->lethal) {
@ -212,7 +224,7 @@ player_interact_traps_and_pits(Player *player, RoomSpace *space)
} }
} }
static bool static bool
player_has_collided(Player *p, RoomSpace *space) player_has_collided(Player *p, RoomSpace *space)
{ {
if (space->occupied) if (space->occupied)
@ -221,7 +233,7 @@ player_has_collided(Player *p, RoomSpace *space)
return !p->phase_count && space->monster && space->monster->sprite->state != SPRITE_STATE_FALLING; return !p->phase_count && space->monster && space->monster->sprite->state != SPRITE_STATE_FALLING;
} }
static bool static bool
has_collided(Player *player, RoomMatrix *matrix, Vector2d direction) has_collided(Player *player, RoomMatrix *matrix, Vector2d direction)
{ {
Position roomCoord = position_to_room_coords(&player->sprite->pos); Position roomCoord = position_to_room_coords(&player->sprite->pos);
@ -254,7 +266,7 @@ has_collided(Player *player, RoomMatrix *matrix, Vector2d direction)
else { else {
player_collect_items(player, space); player_collect_items(player, space);
player_pickup_artifacts(player, space); player_pickup_artifacts(player, space);
// If not phased or phase will end this turn, react to traps and pits // If not phased or phase will end this turn, react to traps and pits
if (!player->phase_count || (player->phase_count == 1 && player->stats.speed == (player->stat_data.steps + 1))) { if (!player->phase_count || (player->phase_count == 1 && player->stats.speed == (player->stat_data.steps + 1))) {
player_interact_objects(player, space); player_interact_objects(player, space);
@ -264,7 +276,7 @@ has_collided(Player *player, RoomMatrix *matrix, Vector2d direction)
} }
} }
static void static void
set_clip_for_direction(Player *player, Vector2d *direction) set_clip_for_direction(Player *player, Vector2d *direction)
{ {
if (vector2d_equals(*direction, VECTOR2D_LEFT)) if (vector2d_equals(*direction, VECTOR2D_LEFT))
@ -277,7 +289,7 @@ set_clip_for_direction(Player *player, Vector2d *direction)
player->sprite->clip.y = 0; player->sprite->clip.y = 0;
} }
void void
player_turn(Player *player, Vector2d *direction) player_turn(Player *player, Vector2d *direction)
{ {
set_clip_for_direction(player, direction); set_clip_for_direction(player, direction);
@ -304,7 +316,7 @@ player_turn(Player *player, Vector2d *direction)
} }
} }
static void static void
move(Player *player, RoomMatrix *matrix, Vector2d direction) move(Player *player, RoomMatrix *matrix, Vector2d direction)
{ {
player_turn(player, &direction); player_turn(player, &direction);
@ -326,12 +338,12 @@ move(Player *player, RoomMatrix *matrix, Vector2d direction)
lastSpace->trap == NULL && lastSpace->trap == NULL &&
lastSpace->objects == NULL && lastSpace->objects == NULL &&
lastSpace->items == NULL lastSpace->items == NULL
) )
map_trigger_tile_fall(lastSpace->tile); map_trigger_tile_fall(lastSpace->tile);
} }
} }
void void
player_sip_health(Player *player) player_sip_health(Player *player)
{ {
bool hasSips = player->class == MAGE ? bool hasSips = player->class == MAGE ?
@ -350,7 +362,7 @@ player_sip_health(Player *player)
} }
} }
static Vector2d static Vector2d
read_direction_from(Input *input) read_direction_from(Input *input)
{ {
if (input_key_is_pressed(input, KEY_LEFT)) if (input_key_is_pressed(input, KEY_LEFT))
@ -365,7 +377,7 @@ read_direction_from(Input *input)
return VECTOR2D_NODIR; return VECTOR2D_NODIR;
} }
static void static void
handle_next_move(UpdateData *data) handle_next_move(UpdateData *data)
{ {
static unsigned int step = 1; static unsigned int step = 1;
@ -405,7 +417,7 @@ handle_next_move(UpdateData *data)
} }
} }
static void static void
use_skill(Skill *skill, SkillData *skillData) use_skill(Skill *skill, SkillData *skillData)
{ {
skill->active = false; skill->active = false;
@ -415,7 +427,7 @@ use_skill(Skill *skill, SkillData *skillData)
skill->resetCountdown = skill->resetTime; skill->resetCountdown = skill->resetTime;
} }
static void static void
check_skill_activation(UpdateData *data) check_skill_activation(UpdateData *data)
{ {
// TODO(Linus): This could be "smarter" // TODO(Linus): This could be "smarter"
@ -456,7 +468,7 @@ check_skill_activation(UpdateData *data)
} }
} }
static bool static bool
check_skill_trigger(UpdateData *data) check_skill_trigger(UpdateData *data)
{ {
Player *player = data->player; Player *player = data->player;
@ -484,7 +496,7 @@ check_skill_trigger(UpdateData *data)
return true; return true;
} }
static void static void
build_sword_animation(Player *p, SDL_Renderer *renderer) build_sword_animation(Player *p, SDL_Renderer *renderer)
{ {
animation_load_texture(p->swordAnimation, "Extras/SwordSwing.png", renderer); animation_load_texture(p->swordAnimation, "Extras/SwordSwing.png", renderer);
@ -502,7 +514,7 @@ build_sword_animation(Player *p, SDL_Renderer *renderer)
p->swordAnimation->sprite->rotationPoint = (SDL_Point) { 16, 16 }; p->swordAnimation->sprite->rotationPoint = (SDL_Point) { 16, 16 };
} }
Player* Player*
player_create(class_t class, Camera *cam) player_create(class_t class, Camera *cam)
{ {
Player *player = malloc(sizeof(Player)); Player *player = malloc(sizeof(Player));
@ -584,7 +596,7 @@ player_create(class_t class, Camera *cam)
return player; return player;
} }
void void
player_reset_on_levelchange(Player *player) player_reset_on_levelchange(Player *player)
{ {
player->sprite->pos = (Position) { player->sprite->pos = (Position) {
@ -602,7 +614,7 @@ ExperienceData player_get_xp_data(Player *p)
return data; return data;
} }
void void
player_monster_kill_check(Player *player, Monster *monster) player_monster_kill_check(Player *player, Monster *monster)
{ {
if (!monster) if (!monster)
@ -642,7 +654,7 @@ player_monster_kill_check(Player *player, Monster *monster)
} }
} }
void void
player_hit(Player *p, unsigned int dmg) player_hit(Player *p, unsigned int dmg)
{ {
if (dmg > 0) { if (dmg > 0) {
@ -666,7 +678,7 @@ player_hit(Player *p, unsigned int dmg)
} }
void void
player_render(Player *player, Camera *cam) player_render(Player *player, Camera *cam)
{ {
sprite_set_alpha(player->sprite, player->phase_count ? 150 : 255); sprite_set_alpha(player->sprite, player->phase_count ? 150 : 255);
@ -679,25 +691,25 @@ player_render(Player *player, Camera *cam)
} }
} }
void void
player_render_toplayer(Player *player, Camera *camera) player_render_toplayer(Player *player, Camera *camera)
{ {
animation_render(player->swordAnimation, camera); animation_render(player->swordAnimation, camera);
} }
void void
player_reset_steps(Player *p) player_reset_steps(Player *p)
{ {
p->stat_data.steps = 0; p->stat_data.steps = 0;
} }
static void static void
reset_dagger_skill(Player *p) reset_dagger_skill(Player *p)
{ {
p->skills[3]->resetCountdown = 0; p->skills[3]->resetCountdown = 0;
} }
void void
player_update(UpdateData *data) player_update(UpdateData *data)
{ {
Player *player = data->player; Player *player = data->player;
@ -737,7 +749,7 @@ player_update(UpdateData *data)
animation_update(player->swordAnimation); animation_update(player->swordAnimation);
} }
static void static void
player_reset(Player *player) player_reset(Player *player)
{ {
for (size_t i = 0; i < LAST_ARTIFACT_EFFECT; ++i) for (size_t i = 0; i < LAST_ARTIFACT_EFFECT; ++i)
@ -748,7 +760,7 @@ player_reset(Player *player)
projectile_destroy(linkedlist_pop(&player->projectiles)); projectile_destroy(linkedlist_pop(&player->projectiles));
} }
void void
player_destroy(Player *player) player_destroy(Player *player)
{ {
player_reset(player); player_reset(player);
@ -768,19 +780,19 @@ player_destroy(Player *player)
free(player); free(player);
} }
bool bool
player_turn_over(Player *player) player_turn_over(Player *player)
{ {
return player->stat_data.steps >= player->stats.speed; return player->stat_data.steps >= player->stats.speed;
} }
Uint32 Uint32
player_has_artifact(Player *p, MagicalEffect effect) player_has_artifact(Player *p, MagicalEffect effect)
{ {
return p->equipment.artifacts[effect].level; return p->equipment.artifacts[effect].level;
} }
void void
player_add_artifact(Player *p, Artifact *a) player_add_artifact(Player *p, Artifact *a)
{ {
if (a->price > p->gold) { if (a->price > p->gold) {
@ -810,7 +822,7 @@ player_add_artifact(Player *p, Artifact *a)
p->equipment.hasArtifacts = true; p->equipment.hasArtifacts = true;
} }
void void
player_set_falling(Player *player) player_set_falling(Player *player)
{ {
mixer_play_effect(FALL0 + get_random(1)); mixer_play_effect(FALL0 + get_random(1));

View File

@ -28,6 +28,8 @@
#include "item_builder.h" #include "item_builder.h"
#include "random.h" #include "random.h"
#include "update_data.h" #include "update_data.h"
#include "effect_util.h"
#include "particle_engine.h"
static void static void
onDaggerRender(Sprite *s) onDaggerRender(Sprite *s)
@ -95,6 +97,22 @@ clear_processed_spaces(Projectile *p)
sizeof(p->processedSpaces[0][0]) * MAP_ROOM_WIDTH * MAP_ROOM_HEIGHT); sizeof(p->processedSpaces[0][0]) * MAP_ROOM_WIDTH * MAP_ROOM_HEIGHT);
} }
static void
perform_dagger_explosion(Player *player, RoomMatrix *rm, Position *collisionPos)
{
if (player_has_artifact(player, VOLATILE_DAGGERS)) {
mixer_play_effect(EXPLOSION_EFFECT);
particle_engine_fire_explosion(*collisionPos, DIM(32, 32));
effect_damage_surroundings(collisionPos,
rm,
player,
&player->stats,
player_has_artifact(player, VOLATILE_DAGGERS),
0,
false);
}
}
void void
projectile_update(Projectile *p, UpdateData *data) projectile_update(Projectile *p, UpdateData *data)
{ {
@ -132,6 +150,7 @@ projectile_update(Projectile *p, UpdateData *data)
if (result.dmg > 0) { if (result.dmg > 0) {
gui_log("Your dagger pierced %s for %u damage", space->monster->lclabel, result.dmg); gui_log("Your dagger pierced %s for %u damage", space->monster->lclabel, result.dmg);
data->player->stat_data.hits += 1; data->player->stat_data.hits += 1;
perform_dagger_explosion(data->player, data->matrix, &collisionPos);
} else { } else {
gui_log("%s dodged your dagger", space->monster->label); gui_log("%s dodged your dagger", space->monster->label);
} }