aboutsummaryrefslogtreecommitdiff
path: root/src/Main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/Main.c')
-rw-r--r--src/Main.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/src/Main.c b/src/Main.c
index a578620..d938a6c 100644
--- a/src/Main.c
+++ b/src/Main.c
@@ -66,6 +66,7 @@ int main(void) {
SDL_SetAtomicInt(&app_running, 1);
if (!SDL_Init(SDL_INIT_VIDEO))
return 1;
+
SDL_Window *window;
SDL_Renderer *renderer;
if (!SDL_CreateWindowAndRenderer("PNDacc", 600, 600, 0, &window, &renderer))
@@ -73,9 +74,13 @@ int main(void) {
SDL_Texture *tex = IMG_LoadTexture(renderer, "profile.png");
if (!tex)
fprintf(stderr, "[ERROR] 'profile.png' not found!\n");
+ SDL_Texture *anger_tex = IMG_LoadTexture(renderer, "assets/emotions/anger.png");
+ if (!anger_tex)
+ fprintf(stderr, "[ERROR] 'assets/emotions/anger.png' not found!\n");
SDL_Thread *audio_thread =
SDL_CreateThread(audio_thread_func, "AudioThread", NULL);
float visual_rms = 0.0f;
+ float anger_alpha = 0.0f;
while (SDL_GetAtomicInt(&app_running)) {
SDL_Event event;
while (SDL_PollEvent(&event)) {
@@ -100,6 +105,7 @@ int main(void) {
"[VIS] vol_norm=%-5.2f stretch_y=%-5.2f squash_x=%-5.2f bob=%-6.1f "
"tilt=%-5.1f\n",
volume_norm, stretch_y, squash_x, bob, tilt);
+ float char_x = 0, char_y = 0, char_w = 0, char_h = 0;
if (tex) {
float img_w, img_h;
SDL_GetTextureSize(tex, &img_w, &img_h);
@@ -108,17 +114,38 @@ int main(void) {
float base_h = img_h * scale;
float final_w = base_w * squash_x;
float final_h = base_h * stretch_y;
- SDL_FRect dst = {300.0f - (final_w / 2.0f), 550.0f - final_h + bob,
- final_w, final_h};
+ char_x = 300.0f - (final_w / 2.0f);
+ char_y = 550.0f - final_h + bob;
+ char_w = final_w;
+ char_h = final_h;
+ SDL_FRect dst = {char_x, char_y, final_w, final_h};
SDL_FPoint origin = {final_w / 2.0f, final_h};
SDL_RenderTextureRotated(renderer, tex, NULL, &dst, (double)tilt, &origin,
SDL_FLIP_NONE);
}
+ float target_alpha = visual_rms > SCREAM_THRESHOLD ? 255.0f : 0.0f;
+ anger_alpha += (target_alpha - anger_alpha) * ANGER_FADE_SPEED;
+ if (anger_tex && anger_alpha > 1.0f) {
+ float anger_w, anger_h;
+ SDL_GetTextureSize(anger_tex, &anger_w, &anger_h);
+ float anger_size = char_w * 0.35f;
+ float anger_scale = anger_size / (anger_h > anger_w ? anger_h : anger_w);
+ float anger_x = char_x + char_w * 0.06f;
+ float anger_y = char_y + char_h * 0.08f;
+ SDL_FRect anger_dst = {anger_x, anger_y,
+ anger_w * anger_scale, anger_h * anger_scale};
+ SDL_FPoint anger_origin = {char_w * 0.44f, char_h * 0.92f};
+ SDL_SetTextureAlphaMod(anger_tex, (uint8_t)anger_alpha);
+ SDL_RenderTextureRotated(renderer, anger_tex, NULL, &anger_dst, (double)tilt,
+ &anger_origin, SDL_FLIP_NONE);
+ }
SDL_RenderPresent(renderer);
SDL_Delay(8);
}
SDL_SetAtomicInt(&app_running, 0);
SDL_WaitThread(audio_thread, NULL);
+ if (anger_tex)
+ SDL_DestroyTexture(anger_tex);
if (tex)
SDL_DestroyTexture(tex);
SDL_DestroyRenderer(renderer);