comparison examples/example-animation/example-animation.c @ 459:541cb950997b

examples: add libmlk-example library
author David Demelier <markand@malikania.fr>
date Sun, 26 Feb 2023 19:44:47 +0100
parents 773a082f0b91
children 5729efd23286
comparison
equal deleted inserted replaced
458:02c1481b7dbb 459:541cb950997b
45 .flags = LABEL_FLAGS_SHADOW 45 .flags = LABEL_FLAGS_SHADOW
46 }; 46 };
47 47
48 static struct state *states[1]; 48 static struct state *states[1];
49 static struct texture numbers; 49 static struct texture numbers;
50 static struct animation animation; 50 static struct mlk_animation animation;
51 static struct sprite sprite; 51 static struct sprite sprite;
52 static int completed = 1; 52 static int completed = 1;
53 53
54 static void 54 static void
55 init(void) 55 init(void)
56 { 56 {
57 if (core_init("fr.malikania", "example-animation") < 0 || ui_init() < 0) 57 if (core_init("fr.malikania", "example-animation") < 0 || ui_init() < 0)
58 panic(); 58 panic();
59 if (window_open("Example - Animation", W, H) < 0) 59 if (window_open("Example - Animation", W, H) < 0)
60 panic(); 60 panic();
61 if (image_openmem(&numbers, assets_numbers, sizeof (assets_numbers)) < 0) 61 if (mlk_image_openmem(&numbers, assets_sprites_numbers, sizeof (assets_sprites_numbers)) < 0)
62 panic(); 62 panic();
63 } 63 }
64 64
65 static void 65 static void
66 handle(struct state *st, const union event *ev) 66 handle(struct state *st, const union mlk_event *ev)
67 { 67 {
68 (void)st; 68 (void)st;
69 69
70 switch (ev->type) { 70 switch (ev->type) {
71 case EVENT_KEYDOWN: 71 case MLK_EVENT_KEYDOWN:
72 switch (ev->key.key) { 72 switch (ev->key.key) {
73 case KEY_SPACE: 73 case MLK_KEY_SPACE:
74 animation_start(&animation); 74 mlk_animation_start(&animation);
75 completed = animation_completed(&animation); 75 completed = mlk_animation_completed(&animation);
76 break; 76 break;
77 default: 77 default:
78 break; 78 break;
79 } 79 }
80 break; 80 break;
81 case EVENT_QUIT: 81 case MLK_EVENT_QUIT:
82 game_quit(); 82 mlk_game_quit();
83 break; 83 break;
84 default: 84 default:
85 break; 85 break;
86 } 86 }
87 } 87 }
90 update(struct state *st, unsigned int ticks) 90 update(struct state *st, unsigned int ticks)
91 { 91 {
92 (void)st; 92 (void)st;
93 93
94 if (!completed) 94 if (!completed)
95 completed = animation_update(&animation, ticks); 95 completed = mlk_animation_update(&animation, ticks);
96 } 96 }
97 97
98 static void 98 static void
99 draw(struct state *st) 99 draw(struct state *st)
100 { 100 {
101 (void)st; 101 (void)st;
102 102
103 painter_set_color(0x4f8fbaff); 103 mlk_painter_set_color(0x4f8fbaff);
104 painter_clear(); 104 mlk_painter_clear();
105 label_draw(&label); 105 label_draw(&label);
106 106
107 if (!completed) 107 if (!completed)
108 animation_draw(&animation, (window.w - sprite.cellw) / 2, (window.h - sprite.cellh) / 2); 108 mlk_animation_draw(&animation, (window.w - sprite.cellw) / 2, (window.h - sprite.cellh) / 2);
109 109
110 painter_present(); 110 mlk_painter_present();
111 } 111 }
112 112
113 static void 113 static void
114 run(void) 114 run(void)
115 { 115 {
118 .update = update, 118 .update = update,
119 .draw = draw 119 .draw = draw
120 }; 120 };
121 121
122 sprite_init(&sprite, &numbers, 48, 48); 122 sprite_init(&sprite, &numbers, 48, 48);
123 animation_init(&animation, &sprite, 1000); 123 mlk_animation_init(&animation, &sprite, 1000);
124 124
125 game_init(states, UTIL_SIZE(states)); 125 mlk_game_init(states, UTIL_SIZE(states));
126 game_push(&state); 126 mlk_game_push(&state);
127 game_loop(); 127 mlk_game_loop();
128 } 128 }
129 129
130 static void 130 static void
131 quit(void) 131 quit(void)
132 { 132 {