From 736eb79996490e1b9ad0d437d12cf90a0512a5d3 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Wed, 8 Aug 2018 14:46:59 +0200 Subject: [PATCH] Continues #2: Artifacts - Adds sparkle effect on artifacts - Implements TRAP_AVOIDANCE, IMPROVED_HEARING --- src/artifact.c | 30 +++++++++++++++++++++++++++++- src/defines.h | 1 + src/main.c | 1 + src/monster.c | 34 ++++++++++++++++++++++++++-------- src/particle_engine.c | 32 +++++++------------------------- src/particle_engine.h | 2 +- src/projectile.c | 13 +++++++------ src/skillbar.c | 2 +- src/trap.c | 12 ++++++++++-- 9 files changed, 83 insertions(+), 44 deletions(-) diff --git a/src/artifact.c b/src/artifact.c index 48ba651..6f4555e 100644 --- a/src/artifact.c +++ b/src/artifact.c @@ -19,46 +19,70 @@ #include "artifact.h" #include "util.h" #include "texturecache.h" +#include "particle_engine.h" static void artifact_set_effect(Artifact *a, MagicalEffect effect) { + Texture *t; + a->effect = effect; switch (effect) { case IMPROVED_HEARING: a->info.name = "Potion of ear juice"; a->info.desc = "Your hearing is slightly improved"; + t = texturecache_add("Items/Potion.png"); + sprite_set_texture(a->sprite, t, 0); + a->sprite->clip = CLIP16(7*16, 4*16); break; case TRAP_AVOIDANCE: a->info.name = "Boot with nails inside"; a->info.desc = "You are lighter on your feet"; + t = texturecache_add("Items/Boot.png"); + sprite_set_texture(a->sprite, t, 0); + a->sprite->clip = CLIP16(5*16, 0); break; case PIERCING_DAGGERS: a->info.name = "Whetstone"; a->info.desc = "Your daggers are sharper"; - Texture *t = texturecache_add("Items/Rock.png"); + t = texturecache_add("Items/Rock.png"); sprite_set_texture(a->sprite, t, 0); a->sprite->clip = CLIP16(0, 0); break; case CHARGE_THROUGH: a->info.name = "Greasy shield"; a->info.desc = "You glide through obstructions"; + t = texturecache_add("Items/Shield.png"); + sprite_set_texture(a->sprite, t, 0); + a->sprite->clip = CLIP16(16, 0); break; case PUSH_BACK: a->info.name = "Glove of strength"; a->info.desc = "Your arm is stronger"; + t = texturecache_add("Items/Glove.png"); + sprite_set_texture(a->sprite, t, 0); + a->sprite->clip = CLIP16(0, 0); break; case DAGGER_RECOVERY: a->info.name = "Forging hammer"; a->info.desc = "Your daggers are more durable"; + t = texturecache_add("Items/LongWep.png"); + sprite_set_texture(a->sprite, t, 0); + a->sprite->clip = CLIP16(0, 6*16); break; case INCREASED_STUN: a->info.name = "Solid shield"; a->info.desc = "Your shield is harder"; + t = texturecache_add("Items/Shield.png"); + sprite_set_texture(a->sprite, t, 0); + a->sprite->clip = CLIP16(4*16, 0); break; case FEAR_INDUCING: a->info.name = "Ugly shirt"; a->info.desc = "You look disgusting"; + t = texturecache_add("Items/Armor.png"); + sprite_set_texture(a->sprite, t, 0); + a->sprite->clip = CLIP16(6*16, 8*16); break; default: break; @@ -89,6 +113,10 @@ void artifact_render(Artifact *a, Camera *cam) { sprite_render(a->sprite, cam); + Position pos = a->sprite->pos; + pos.x += 4; + pos.y += 4; + particle_engine_sparkle(pos, (Dimension) { 24, 24 }, C_PURPLE, false); } void diff --git a/src/defines.h b/src/defines.h index bf47b98..32bfad1 100644 --- a/src/defines.h +++ b/src/defines.h @@ -67,6 +67,7 @@ #define C_BLUE (SDL_Color) { 0, 0, 255, 255 } #define C_YELLOW (SDL_Color) { 255, 255, 0, 255 } #define C_BLACK (SDL_Color) { 0, 0, 0, 255 } +#define C_PURPLE (SDL_Color) { 137, 16, 229, 255 } // MSVC seems to have min/max defined. // Haven't looked into it further. diff --git a/src/main.c b/src/main.c index bc567e8..a5dd2ac 100644 --- a/src/main.c +++ b/src/main.c @@ -619,6 +619,7 @@ run_menu(void) SDL_RenderClear(gRenderer); SDL_RenderSetViewport(gRenderer, &menuViewport); map_render(gMap, gCamera); + map_render_top_layer(gMap, gCamera); roommatrix_render_lightmap(gRoomMatrix, gCamera); SDL_RenderSetViewport(gRenderer, NULL); diff --git a/src/monster.c b/src/monster.c index 7ab1819..77e1955 100644 --- a/src/monster.c +++ b/src/monster.c @@ -376,7 +376,6 @@ monster_coward_walk(Monster *m, RoomMatrix *rm) bool monster_move(Monster *m, RoomMatrix *rm) { - Position monsterRoomPos; if (m->state.current == STUNNED) { if (m->state.stepsSinceChange < 3) { @@ -390,9 +389,10 @@ monster_move(Monster *m, RoomMatrix *rm) monster_behaviour_check(m, rm); - monsterRoomPos = position_to_matrix_coords(&m->sprite->pos); - rm->spaces[monsterRoomPos.x][monsterRoomPos.y].occupied = false; - rm->spaces[monsterRoomPos.x][monsterRoomPos.y].monster = NULL; + Position originalPosition = + position_to_matrix_coords(&m->sprite->pos); + rm->spaces[originalPosition.x][originalPosition.y].occupied = false; + rm->spaces[originalPosition.x][originalPosition.y].monster = NULL; switch (m->state.current) { case PASSIVE: @@ -413,9 +413,25 @@ monster_move(Monster *m, RoomMatrix *rm) monster_update_pos(m, m->sprite->pos); - monsterRoomPos = position_to_matrix_coords(&m->sprite->pos); - rm->spaces[monsterRoomPos.x][monsterRoomPos.y].occupied = true; - rm->spaces[monsterRoomPos.x][monsterRoomPos.y].monster = m; + Position newPos = position_to_matrix_coords(&m->sprite->pos); + rm->spaces[newPos.x][newPos.y].occupied = true; + rm->spaces[newPos.x][newPos.y].monster = m; + + if (!position_equals(&originalPosition, &newPos)) { + Player *p = rm->spaces[rm->playerRoomPos.x][rm->playerRoomPos.y].player; + if (p) { + Uint32 range = 3 + player_has_artifact(p, IMPROVED_HEARING) * 2; + bool withinHearingDist = + range > 3 && position_proximity(range, + &newPos, + &rm->playerRoomPos); + + RoomSpace *space = &rm->spaces[newPos.x][newPos.y]; + if (space->light < 100 && withinHearingDist) { + actiontextbuilder_create_text("!", C_WHITE, &m->sprite->pos); + } + } + } m->steps++; if (m->steps >= m->stats.speed) { @@ -538,7 +554,9 @@ monster_drop_loot(Monster *monster, Map *map, Player *player) linkedlist_append(&map->items, container); } - Artifact *a = artifact_create(PIERCING_DAGGERS); + // TODO: This should not occur every time + // Debug code. + Artifact *a = artifact_create(TRAP_AVOIDANCE); a->sprite->pos = monster->sprite->pos; linkedlist_append(&map->artifacts, a); } diff --git a/src/particle_engine.c b/src/particle_engine.c index f2f18b7..afefceb 100644 --- a/src/particle_engine.c +++ b/src/particle_engine.c @@ -82,27 +82,6 @@ create_rect_particle(void) return p; } -/* - * Not used right now, hide for now -static Particle * -create_line_particle(void) -{ - Particle *p = ec_malloc(sizeof(Particle)); - - p->type = LINE; - p->velocity = VECTOR2D_NODIR; - p->movetime = 100; - p->lifetime = 100; - p->fixed = false; - p->blend_mode = SDL_BLENDMODE_MOD; - p->color = C_WHITE; - p->particle.line.startPos = (Position) { 0, 0 }; - p->particle.line.endPos = (Position) { 32, 32 }; - - return p; -} -*/ - static void check_engine(void) { @@ -243,7 +222,7 @@ particle_engine_speed_lines(Position pos, Dimension dim, bool horizontal) } void -particle_engine_sparkle(Position pos, Dimension dim) +particle_engine_sparkle(Position pos, Dimension dim, SDL_Color color, bool global) { for (unsigned int i = 0; i < 10; ++i) { int x, y, yv, alpha; @@ -266,10 +245,13 @@ particle_engine_sparkle(Position pos, Dimension dim) p->movetime = lt; p->lifetime = lt; p->blend_mode = SDL_BLENDMODE_BLEND; - p->color = C_WHITE; + p->color = color; p->color.a = (Uint8) alpha; - p->fixed = true; - linkedlist_append(&engine->global_particles, p); + p->fixed = global; + if (global) + linkedlist_append(&engine->global_particles, p); + else + linkedlist_append(&engine->game_particles, p); } } diff --git a/src/particle_engine.h b/src/particle_engine.h index 09c8f28..55f0d48 100644 --- a/src/particle_engine.h +++ b/src/particle_engine.h @@ -41,7 +41,7 @@ void particle_engine_speed_lines(Position, Dimension, bool horizontal); void -particle_engine_sparkle(Position, Dimension); +particle_engine_sparkle(Position, Dimension, SDL_Color, bool global); void particle_engine_wind(Vector2d direction); diff --git a/src/projectile.c b/src/projectile.c index 271db68..4aa1d59 100644 --- a/src/projectile.c +++ b/src/projectile.c @@ -108,17 +108,18 @@ projectile_update(Projectile *p, UpdateData *data) if (dmg > 0) { gui_log("Your dagger pierced %s for %u damage", space->monster->lclabel, dmg); data->player->stat_data.hits += 1; + } else { + gui_log("%s dodged your dagger", space->monster->label); } - if (get_random(5) == 0 - || get_random(5) < player_has_artifact(data->player, DAGGER_RECOVERY)) { + monster_hit(space->monster, dmg); + player_monster_kill_check(data->player, space->monster); + alive = player_has_artifact(data->player, PIERCING_DAGGERS) > p->collisionCount; + if (!alive && (get_random(5) == 0 + || get_random(5) < player_has_artifact(data->player, DAGGER_RECOVERY))) { Item *item = item_builder_build_item(DAGGER, 1); item->sprite->pos = space->monster->sprite->pos; linkedlist_append(&data->map->items, item); } - monster_hit(space->monster, dmg); - player_monster_kill_check(data->player, space->monster); - - alive = player_has_artifact(data->player, PIERCING_DAGGERS) > p->collisionCount; } mixer_play_effect(SWORD_HIT); p->alive = alive; diff --git a/src/skillbar.c b/src/skillbar.c index ea20d73..0ef70e3 100644 --- a/src/skillbar.c +++ b/src/skillbar.c @@ -235,7 +235,7 @@ render_skill_sparkles(SkillBar *bar, Player *player) continue; pos.x += 32 * i; - particle_engine_sparkle(pos, dim); + particle_engine_sparkle(pos, dim, C_WHITE, true); } } diff --git a/src/trap.c b/src/trap.c index c216c67..03eca20 100644 --- a/src/trap.c +++ b/src/trap.c @@ -20,6 +20,8 @@ #include "trap.h" #include "util.h" #include "gui.h" +#include "random.h" +#include "actiontextbuilder.h" Trap * trap_create() @@ -35,14 +37,20 @@ trap_create() void trap_activate(Trap *trap, Player *player) { - player->stats.hp -= trap->damage; - player_hit(player, trap->damage); if (!trap->sprite->animate) { gui_log("A trap is sprung!"); trap->sprite->animate = true; } else { gui_log("You step in a trap!"); } + + if (get_random(10) > 2 * player_has_artifact(player, TRAP_AVOIDANCE)) { + player->stats.hp -= trap->damage; + player_hit(player, trap->damage); + } else { + actiontextbuilder_create_text("Dodged", C_YELLOW, &player->sprite->pos); + gui_log("You nimbly avoid getting hurt by the trap"); + } } void