summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoresquizo <esquizo+noreply@esquizo.net>2026-05-03 20:52:32 -0300
committeresquizo <esquizo+noreply@esquizo.net>2026-05-03 20:52:32 -0300
commite4a5b88262430a77bf0c9b47acdc8398ff06c899 (patch)
tree8150028eba2c994da04afdf3ab87f00bb3830a72
parentcaefbf2e217e9a14ea62fa82caa796e924e52074 (diff)
posições de entidades
-rw-r--r--dat.h3
-rw-r--r--game.c9
-rwxr-xr-ximg2map37
-rw-r--r--map.pngbin314 -> 655 bytes
4 files changed, 38 insertions, 11 deletions
diff --git a/dat.h b/dat.h
index 723f1c2..f0bc5ff 100644
--- a/dat.h
+++ b/dat.h
@@ -43,6 +43,9 @@ extern int ebufi;
extern char map_data[];
extern int map_width, map_height;
+extern float player_x, player_y;
+extern int ghostcount;
+extern float ghostpositions[][2];
extern Entity *player;
diff --git a/game.c b/game.c
index eba5244..12239d0 100644
--- a/game.c
+++ b/game.c
@@ -33,13 +33,16 @@ entinit()
{
player = allocentity();
player->type = EPLAYER;
+ player->body.pos[0] = player_x;
+ player->body.pos[1] = player_x;
player->body.size[0] = ENTITY_SIZE;
player->body.size[1] = ENTITY_SIZE;
- for(int i = 0; i < 10; i++) {
+
+ for(int i = 0; i < ghostcount; i++) {
Entity *e = allocentity();
e->type = EGHOST;
- e->body.pos[0] = rand() % 800;
- e->body.pos[1] = rand() % 600;
+ e->body.pos[0] = ghostpositions[i][0] * ENTITY_SIZE * 2;
+ e->body.pos[1] = ghostpositions[i][1] * ENTITY_SIZE * 2;
e->body.size[0] = ENTITY_SIZE;
e->body.size[1] = ENTITY_SIZE;
}
diff --git a/img2map b/img2map
index d9e7e78..5d08db8 100755
--- a/img2map
+++ b/img2map
@@ -3,19 +3,40 @@
import sys
from PIL import Image
-img = Image.open(sys.argv[1]).convert('1')
+img = Image.open(sys.argv[1]).convert('RGB')
width, height = img.size
-print(f"int map_width = {width};")
-print(f"int map_height = {height};")
-print("char map_data[] = {")
+map_pixels = [ ]
+player_position = (0, 0)
+
+ghosts = []
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)},")
+ r, g, b = img.getpixel((x, y))
+ valor = '0'
+ if (r == 0xFF) and (g == 0xFF) and (b == 0xFF):
+ valor = '1'
+
+ if (r == 0x00) and (g == 0x00) and (b == 0xFF):
+ player_position = (x, y)
+
+ if (r == 0xFF) and (g == 0x00) and (b == 0x00):
+ ghosts.append((x, y))
+
+ map_pixels.append(valor)
+print(f"int map_width = {width};")
+print(f"int map_height = {height};")
+print(f"float player_x = {player_position[0]};")
+print(f"float player_y = {player_position[1]};")
+print(f"int ghostcount = {len(ghosts)};")
+
+print("float ghostpositions[][2] = {")
+print("".join([ f"{{ {str(x[0])}, {str(x[1])} }}, " for x in ghosts ]))
+print("};")
+
+print("char map_data[] = {")
+print("".join([ f"{x}," for x in map_pixels ]))
print("};")
diff --git a/map.png b/map.png
index 6a14ca1..3f48340 100644
--- a/map.png
+++ b/map.png
Binary files differ