Skip to content

Commit 8e3b412

Browse files
authored
Spread loot to surrounding spaces (#101)
Instead of grouping loot into a sack it will now be "dropped" randomly to surrounding spaces around the monster. To facilitate this sprite interpolation has been added to the engine. Sprites can be interpolated for position, dimension and rotation. Introduces loot.c/loot.h which handle loot placement and drops. All dropped items now interpolate to their destination. Documentation for position functions has been updated and the function artifact_update has been introduced. Sound effects have been added to most item drops.
1 parent 09fab1b commit 8e3b412

30 files changed

+689
-184
lines changed

assets/Sounds/FX/coin2.wav

282 KB
Binary file not shown.

assets/Sounds/FX/coin3.wav

87.7 KB
Binary file not shown.

assets/Sounds/FX/flesh_drop1.wav

118 KB
Binary file not shown.

assets/Sounds/FX/flesh_drop2.wav

112 KB
Binary file not shown.

assets/Sounds/FX/metal-small3.wav

130 KB
Binary file not shown.

assets/Sounds/FX/potion_drop.wav

146 KB
Binary file not shown.

src/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
file(GLOB SOURCE_FILES CONFIGURE_DEPENDS *.c)
22
target_sources(${PROJECT_NAME} PRIVATE ${SOURCE_FILES})
33

4+
if (DEBUG_BUILD)
5+
target_sources(${PROJECT_NAME} PRIVATE debug/debug.c)
6+
endif ()
7+
48
if (STEAM)
59
target_sources(${PROJECT_NAME} PRIVATE steam/steamworks_api_wrapper.c)
610
endif ()

src/artifact.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ artifact_create_random(Player *p, Uint8 level)
198198
void
199199
artifact_add_price(Artifact *a, unsigned int price)
200200
{
201-
201+
202202
Sprite *sprite = sprite_util_create_text_sprite("GUI/SDS_8x8.ttf",
203203
8,
204204
C_YELLOW,
@@ -310,6 +310,16 @@ artifact_copy(const Artifact *a)
310310
return new;
311311
}
312312

313+
void
314+
artifact_update(Artifact *a, UpdateData *ud)
315+
{
316+
sprite_update(a->sprite, ud);
317+
if (a->priceSprite)
318+
a->priceSprite->pos = a->sprite->pos;
319+
if (a->levelSprite)
320+
a->levelSprite->pos = a->sprite->pos;
321+
}
322+
313323
void
314324
artifact_render(Artifact *a, Camera *cam)
315325
{
@@ -319,11 +329,9 @@ artifact_render(Artifact *a, Camera *cam)
319329
pos.y += 4;
320330
particle_engine_sparkle(pos, DIM(24, 24), C_PURPLE, false);
321331
if (a->priceSprite) {
322-
a->priceSprite->pos = a->sprite->pos;
323332
sprite_render(a->priceSprite, cam);
324333
}
325334
if (a->levelSprite) {
326-
a->levelSprite->pos = a->sprite->pos;
327335
sprite_render(a->levelSprite, cam);
328336
}
329337
}

src/artifact.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ artifact_create(MagicalEffect);
6868
Artifact *
6969
artifact_copy(const Artifact*);
7070

71+
void
72+
artifact_update(Artifact*, struct UpdateData*);
73+
7174
void
7275
artifact_render(Artifact*, Camera*);
7376

src/debug/debug.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* BreakHack - A dungeone crawler RPG
3+
* Copyright (C) 2025 Linus Probert <linus.probert@gmail.com>
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
#include "debug.h"
19+
#include "../sprite.h"
20+
#include "../texturecache.h"
21+
22+
static Sprite *sprite = NULL;
23+
24+
void
25+
debug_update(UpdateData *ud)
26+
{
27+
/* Kill a monster when clicked */
28+
if (input_mousebutton_is_pressed(ud->input, MBUTTON_LEFT)) {
29+
Position mpos = POS(ud->input->mouseX, ud->input->mouseY);
30+
31+
Position mat_pos = position_to_matrix_coords(&mpos);
32+
Monster *monster = ud->matrix->spaces[mat_pos.x][mat_pos.y].monster;
33+
if (monster) {
34+
monster->stats.hp = 0;
35+
} else {
36+
if (sprite) {
37+
sprite_destroy(sprite);
38+
}
39+
sprite = sprite_create();
40+
sprite->textures[0] = texturecache_add("Items/Amulet.png");
41+
sprite->clip = CLIP16(0, 0);
42+
sprite->dim = DIM(4, 4);
43+
sprite->pos = mpos;
44+
45+
Destination dest = {
46+
.pos = POS(mpos.x + 64, mpos.y + 64),
47+
.dim = DIM(32, 32),
48+
.angle = 0.0f,
49+
.time_ms = 400,
50+
};
51+
52+
sprite_interpolate_to(sprite, &dest);
53+
}
54+
}
55+
56+
if (sprite) {
57+
sprite_update(sprite, ud);
58+
}
59+
}
60+
61+
void
62+
debug_render(Camera *cam)
63+
{
64+
if (sprite)
65+
sprite_render(sprite, cam);
66+
}

0 commit comments

Comments
 (0)