summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile3
-rw-r--r--dat.h15
-rw-r--r--game.c32
-rwxr-xr-ximg2map9
-rw-r--r--map.pngbin655 -> 913 bytes
-rw-r--r--map_data.c8
-rw-r--r--sdl3_main.c5
7 files changed, 69 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index f2a9b94..98c2548 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,8 @@ OBJ=\
sdl3_main.o\
physics.o\
map.o\
- game.o
+ game.o\
+ map_data.o
LDFLAGS=`pkg-config --libs sdl3` -lm
CFLAGS=`pkg-config --cflags sdl3` -O2 -Iinclude
diff --git a/dat.h b/dat.h
index 4ad6fd9..71bf8e8 100644
--- a/dat.h
+++ b/dat.h
@@ -12,6 +12,7 @@ typedef struct {
EPLAYER,
EGHOST,
EBULLET,
+ ETELEPORTER,
LASTEntity,
} type;
@@ -20,6 +21,8 @@ typedef struct {
float time;
float life;
bool alive;
+
+ int telex, teley;
} Entity;
typedef struct {
@@ -51,9 +54,21 @@ extern float player_x, player_y;
extern int ghostcount;
extern float ghostpositions[][2];
+extern struct {
+ int ftx, fty;
+ int ttx, tty;
+} telemap[];
+extern int telemapsize;
+
+extern struct {
+ float x, y;
+} teles[];
+extern int telessize;
+
extern Entity *player;
extern bool shot;
extern int shotx, shoty;
extern bool moveleft, moveright, moveup, movedown;
+
diff --git a/game.c b/game.c
index d305318..a3a1e66 100644
--- a/game.c
+++ b/game.c
@@ -11,13 +11,16 @@
static EntityCollisionProc bulletcollproc;
static EntityCollisionProc ghostcollproc;
+static EntityCollisionProc teleportercollproc;
+
static EntityUpdateProc playerproc;
static EntityUpdateProc ghostproc;
static EntityUpdateProc bulletproc;
static EntityCollisionProc *collisionProcs[LASTEntity] = {
- [EBULLET] = bulletcollproc,
- [EGHOST] = ghostcollproc,
+ [EBULLET] = bulletcollproc,
+ [EGHOST] = ghostcollproc,
+ [ETELEPORTER] = teleportercollproc,
};
static EntityUpdateProc *updateprocs[LASTEntity] = {
@@ -63,6 +66,17 @@ entinit()
e->life = 2;
e->alive = true;
}
+
+ for(int i = 0; i < telessize; i++) {
+ Entity *e = allocentity();
+ e->type = ETELEPORTER;
+ e->body.pos[0] = teles[i].x * ENTITY_SIZE * 2;
+ e->body.pos[1] = teles[i].y * ENTITY_SIZE * 2;
+ e->body.size[0] = ENTITY_SIZE;
+ e->body.size[1] = ENTITY_SIZE;
+ e->telex = floorf(teles[i].x);
+ e->teley = floorf(teles[i].y);
+ }
}
void
@@ -105,6 +119,20 @@ ghostcollproc(Entity *self, Entity *target)
}
void
+teleportercollproc(Entity *self, Entity *target)
+{
+ if(target->type == EPLAYER && target->alive) {
+ for(int i = 0; i < telemapsize; i++) {
+ if(self->telex == telemap[i].ftx && self->teley == telemap[i].fty) {
+ target->body.pos[0] = telemap[i].ttx * ENTITY_SIZE * 2;
+ target->body.pos[1] = telemap[i].tty * ENTITY_SIZE * 2;
+ break;
+ }
+ }
+ }
+}
+
+void
playerproc(Entity *e, float delta)
{
Entity *bullet;
diff --git a/img2map b/img2map
index 5d08db8..128fc63 100755
--- a/img2map
+++ b/img2map
@@ -10,6 +10,7 @@ map_pixels = [ ]
player_position = (0, 0)
ghosts = []
+teles = []
for y in range(height):
linha = []
@@ -25,6 +26,9 @@ for y in range(height):
if (r == 0xFF) and (g == 0x00) and (b == 0x00):
ghosts.append((x, y))
+ if (r == 0xFF) and (g == 0xFF) and (b == 0x00):
+ teles.append((x, y))
+
map_pixels.append(valor)
print(f"int map_width = {width};")
@@ -33,6 +37,11 @@ print(f"float player_x = {player_position[0]};")
print(f"float player_y = {player_position[1]};")
print(f"int ghostcount = {len(ghosts)};")
+print(f"int telessize = {len(teles)};")
+print("struct { float x, y; } teles[] = {")
+print("".join([ f"{{ .x = {str(x[0])}, .y = {str(x[1])} }}, " for x in teles ]))
+print("};")
+
print("float ghostpositions[][2] = {")
print("".join([ f"{{ {str(x[0])}, {str(x[1])} }}, " for x in ghosts ]))
print("};")
diff --git a/map.png b/map.png
index 3f48340..7b26386 100644
--- a/map.png
+++ b/map.png
Binary files differ
diff --git a/map_data.c b/map_data.c
new file mode 100644
index 0000000..e673de8
--- /dev/null
+++ b/map_data.c
@@ -0,0 +1,8 @@
+struct {
+ int ftx, fty;
+ int ttx, tty;
+} telemap[] = {
+ { 10, 5, 131, 3 },
+ { 138, 6, 3, 4 },
+};
+int telemapsize = sizeof telemap / sizeof telemap[0];
diff --git a/sdl3_main.c b/sdl3_main.c
index 9780e3d..873a862 100644
--- a/sdl3_main.c
+++ b/sdl3_main.c
@@ -109,6 +109,11 @@ render(void)
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0x00, 0xFF);
renderrect(e->body.pos, e->body.size);
break;
+
+ case ETELEPORTER:
+ SDL_SetRenderDrawColor(renderer, 0xFF, 0x00, 0xFF, 0xFF);
+ renderrect(e->body.pos, e->body.size);
+ break;
}
}
}