diff options
author | Aleksey Veresov <aleksey@veresov.pro> | 2021-02-23 15:06:18 +0300 |
---|---|---|
committer | Aleksey Veresov <aleksey@veresov.pro> | 2021-02-23 15:06:18 +0300 |
commit | 4cfd9c6b96035ca7ccf6444e911b2a908d8500eb (patch) | |
tree | f3eba4ade72278c1a65c8eeead7a289236ab1601 | |
parent | a236f83d8cd680f956677ac6d65f0a953036e144 (diff) | |
download | takethis-4cfd9c6b96035ca7ccf6444e911b2a908d8500eb.tar takethis-4cfd9c6b96035ca7ccf6444e911b2a908d8500eb.tar.xz takethis-4cfd9c6b96035ca7ccf6444e911b2a908d8500eb.zip |
.
-rw-r--r-- | data/anim.bmp (renamed from data/textures.bmp) | bin | 22666 -> 22666 bytes | |||
-rw-r--r-- | data/boss.bmp | bin | 0 -> 22666 bytes | |||
-rw-r--r-- | data/map | 10 | ||||
-rw-r--r-- | data/rooms/0 | 15 | ||||
-rw-r--r-- | data/rooms/01 | 16 | ||||
-rw-r--r-- | data/rooms/1 (renamed from data/rooms/02) | 0 | ||||
-rw-r--r-- | data/rooms/2 (renamed from data/rooms/03) | 0 | ||||
-rw-r--r-- | data/rooms/3 (renamed from data/rooms/04) | 0 | ||||
-rw-r--r-- | data/rooms/4 (renamed from data/rooms/05) | 0 | ||||
-rw-r--r-- | data/rooms/5 (renamed from data/rooms/06) | 0 | ||||
-rw-r--r-- | data/rooms/6 (renamed from data/rooms/07) | 0 | ||||
-rw-r--r-- | data/rooms/7 (renamed from data/rooms/08) | 0 | ||||
-rw-r--r-- | data/rooms/8 (renamed from data/rooms/09) | 0 | ||||
-rw-r--r-- | data/rooms/9 (renamed from data/rooms/10) | 0 | ||||
-rw-r--r-- | data/tiles.bmp | bin | 0 -> 16522 bytes | |||
-rw-r--r-- | src/main.c | 2 | ||||
-rw-r--r-- | src/room.c | 100 | ||||
-rw-r--r-- | src/room.h | 10 | ||||
-rw-r--r-- | src/texture.c | 2 |
19 files changed, 58 insertions, 97 deletions
diff --git a/data/textures.bmp b/data/anim.bmp Binary files differindex a59ced7..a59ced7 100644 --- a/data/textures.bmp +++ b/data/anim.bmp diff --git a/data/boss.bmp b/data/boss.bmp Binary files differnew file mode 100644 index 0000000..a59ced7 --- /dev/null +++ b/data/boss.bmp @@ -1,5 +1,5 @@ -01 = 02 = 03 . 07 = 08 -. . | . . . | . . -. . 04 = 05 = 06 = 09 -. . . . . . . . | -. . . . . . . . 10 +0 = 1 = 2 . 6 = 7 +. . | . . . | . . +. . 3 = 4 = 5 = 8 +. . . . . . . . | +. . . . . . . . 9 diff --git a/data/rooms/0 b/data/rooms/0 new file mode 100644 index 0000000..a4bdbb3 --- /dev/null +++ b/data/rooms/0 @@ -0,0 +1,15 @@ +#0#4#4#4#4#4#4#4#4#4#4#4#4#4#4#4#4#4#1 +#7. . . . . . . . . . . . . . . . . #5 +#7. . . . . . . . . . . . . . . . . #5 +#7. . . . . . . . . . . . . . . . . #5 +#7. . . . . . . . . . . . . . . . . #5 +#7. . . . . . . . . . . . . . . . . #5 +#7. . . . . . . . . . . . . . . . . #5 +#7. . . . . . . . . . . . . . . . . #5 +#7. . . . . . . . . . . . . . . . . #5 +#7. . . . . . . . . . . . . . . . . #5 +#7. . . . . . . . . . . . . . . . . #5 +#7. . . . . . . . . . . . . . . . . #5 +#7. . . . . . . . . . . . . . . . . #5 +#7. . . . . . . . . . . . . . . . . #5 +#3#6#6#6#6#6#6#6#6#6#6#6#6#6#6#6#6#6#2 diff --git a/data/rooms/01 b/data/rooms/01 deleted file mode 100644 index 1ea08e7..0000000 --- a/data/rooms/01 +++ /dev/null @@ -1,16 +0,0 @@ -zelda -# # # # # # # # # # # # # # # # # # # -# . . . . . . . . . . . . . . . . . # -# . . . . . . . . . . . . . . . . . # -# . . . . . . . . . . . . . . . . . # -# . . . . . . . . . . . . . . . . . # -# . . . . . . . . . . . . . . . . . # -# . . . . . . . . . . . . . . . . . # -# . . . . . . . . . . . . . . . . . # -# . . . . . . . . . . . . . . . . . # -# . . . . . . . . . . . . . . . . . # -# . . . . . . . . . . . . . . . . . # -# . . . . . . . . . . . . . . . . . # -# . . . . . . . . . . . . . . . . . # -# . . . . . . . . . . . . . . . . . # -# # # # # # # # # # # # # # # # # # # diff --git a/data/rooms/02 b/data/rooms/1 index 18739f6..18739f6 100644 --- a/data/rooms/02 +++ b/data/rooms/1 diff --git a/data/rooms/03 b/data/rooms/2 index d6185ff..d6185ff 100644 --- a/data/rooms/03 +++ b/data/rooms/2 diff --git a/data/rooms/04 b/data/rooms/3 index e0d902a..e0d902a 100644 --- a/data/rooms/04 +++ b/data/rooms/3 diff --git a/data/rooms/05 b/data/rooms/4 index a3f2532..a3f2532 100644 --- a/data/rooms/05 +++ b/data/rooms/4 diff --git a/data/rooms/06 b/data/rooms/5 index d72c22e..d72c22e 100644 --- a/data/rooms/06 +++ b/data/rooms/5 diff --git a/data/rooms/07 b/data/rooms/6 index 0407287..0407287 100644 --- a/data/rooms/07 +++ b/data/rooms/6 diff --git a/data/rooms/08 b/data/rooms/7 index d6185ff..d6185ff 100644 --- a/data/rooms/08 +++ b/data/rooms/7 diff --git a/data/rooms/09 b/data/rooms/8 index e689452..e689452 100644 --- a/data/rooms/09 +++ b/data/rooms/8 diff --git a/data/rooms/10 b/data/rooms/9 index 1d0cfe4..1d0cfe4 100644 --- a/data/rooms/10 +++ b/data/rooms/9 diff --git a/data/tiles.bmp b/data/tiles.bmp Binary files differnew file mode 100644 index 0000000..1b40620 --- /dev/null +++ b/data/tiles.bmp @@ -12,7 +12,7 @@ int main(int argc, char **argv) SDL_Renderer *rdr = SDL_CreateRenderer(wdw, -1, SDL_RENDERER_ACCELERATED); SDL_Texture *txr = tt_texture_load(rdr); - tt_room *room = tt_room_load(1); + tt_room *room = tt_room_load('0'); SDL_SetRenderDrawColor(rdr, 215, 174, 0, 255); @@ -4,94 +4,52 @@ #include "texture.h" -#define ROOM_W 19 -#define ROOM_H 15 - - -static char *readline(FILE *f) +static SDL_Rect *rect(int x, int y, int w, int h) { - int len = 0; - char *res = malloc(1); - int c = fgetc(f); - while (c != EOF && c != '\n') { - res = realloc(res, len + 2); - res[len++] = c; - c = fgetc(f); - } - res[len] = 0; + SDL_Rect *res = malloc(sizeof(*res)); + res->x = x; + res->y = y; + res->w = w; + res->h = h; return res; } -static char skipspaces(FILE *f) -{ - int c = fgetc(f); - while (c == ' ' || c == '\n' || c == '\t') c = fgetc(f); - return c == EOF ? 0 : c; -} - -tt_room *tt_room_load(int num) +tt_room *tt_room_load(char c) { tt_room *res = malloc(sizeof(*res)); - char path[] = "data/rooms/00"; - path[11] = '0' + num / 10; - path[12] = '0' + num % 10; + char path[] = "data/rooms/0"; + path[11] = c; FILE *f = fopen(path, "r"); - char *type = readline(f); - free(type); int i, j; - for (i = 0; i != ROOM_H; ++i) { - for (j = 0; j != ROOM_W; ++j) { - char c = skipspaces(f); - if (c == '.') { - res->tiles[i][j] = &tt_texture_floor; - res->bodies[i][j] = 0; - } else if (c == '#') { - if (i == 0 && j == 0) { - res->tiles[i][j] = &tt_texture_corner_lu; - } else if (i == 0 && j == ROOM_W - 1) { - res->tiles[i][j] = &tt_texture_corner_ru; - } else if (i == ROOM_H - 1 && j == 0) { - res->tiles[i][j] = &tt_texture_corner_ld; - } else if (i == ROOM_H - 1 && j == ROOM_W - 1) { - res->tiles[i][j] = &tt_texture_corner_rd; - } else if (i == 0) { - res->tiles[i][j] = &tt_texture_wall_u; - } else if (i == ROOM_H - 1) { - res->tiles[i][j] = &tt_texture_wall_d; - } else if (j == 0) { - res->tiles[i][j] = &tt_texture_wall_l; - } else if (j == ROOM_W - 1) { - res->tiles[i][j] = &tt_texture_wall_r; - } else { - fclose(f); - free(res); - return 0; - } - res->bodies[i][j] = 0; -/* } else if (c == '@') { - res->tiles[i][j] = tt_tile_floor; - res->bodies[i][j] = tt_player_spawn(); - if (!res->bodies[i][j]) { - flcose(f); - free(res); - return 0; - } */ - } else { - fclose(f); - free(res); - return 0; - } + for (i = 0; i != TT_ROOM_H; ++i) { + for (j = 0; j != TT_ROOM_W; ++j) { + int type = fgetc(f); + res->tiletypes[i][j] = type; + res->bodies[i][j] = 0; + int id = fgetc(f); + if (id == ' ') id = '0'; + if (id < '0' || '9' < id) goto error; + id = (id - '0') * 16; + if (type == '.') res->tiles[i][j] = rect(id, 16, 16, 16); + else if (type == '#') res->tiles[i][j] = rect(id, 0, 16, 16); + else goto error; } + fgetc(f); } + fclose(f); return res; +error: + fclose(f); + free(res); + return 0; } void tt_room_draw(SDL_Renderer *rdr, SDL_Texture *txr, tt_room *room) { int i, j; - for (i = 0; i != ROOM_H; ++i) { - for (j = 0; j != ROOM_W; ++j) { + for (i = 0; i != TT_ROOM_H; ++i) { + for (j = 0; j != TT_ROOM_W; ++j) { const SDL_Rect *src = room->tiles[i][j]; if (src) { SDL_Rect dst = { 30 + 32 * j, 30 + 32 * i, 32, 32 }; @@ -5,13 +5,17 @@ #include <SDL2/SDL.h> +#define TT_ROOM_W 19 +#define TT_ROOM_H 15 + typedef struct tt_room { - const SDL_Rect *tiles[15][19]; - void *bodies[15][19]; + char tiletypes[TT_ROOM_H][TT_ROOM_W]; + const SDL_Rect *tiles[TT_ROOM_H][TT_ROOM_W]; + void *bodies[TT_ROOM_H][TT_ROOM_W]; } tt_room; -tt_room *tt_room_load(int num); +tt_room *tt_room_load(char c); void tt_room_draw(SDL_Renderer *rdr, SDL_Texture *txr, tt_room *room); diff --git a/src/texture.c b/src/texture.c index 3606274..e046f6f 100644 --- a/src/texture.c +++ b/src/texture.c @@ -15,7 +15,7 @@ const SDL_Rect tt_texture_player = { 0, 0, 0, 0 }; SDL_Texture *tt_texture_load(SDL_Renderer *rdr) { - SDL_Surface *surf = SDL_LoadBMP("data/textures.bmp"); + SDL_Surface *surf = SDL_LoadBMP("data/tiles.bmp"); SDL_Texture *res = SDL_CreateTextureFromSurface(rdr, surf); SDL_FreeSurface(surf); return res; |