Skip to content

Commit c36dfdf

Browse files
committed
Spread loot to surrounding spaces
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 bec298e commit c36dfdf

29 files changed

+683
-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/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.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
#include "util.h"
22+
23+
static Sprite *sprite = NULL;
24+
25+
void
26+
debug_update(UpdateData *ud)
27+
{
28+
/* Kill a monster when clicked */
29+
if (input_mousebutton_is_pressed(ud->input, MBUTTON_LEFT)) {
30+
Position mpos = POS(ud->input->mouseX, ud->input->mouseY);
31+
32+
Position mat_pos = position_to_matrix_coords(&mpos);
33+
Monster *monster = ud->matrix->spaces[mat_pos.x][mat_pos.y].monster;
34+
if (monster) {
35+
monster->stats.hp = 0;
36+
} else {
37+
if (sprite) {
38+
sprite_destroy(sprite);
39+
}
40+
sprite = sprite_create();
41+
sprite->textures[0] = texturecache_add("Items/Amulet.png");
42+
sprite->clip = CLIP16(0, 0);
43+
sprite->dim = DIM(4, 4);
44+
sprite->pos = mpos;
45+
46+
Destination dest = {
47+
.pos = POS(mpos.x + 64, mpos.y + 64),
48+
.dim = DIM(32, 32),
49+
.angle = 0.0f,
50+
.time_ms = 400,
51+
};
52+
53+
sprite_interpolate_to(sprite, &dest);
54+
}
55+
}
56+
57+
if (sprite) {
58+
sprite_update(sprite, ud);
59+
}
60+
}
61+
62+
void
63+
debug_render(Camera *cam)
64+
{
65+
if (sprite)
66+
sprite_render(sprite, cam);
67+
}

src/debug.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* BreakHack - A dungeone crawler RPG
3+
* Copyright (C) 2018 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+
#ifdef DEBUG
19+
#ifndef _DEBUG_H_
20+
#define _DEBUG_H_
21+
22+
#include "update_data.h"
23+
24+
/**
25+
* \brief Utility function for multi purpose testing
26+
*
27+
* This function is intended for anything required during testing. This is to
28+
* avoid manipulating other systems in order to test functionality.
29+
*
30+
* \param update_data The UpdateData struct
31+
*/
32+
void
33+
debug_update(UpdateData *update_data);
34+
35+
void
36+
debug_render(Camera *cam);
37+
38+
#endif // _DEBUG_H_
39+
#endif // DEBUG
40+

0 commit comments

Comments
 (0)