Centered trochoids: Sound effects on release

This commit is contained in:
Bill Kendrick 2024-01-07 13:13:15 -08:00
parent 12b9c65536
commit 31ceeff596
4 changed files with 50 additions and 3 deletions

View file

@ -65,7 +65,12 @@ https://tuxpaint.org/
available, each with differing pen positions.
+ Code: Bill Kendrick <bill@newbreedsoftware.com>
+ WIP - Needs icons
+ WIP - Needs sounds
+ WIP Sounds:
- Drag: TBD
- Epitrochoid draw "celtic_harp_c3.wav" &
Hypotrochoid draw "celtic_harp_c2.wav"
both CC0 1.0 Universal
by Daphne Farazi (https://soundcloud.com/daphnefarazi)
* Improvements to "Text" & "Label" tools:
---------------------------------------

Binary file not shown.

Binary file not shown.

View file

@ -133,7 +133,8 @@ const char *tool_descriptions[NUM_TOOLS] = {
/* Sound effects (same for everyone) */
enum {
SND_DRAW_CLICK,
SND_DRAW_RELEASE,
SND_DRAW_RELEASE_EPITROCHOID,
SND_DRAW_RELEASE_HYPOTROCHOID,
NUM_SNDS
};
@ -141,7 +142,8 @@ Mix_Chunk *sound_effects[NUM_SNDS];
const char *sound_filenames[NUM_SNDS] = {
"n_pt_persp_click.ogg", // FIXME
"n_pt_persp_release.ogg", // FIXME
"epitrochoid.ogg",
"hypotrochoid.ogg",
};
Uint8 trochoids_size = 1;
@ -424,11 +426,51 @@ void trochoids_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot,
int x, int y, SDL_Rect * update_rect)
{
int tool, snd_idx, R, vol, pan;
/* If they clicked & released with no drag,
ignore the (x,y) we received; we want the
'default' offset to get a reasonably pleasant
shape -- for users who tried clicking w/o dragging */
if (dragged == 0) {
x += (canvas->w / 20);
y += (canvas->h / 20);
}
/* Pick which sound to play */
tool = which_to_tool[which];
if (tool == TOOL_EPITROCHOID_SIZES ||
tool == TOOL_EPITROCHOID_NOSIZES_1 ||
tool == TOOL_EPITROCHOID_NOSIZES_2 ||
tool == TOOL_EPITROCHOID_NOSIZES_3) {
snd_idx = SND_DRAW_RELEASE_EPITROCHOID;
} else {
snd_idx = SND_DRAW_RELEASE_HYPOTROCHOID;
}
/* Volume based on the radius of the stator (fixed circle);
larger = louder */
R = abs(trochoids_x - x);
if (R < 20) {
R = 20;
} else if (R > canvas->w) {
R = canvas->w;
}
vol = (255 * R * 2) / canvas->w;
if (vol > 255) {
vol = 255;
}
/* (Stop previous sound if they made another shape quickly;
the sound effect lingers & we want to start playing again,
else it will seem like the sound only happens intermittently) */
api->stopsound();
/* Panning based on the left/right position of the shape */
pan = 128; /* FIXME */
api->playsound(sound_effects[snd_idx], pan, vol);
/* Draw it (no guides, this time!) */
trochoids_work(api, which, canvas, snapshot, x, y, update_rect, 0);
}