From 2416783679eafe35aea7af15bf1308a6895e251a Mon Sep 17 00:00:00 2001 From: esquizo Date: Sat, 2 May 2026 14:55:03 -0300 Subject: mapa arbitrário a partir de uma imagem MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 4 ++++ game.c | 2 +- img2map | 21 +++++++++++++++++++++ map.c | 14 -------------- map.png | Bin 0 -> 314 bytes 5 files changed, 26 insertions(+), 15 deletions(-) create mode 100755 img2map delete mode 100644 map.c create mode 100644 map.png diff --git a/Makefile b/Makefile index cb8837c..b34cf93 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,7 @@ all: game clean: rm -f game rm -f $(OBJ) + rm -f map.c game: $(OBJ) $(CC) $^ `pkg-config --libs sdl3` -lm -o $@ @@ -16,4 +17,7 @@ game: $(OBJ) %.o: %.c $(CC) $< `pkg-config --cflags sdl3` -c -o $@ +map.c: map.png img2map + ./img2map map.png > map.c + .PHONY: all clean diff --git a/game.c b/game.c index fdf0125..692f076 100644 --- a/game.c +++ b/game.c @@ -6,7 +6,7 @@ #include "dat.h" -#define SPEED 100 +#define SPEED 250 static EntityCollisionProc bulletcollproc; static EntityUpdateProc playerproc; diff --git a/img2map b/img2map new file mode 100755 index 0000000..d9e7e78 --- /dev/null +++ b/img2map @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 + +import sys +from PIL import Image + +img = Image.open(sys.argv[1]).convert('1') +width, height = img.size + +print(f"int map_width = {width};") +print(f"int map_height = {height};") +print("char map_data[] = {") + +for y in range(height): + linha = [] + for x in range(width): + pixel = img.getpixel((x, y)) + valor = '0' if pixel == 0 else '1' + linha.append(valor) + print(f" {', '.join(linha)},") + +print("};") diff --git a/map.c b/map.c deleted file mode 100644 index 8c12514..0000000 --- a/map.c +++ /dev/null @@ -1,14 +0,0 @@ -int map_width = 8; -int map_height = 8; - -char map_data[] = { - 1, 0, 0, 0, 0, 0, 0, 0, - 0, 1, 1, 0, 0, 0, 0, 0, - 0, 1, 1, 0, 0, 0, 0, 0, - 0, 1, 1, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 1, 1, 0, - 0, 0, 0, 0, 0, 1, 1, 0, - 0, 0, 0, 0, 0, 1, 1, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, -}; diff --git a/map.png b/map.png new file mode 100644 index 0000000..6a14ca1 Binary files /dev/null and b/map.png differ -- cgit v1.2.3