diff 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
line wrap: on
line diff
--- a/libmlk-adventure/adventure/molko.c	Sat Dec 05 15:57:02 2020 +0100
+++ b/libmlk-adventure/adventure/molko.c	Sun Dec 06 11:22:03 2020 +0100
@@ -16,16 +16,20 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#include <assert.h>
 #include <stddef.h>
 #include <setjmp.h>
+#include <string.h>
 #include <locale.h>
 
 #include <core/clock.h>
 #include <core/core.h>
 #include <core/event.h>
+#include <core/image.h>
 #include <core/panic.h>
 #include <core/translate.h>
 #include <core/util.h>
+#include <core/sys.h>
 #include <core/window.h>
 
 #include <ui/ui.h>
@@ -35,6 +39,7 @@
 #include <adventure/state/panic.h>
 #include <adventure/state/splashscreen.h>
 #include <adventure/state/mainmenu.h>
+#include <adventure/state/map.h>
 
 #include "molko.h"
 
@@ -98,15 +103,11 @@
 	 */
 
 	/* Init unrecoverable panic state. */
-	panic_state(&molko.states[MOLKO_STATE_PANIC]);
+	molko.panic = panic_state_new();
 	panic_handler = crash;
 
-	/* Init states. */
-	splashscreen_state(&molko.states[MOLKO_STATE_SPLASH], &molko.states[MOLKO_STATE_MAINMENU]);
-	mainmenu_state(&molko.states[MOLKO_STATE_MAINMENU]);
-
 	/* Start to splash. */
-	game_switch(&molko.states[MOLKO_STATE_SPLASH], true);
+	game_switch(splashscreen_state_new(), true);
 }
 
 void
@@ -120,17 +121,30 @@
 		for (union event ev; event_poll(&ev); )
 			continue;
 
-		game_switch(&molko.states[MOLKO_STATE_PANIC], true);
+		game_switch(molko.panic, true);
 		loop();
 	}
 }
 
 void
+molko_teleport(const char *map, int origin_x, int origin_y)
+{
+	game_switch(map_state_new(map, origin_x, origin_y), false);
+	game.inhibit = INHIBIT_NONE;
+}
+
+const char *
+molko_path(const char *file)
+{
+	assert(file);
+
+	/* TODO: libmlk-adventure must be renamed. */
+	return pprintf("%s/libmlk-adventure/%s", sys_dir(SYS_DIR_DATA), file);
+}
+
+void
 molko_finish(void)
 {
-	for (size_t i = 0; i < MOLKO_STATE_NUM; ++i)
-		state_finish(&molko.states[i]);
-
 	window_finish();
 	rpg_finish();
 	ui_finish();