diff options
| -rw-r--r-- | dat.h | 3 | ||||
| -rw-r--r-- | game.c | 33 | ||||
| -rwxr-xr-x | img2map | 6 | ||||
| -rw-r--r-- | map.png | bin | 913 -> 920 bytes | |||
| -rw-r--r-- | sdl3_main.c | 5 |
5 files changed, 47 insertions, 0 deletions
@@ -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; @@ -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; @@ -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]};") Binary files differdiff --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; } } } |
