data/
datasrc/
game
+tools/dunger/src/level.c
int init_level(struct level *lvl, int xsz, int ysz)
{
+ memset(lvl, 0, sizeof *lvl);
+
if(!(lvl->cells = calloc(xsz * ysz, sizeof *lvl->cells))) {
free(lvl);
return -1;
lvl->fname = strdup(fname);
if((lvl->dirname = malloc(strlen(fname) + 1))) {
+#ifndef LEVEL_EDITOR
path_dir(lvl->fname, lvl->dirname);
+#endif
}
if(!(ts = ts_load(fname))) {
return -1;
}
+#ifndef LEVEL_EDITOR
+
static int load_tileset(struct level *lvl, struct ts_node *tsn)
{
static const char *tile_types[] = {"empty", "straight", "corner", "door", 0};
}
return 0;
}
+
+#else
+
+static int load_tileset(struct level *lvl, struct ts_node *tsn)
+{
+ return 0; /* in the level editor we don't need tileset loading */
+}
+
+#endif /* !LEVEL_EDITOR */
-src = $(wildcard src/*.c) ../../src/level.c
+src = src/main.c src/lview.c src/level.c
obj = $(src:.c=.o)
dep = $(src:.c=.d)
bin = dunger
-CFLAGS = -pedantic -Wall -g
+CFLAGS = -pedantic -Wall -g -DLEVEL_EDITOR -I../../src
LDFLAGS = -lGL -lGLU -lglut -lutk -ldrawtext -ltreestore
$(bin): $(obj)
$(CC) -o $@ $(obj) $(LDFLAGS)
+src/level.c: ../../src/level.c
+ cp $< $@
+
-include $(dep)
.PHONY: clean
#include <GL/gl.h>
+#include <drawtext.h>
#include "lview.h"
static struct level *lvl;
}
glEnd();
+ if(sel) {
+ int cidx = sel - lvl->cells;
+ int row = cidx / lvl->width;
+ int col = cidx % lvl->width;
+
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glTranslatef(10, 10, 0);
+
+ glColor3f(1, 1, 1);
+ dtx_printf("(%d, %d)", col, row);
+ dtx_flush();
+
+ glPopMatrix();
+ }
}
void cell_to_pos(int cx, int cy, float *px, float *py)
static struct level lvl;
+static const char *opt_fname;
+
int main(int argc, char **argv)
{
utk_set_size(uiwin_new, utk_get_width(vbox) + pad * 2.0f, utk_get_height(vbox) + pad * 2.0f);
- if(init_level(&lvl, 32, 32) == -1) {
- fprintf(stderr, "failed to create level\n");
- return -1;
+ if(opt_fname) {
+ if(load_level(&lvl, opt_fname) == -1) {
+ fprintf(stderr, "failed to load level: %s\n", opt_fname);
+ return -1;
+ }
+ } else {
+ if(init_level(&lvl, 32, 32) == -1) {
+ fprintf(stderr, "failed to create level\n");
+ return -1;
+ }
}
if(init_lview(&lvl) == -1) {
return -1;
return -1;
}
} else {
- fprintf(stderr, "unexpected argument: %s\n", argv[i]);
- return -1;
+ if(opt_fname) {
+ fprintf(stderr, "unexpected argument: %s\n", argv[i]);
+ return -1;
+ }
+ opt_fname = argv[i];
}
}
return 0;