diff options
| author | esquizo <esquizo+noreply@esquizo.net> | 2026-05-02 14:55:03 -0300 |
|---|---|---|
| committer | esquizo <esquizo+noreply@esquizo.net> | 2026-05-02 14:55:03 -0300 |
| commit | 2416783679eafe35aea7af15bf1308a6895e251a (patch) | |
| tree | f3d08269b9dff0eeedff8312e4b96b99169652ff | |
| parent | d2d0886cf770488d1b4890a3a414bbf983e784a6 (diff) | |
mapa arbitrário a partir de uma imagem
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | game.c | 2 | ||||
| -rwxr-xr-x | img2map | 21 | ||||
| -rw-r--r-- | map.c | 14 | ||||
| -rw-r--r-- | map.png | bin | 0 -> 314 bytes |
5 files changed, 26 insertions, 15 deletions
@@ -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 @@ -6,7 +6,7 @@ #include "dat.h" -#define SPEED 100 +#define SPEED 250 static EntityCollisionProc bulletcollproc; static EntityUpdateProc playerproc; @@ -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("};") @@ -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, -}; Binary files differ |
