comparison libmlk-adventure/adventure/molko.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 bfde372bf152
comparison
equal deleted inserted replaced
258:f978fa0137ce 259:16be1ad3ddba
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */ 17 */
18 18
19 #include <assert.h>
19 #include <stddef.h> 20 #include <stddef.h>
20 #include <setjmp.h> 21 #include <setjmp.h>
22 #include <string.h>
21 #include <locale.h> 23 #include <locale.h>
22 24
23 #include <core/clock.h> 25 #include <core/clock.h>
24 #include <core/core.h> 26 #include <core/core.h>
25 #include <core/event.h> 27 #include <core/event.h>
28 #include <core/image.h>
26 #include <core/panic.h> 29 #include <core/panic.h>
27 #include <core/translate.h> 30 #include <core/translate.h>
28 #include <core/util.h> 31 #include <core/util.h>
32 #include <core/sys.h>
29 #include <core/window.h> 33 #include <core/window.h>
30 34
31 #include <ui/ui.h> 35 #include <ui/ui.h>
32 36
33 #include <rpg/rpg.h> 37 #include <rpg/rpg.h>
34 38
35 #include <adventure/state/panic.h> 39 #include <adventure/state/panic.h>
36 #include <adventure/state/splashscreen.h> 40 #include <adventure/state/splashscreen.h>
37 #include <adventure/state/mainmenu.h> 41 #include <adventure/state/mainmenu.h>
42 #include <adventure/state/map.h>
38 43
39 #include "molko.h" 44 #include "molko.h"
40 45
41 #define WINDOW_WIDTH 1280 46 #define WINDOW_WIDTH 1280
42 #define WINDOW_HEIGHT 720 47 #define WINDOW_HEIGHT 720
96 * From here, we can setup our panic state which requires a window 101 * From here, we can setup our panic state which requires a window
97 * to be running. 102 * to be running.
98 */ 103 */
99 104
100 /* Init unrecoverable panic state. */ 105 /* Init unrecoverable panic state. */
101 panic_state(&molko.states[MOLKO_STATE_PANIC]); 106 molko.panic = panic_state_new();
102 panic_handler = crash; 107 panic_handler = crash;
103 108
104 /* Init states. */
105 splashscreen_state(&molko.states[MOLKO_STATE_SPLASH], &molko.states[MOLKO_STATE_MAINMENU]);
106 mainmenu_state(&molko.states[MOLKO_STATE_MAINMENU]);
107
108 /* Start to splash. */ 109 /* Start to splash. */
109 game_switch(&molko.states[MOLKO_STATE_SPLASH], true); 110 game_switch(splashscreen_state_new(), true);
110 } 111 }
111 112
112 void 113 void
113 molko_run(void) 114 molko_run(void)
114 { 115 {
118 } else { 119 } else {
119 /* Clear event queue to avoid accidental key presses. */ 120 /* Clear event queue to avoid accidental key presses. */
120 for (union event ev; event_poll(&ev); ) 121 for (union event ev; event_poll(&ev); )
121 continue; 122 continue;
122 123
123 game_switch(&molko.states[MOLKO_STATE_PANIC], true); 124 game_switch(molko.panic, true);
124 loop(); 125 loop();
125 } 126 }
126 } 127 }
127 128
128 void 129 void
130 molko_teleport(const char *map, int origin_x, int origin_y)
131 {
132 game_switch(map_state_new(map, origin_x, origin_y), false);
133 game.inhibit = INHIBIT_NONE;
134 }
135
136 const char *
137 molko_path(const char *file)
138 {
139 assert(file);
140
141 /* TODO: libmlk-adventure must be renamed. */
142 return pprintf("%s/libmlk-adventure/%s", sys_dir(SYS_DIR_DATA), file);
143 }
144
145 void
129 molko_finish(void) 146 molko_finish(void)
130 { 147 {
131 for (size_t i = 0; i < MOLKO_STATE_NUM; ++i)
132 state_finish(&molko.states[i]);
133
134 window_finish(); 148 window_finish();
135 rpg_finish(); 149 rpg_finish();
136 ui_finish(); 150 ui_finish();
137 core_finish(); 151 core_finish();
138 } 152 }