summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dat.h3
-rw-r--r--game.c33
-rwxr-xr-ximg2map6
-rw-r--r--map.pngbin913 -> 920 bytes
-rw-r--r--sdl3_main.c5
5 files changed, 47 insertions, 0 deletions
diff --git a/dat.h b/dat.h
index 71bf8e8..e54ceb1 100644
--- a/dat.h
+++ b/dat.h
@@ -13,6 +13,7 @@ typedef struct {
EGHOST,
EBULLET,
ETELEPORTER,
+ EGOAL,
LASTEntity,
} type;
@@ -65,6 +66,8 @@ extern struct {
} teles[];
extern int telessize;
+extern int goalx, goaly;
+
extern Entity *player;
extern bool shot;
diff --git a/game.c b/game.c
index a3a1e66..e2cb381 100644
--- a/game.c
+++ b/game.c
@@ -12,6 +12,7 @@
static EntityCollisionProc bulletcollproc;
static EntityCollisionProc ghostcollproc;
static EntityCollisionProc teleportercollproc;
+static EntityCollisionProc goalcollproc;
static EntityUpdateProc playerproc;
static EntityUpdateProc ghostproc;
@@ -21,6 +22,7 @@ static EntityCollisionProc *collisionProcs[LASTEntity] = {
[EBULLET] = bulletcollproc,
[EGHOST] = ghostcollproc,
[ETELEPORTER] = teleportercollproc,
+ [EGOAL] = goalcollproc,
};
static EntityUpdateProc *updateprocs[LASTEntity] = {
@@ -47,6 +49,8 @@ entrestart()
void
entinit()
{
+ Entity *e;
+
player = allocentity();
player->type = EPLAYER;
player->body.pos[0] = player_x * ENTITY_SIZE * 2;
@@ -56,6 +60,13 @@ entinit()
player->life = 1;
player->alive = true;
+ e = allocentity();
+ e->type = EGOAL;
+ e->body.pos[0] = goalx * ENTITY_SIZE * 2;
+ e->body.pos[1] = goaly * ENTITY_SIZE * 2;
+ e->body.size[0] = ENTITY_SIZE;
+ e->body.size[1] = ENTITY_SIZE;
+
for(int i = 0; i < ghostcount; i++) {
Entity *e = allocentity();
e->type = EGHOST;
@@ -133,6 +144,28 @@ teleportercollproc(Entity *self, Entity *target)
}
void
+goalcollproc(Entity *self, Entity *target)
+{
+ static int goal = 0;
+ if(goal)
+ return;
+
+ if(target->type == EPLAYER && target->alive) {
+ goal = 1;
+ printf("GOAL!\n");
+
+ for(int i = 0; i < ebufi; i++) {
+ Entity *e = entitybuffer + i;
+ if(!e->active)
+ continue;
+
+ if(e->type == EGHOST)
+ e->alive = false;
+ }
+ }
+}
+
+void
playerproc(Entity *e, float delta)
{
Entity *bullet;
diff --git a/img2map b/img2map
index 128fc63..2260fc6 100755
--- a/img2map
+++ b/img2map
@@ -8,6 +8,7 @@ width, height = img.size
map_pixels = [ ]
player_position = (0, 0)
+goal_position = (0, 0)
ghosts = []
teles = []
@@ -23,6 +24,9 @@ for y in range(height):
if (r == 0x00) and (g == 0x00) and (b == 0xFF):
player_position = (x, y)
+ if (r == 0x00) and (g == 0xFF) and (b == 0x00):
+ goal_position = (x, y)
+
if (r == 0xFF) and (g == 0x00) and (b == 0x00):
ghosts.append((x, y))
@@ -49,3 +53,5 @@ print("};")
print("char map_data[] = {")
print("".join([ f"{x}," for x in map_pixels ]))
print("};")
+
+print(f"int goalx = {goal_position[0]}, goaly = {goal_position[1]};")
diff --git a/map.png b/map.png
index 7b26386..f63db97 100644
--- a/map.png
+++ b/map.png
Binary files differ
diff --git a/sdl3_main.c b/sdl3_main.c
index 873a862..639c0d4 100644
--- a/sdl3_main.c
+++ b/sdl3_main.c
@@ -114,6 +114,11 @@ render(void)
SDL_SetRenderDrawColor(renderer, 0xFF, 0x00, 0xFF, 0xFF);
renderrect(e->body.pos, e->body.size);
break;
+
+ case EGOAL:
+ SDL_SetRenderDrawColor(renderer, 0x00, 0xFF, 0x00, 0xFF);
+ renderrect(e->body.pos, e->body.size);
+ break;
}
}
}