comparison libmlk-adventure/adventure/state/splashscreen.c @ 259:16be1ad3ddba

adventure: start working on maps and teleport
author David Demelier <markand@malikania.fr>
date Sun, 06 Dec 2020 11:22:03 +0100
parents 71b3b7036de7
children cd5bdb995052
comparison
equal deleted inserted replaced
258:f978fa0137ce 259:16be1ad3ddba
38 #include "splashscreen.h" 38 #include "splashscreen.h"
39 #include "mainmenu.h" 39 #include "mainmenu.h"
40 40
41 #define DELAY 3000 41 #define DELAY 3000
42 42
43 struct splashscreen { 43 struct self {
44 struct state state;
44 struct texture tex; 45 struct texture tex;
45 int x; 46 int x;
46 int y; 47 int y;
47 struct state *next;
48 unsigned int elapsed; 48 unsigned int elapsed;
49 }; 49 };
50 50
51 static struct splashscreen * 51 static void
52 init(struct state *next) 52 start(struct state *state)
53 { 53 {
54 struct splashscreen *splash; 54 struct self *self = state->data;
55 struct font font; 55 struct font font;
56
57 splash = alloc_new0(sizeof (*splash));
58 splash->next = next;
59 56
60 if (!font_openmem(&font, fonts_cubic, sizeof (fonts_cubic), 80)) 57 if (!font_openmem(&font, fonts_cubic, sizeof (fonts_cubic), 80))
61 panic(); 58 panic();
62 59
63 font.style = FONT_STYLE_ANTIALIASED; 60 font.style = FONT_STYLE_ANTIALIASED;
64 61
65 if (!font_render(&font, &splash->tex, "malikania", 0x19332dff)) 62 if (!font_render(&font, &self->tex, "malikania", 0x19332dff))
66 panic(); 63 panic();
67 64
68 align(ALIGN_CENTER, &splash->x, &splash->y, splash->tex.w, splash->tex.h, 65 align(ALIGN_CENTER, &self->x, &self->y, self->tex.w, self->tex.h,
69 0, 0, window.w, window.h); 66 0, 0, window.w, window.h);
70 font_finish(&font); 67 font_finish(&font);
71
72 return splash;
73 } 68 }
74 69
75 static void 70 static void
76 update(struct state *state, unsigned int ticks) 71 update(struct state *state, unsigned int ticks)
77 { 72 {
78 struct splashscreen *splash = state->data; 73 struct self *self = state->data;
79 74
80 splash->elapsed += ticks; 75 self->elapsed += ticks;
81 76
82 if (splash->elapsed >= DELAY) 77 if (self->elapsed >= DELAY)
83 game_switch(splash->next, false); 78 game_switch(mainmenu_state_new(), false);
84 } 79 }
85 80
86 static void 81 static void
87 draw(struct state *state) 82 draw(struct state *state)
88 { 83 {
89 struct splashscreen *splash = state->data; 84 struct self *self = state->data;
90 85
91 painter_set_color(0xffffffff); 86 painter_set_color(0xffffffff);
92 painter_clear(); 87 painter_clear();
93 texture_draw(&splash->tex, splash->x, splash->y); 88 texture_draw(&self->tex, self->x, self->y);
94 painter_present(); 89 painter_present();
95 } 90 }
96 91
97 static void 92 static void
98 finish(struct state *state) 93 finish(struct state *state)
99 { 94 {
100 struct splashscreen *splash = state->data; 95 struct self *self = state->data;
101 96
102 texture_finish(&splash->tex); 97 texture_finish(&self->tex);
103 98
104 free(splash); 99 free(self);
105 memset(state, 0, sizeof (*state));
106 } 100 }
107 101
108 void 102 struct state *
109 splashscreen_state(struct state *state, struct state *next) 103 splashscreen_state_new(void)
110 { 104 {
111 assert(state); 105 struct self *self;
112 assert(next);
113 106
114 memset(state, 0, sizeof (*state)); 107 self = alloc_new0(sizeof (*self));
115 state->data = init(next); 108 self->state.data = self;
116 state->update = update; 109 self->state.start = start;
117 state->draw = draw; 110 self->state.update = update;
118 state->finish = finish; 111 self->state.draw = draw;
112 self->state.finish = finish;
113
114 return &self->state;
119 } 115 }