]> git.lizzy.rs Git - nothing.git/blob - src/game/credits.c
(#1153) Remove TODO for #1157 (sorry!) and cleanup key handling.
[nothing.git] / src / game / credits.c
1 #include "./credits.h"
2 #include "game/level/background.h"
3 #include "game/sprite_font.h"
4 #include "system/lt.h"
5 #include "system/nth_alloc.h"
6 #include "system/stacktrace.h"
7 #include "system/str.h"
8 #include "system/log.h"
9 #include "ui/wiggly_text.h"
10 #include "config.h"
11
12 #define TITLE_MARGIN_TOP 100.0f
13
14 struct Credits
15 {
16     Lt *lt;
17     Background background;
18     Vec2f camera_position;
19     WigglyText wiggly_text;
20 };
21
22 Credits *create_credits(void)
23 {
24         Lt *lt = create_lt();
25         Credits *credits = PUSH_LT(
26         lt,
27         nth_calloc(1, sizeof(Credits)),
28         free);
29     if (credits == NULL) {
30         RETURN_LT(lt, NULL);
31     }
32     credits->lt = lt;
33
34     credits->background = create_background(hexstr("250741"));
35
36     credits->camera_position = vec(0.0f, 0.0f);
37
38     credits->wiggly_text = (WigglyText) {
39         .text = "Twitch Subs/Contributors",
40         .scale = {8.0f, 8.0f},
41         .color = COLOR_WHITE,
42     };
43
44     return credits;
45 }
46
47 void destroy_credits(Credits *credits)
48 {
49     trace_assert(credits);
50     RETURN_LT0(credits->lt);
51 }
52
53 int credits_render(const Credits *credits, const Camera *camera)
54 {
55     trace_assert(credits);
56     trace_assert(camera);
57
58     const Rect viewport = camera_view_port_screen(camera);
59
60     if (background_render(&credits->background, camera) < 0) {
61         return -1;
62     }
63
64     const Vec2f title_size = wiggly_text_size(&credits->wiggly_text, camera);
65
66     if (wiggly_text_render(
67             &credits->wiggly_text,
68             camera,
69             vec(viewport.w * 0.5f - title_size.x * 0.5f, TITLE_MARGIN_TOP)) < 0) {
70         return -1;
71     }
72     // TODO(#1150): Credits page don't display list of subs and contributors
73     return 0;
74 }
75
76 int credits_update(Credits *credits, Camera *camera, float dt)
77 {
78     trace_assert(credits);
79     trace_assert(camera);
80
81     vec_add(&credits->camera_position,
82             vec(0.0f, 20.0f * dt));
83     camera_center_at(camera, credits->camera_position);
84
85     if (wiggly_text_update(&credits->wiggly_text, dt) < 0) {
86         return -1;
87     }
88
89     return 0;
90 }