summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAleksey Veresov <aleksey@veresov.pro>2021-03-02 15:34:56 +0300
committerAleksey Veresov <aleksey@veresov.pro>2021-03-02 15:34:56 +0300
commiteffc1a3b86df640d31fff0258d12a94ec0e2181e (patch)
tree09993d66437d31dead9cd692bda3f3143a68e40a /src
parent8889468f6af3ad184acfc39e0beaff503b10e3c1 (diff)
downloadtakethis-effc1a3b86df640d31fff0258d12a94ec0e2181e.tar
takethis-effc1a3b86df640d31fff0258d12a94ec0e2181e.tar.xz
takethis-effc1a3b86df640d31fff0258d12a94ec0e2181e.zip
The DOORS!
Diffstat (limited to 'src')
-rw-r--r--src/body.h1
-rw-r--r--src/game.c62
-rw-r--r--src/map.c32
-rw-r--r--src/player.c9
4 files changed, 92 insertions, 12 deletions
diff --git a/src/body.h b/src/body.h
index ed72a26..33cab2f 100644
--- a/src/body.h
+++ b/src/body.h
@@ -23,6 +23,7 @@ typedef struct tt_body {
int collision_act;
char *msg;
int msglen;
+ int isdoor;
} tt_body;
diff --git a/src/game.c b/src/game.c
index d433ffe..c9b3fb2 100644
--- a/src/game.c
+++ b/src/game.c
@@ -117,6 +117,7 @@ static void save()
outnum(f, w->anim);
outnum(f, w->rate);
outnum(f, w->collision_act);
+ outnum(f, w->isdoor);
outnum(f, w->msglen);
if (w->msg) fputs(w->msg, f);
fputc('\n', f);
@@ -138,6 +139,7 @@ static void save()
outnum(f, b->anim);
outnum(f, b->rate);
outnum(f, b->collision_act);
+ outnum(f, b->isdoor);
outnum(f, b->msglen);
if (b->msg) fputs(b->msg, f);
fputc('\n', f);
@@ -225,6 +227,7 @@ static void load()
b->anim = readnum(f);
b->rate = readnum(f);
b->collision_act = readnum(f);
+ b->isdoor = readnum(f);
b->msglen = readnum(f);
if (b->msglen) b->msg = readline(f);
else {
@@ -250,6 +253,7 @@ static void load()
b->anim = readnum(f);
b->rate = readnum(f);
b->collision_act = readnum(f);
+ b->isdoor = readnum(f);
b->msglen = readnum(f);
if (b->msglen) b->msg = readline(f);
else {
@@ -312,6 +316,35 @@ static void keytake(tt_body *b)
static void doorcol(tt_body *b)
{
+ if (ttplayer.keys[b->txrrow - 4]) {
+ int i;
+ tt_room *r = ttplayer.room;
+ tt_body *part = 0;
+ for (i = 0; i != r->bodies_count; i++) {
+ part = r->bodies + i;
+ int dx = (part->x - b->x) / 32;
+ int xe = (part->x - b->x) % 32;
+ int dy = (part->y - b->y) / 32;
+ int ye = (part->y - b->y) % 32;
+ if (part->isdoor && !xe && !ye &&
+ ((dx == 1 || dx == -1) ^ (dy == 1 || dy == -1))) break;
+ }
+ free(r->walls[b->y / 32][b->x / 32]);
+ r->walls[b->y / 32][b->x / 32] = 0;
+ free(r->walls[part->y / 32][part->x / 32]);
+ r->walls[part->y / 32][part->x / 32] = 0;
+ ttplayer.keys[b->txrrow - 4]--;
+ b->collision_act = 0;
+ b->txrrow = 0;
+ b->txrcol = 15;
+ b->msg = 0;
+ b->msglen = 0;
+ part->collision_act = 0;
+ part->txrrow = 0;
+ part->txrcol = 15;
+ part->msg = 0;
+ part->msglen = 0;
+ }
}
static void step(int d)
@@ -414,14 +447,27 @@ static void step(int d)
SDL_Rect box = { ttplayer.x, ttplayer.y, 32, 32 };
for (i = 0; i != ttplayer.room->bodies_count; ++i) {
tt_body *b = ttplayer.room->bodies + i;
- SDL_Rect body = { 4 + b->x, 4 + b->y, 24, 24 };
- if (SDL_HasIntersection(&body, &box)) {
- switch (b->collision_act) {
- case colact_grib: gribtake(b); break;
- case colact_gulag: togulag(b); break;
- case colact_instgulag: directly_gulag(b); break;
- case colact_key: keytake(b); break;
- case colact_door: doorcol(b); break;
+ if (b->isdoor) {
+ SDL_Rect body = { b->x - 2, b->y - 2, 36, 36 };
+ if (SDL_HasIntersection(&body, &box)) {
+ switch (b->collision_act) {
+ case colact_grib: gribtake(b); break;
+ case colact_gulag: togulag(b); break;
+ case colact_instgulag: directly_gulag(b); break;
+ case colact_key: keytake(b); break;
+ case colact_door: doorcol(b); break;
+ }
+ }
+ } else {
+ SDL_Rect body = { 4 + b->x, 4 + b->y, 24, 24 };
+ if (SDL_HasIntersection(&body, &box)) {
+ switch (b->collision_act) {
+ case colact_grib: gribtake(b); break;
+ case colact_gulag: togulag(b); break;
+ case colact_instgulag: directly_gulag(b); break;
+ case colact_key: keytake(b); break;
+ case colact_door: doorcol(b); break;
+ }
}
}
}
diff --git a/src/map.c b/src/map.c
index 632a355..5a6f618 100644
--- a/src/map.c
+++ b/src/map.c
@@ -84,6 +84,7 @@ static void loadroom(tt_room *r, FILE *f)
b->anim = 1;
b->rate = 1;
b->collision_act = 0;
+ b->isdoor = 0;
b->msg = 0;
b->msglen = 0;
} else if (type == 'b') {
@@ -101,6 +102,7 @@ static void loadroom(tt_room *r, FILE *f)
b->anim = 1;
b->rate = 1;
b->collision_act = 0;
+ b->isdoor = 0;
b->msg = 0;
b->msglen = 0;
} else if (type == 'r') {
@@ -118,6 +120,7 @@ static void loadroom(tt_room *r, FILE *f)
b->anim = 1;
b->rate = 1;
b->collision_act = 0;
+ b->isdoor = 0;
b->msg = 0;
b->msglen = 0;
} else if (type == 'g') {
@@ -138,6 +141,7 @@ static void loadroom(tt_room *r, FILE *f)
b->anim = 4;
b->rate = 150 + (rand() % 50 - 25);
b->collision_act = colact_grib;
+ b->isdoor = 0;
b->msg = 0;
b->msglen = 0;
} else if (type == '^') {
@@ -156,6 +160,7 @@ static void loadroom(tt_room *r, FILE *f)
b->anim = 4;
b->rate = 150 + (rand() % 50 - 25);
b->collision_act = 0;
+ b->isdoor = 0;
b->msg = 0;
b->msglen = 0;
} else if (type == ';') {
@@ -174,6 +179,7 @@ static void loadroom(tt_room *r, FILE *f)
b->anim = 1;
b->rate = 100;
b->collision_act = 0;
+ b->isdoor = 0;
b->msg = 0;
b->msglen = 0;
} else if (type == '.') {
@@ -193,6 +199,7 @@ static void loadroom(tt_room *r, FILE *f)
b->anim = 4;
b->rate = 150 + (rand() % 50 - 25);
b->collision_act = 0;
+ b->isdoor = 0;
b->msg = 0;
b->msglen = 0;
} else if (type == '=') {
@@ -211,6 +218,7 @@ static void loadroom(tt_room *r, FILE *f)
b->anim = 1;
b->rate = 100;
b->collision_act = 0;
+ b->isdoor = 0;
} else if (type == 'k') {
r->floor[i][j] = newtile(0, default_floor_id);
r->bodies_count++;
@@ -227,7 +235,8 @@ static void loadroom(tt_room *r, FILE *f)
b->anim = 1;
b->rate = 100;
b->collision_act = colact_key;
- } else if (type == 'd') {
+ b->isdoor = 0;
+ } else if (type == 'd' || type == 'D') {
r->floor[i][j] = newtile(0, default_floor_id);
r->bodies_count++;
r->bodies = realloc(r->bodies,
@@ -238,11 +247,29 @@ static void loadroom(tt_room *r, FILE *f)
b->xrem = 0;
b->yrem = 0;
b->rem = 0;
- b->txrrow = 4;
+ b->txrrow = 4 + (type == 'D');
b->txrcol = id;
b->anim = 1;
b->rate = 100;
b->collision_act = colact_door;
+ b->isdoor = 1;
+ r->walls[i][j] = malloc(sizeof(tt_body));
+ b = r->walls[i][j];
+ b->x = j * 32;
+ b->y = i * 32;
+ b->xrem = 0;
+ b->yrem = 0;
+ b->xvel = 0;
+ b->yvel = 0;
+ b->rem = 0;
+ b->txrrow = 0;
+ b->txrcol = 15;
+ b->anim = 1;
+ b->rate = 100;
+ b->collision_act = 0;
+ b->isdoor = 0;
+ b->msg = 0;
+ b->msglen = 0;
} else if (type == '$') {
r->floor[i][j] = newtile(0, default_floor_id);
r->bodies_count++;
@@ -259,6 +286,7 @@ static void loadroom(tt_room *r, FILE *f)
b->anim = 4;
b->rate = 100 + (rand() % 50 - 25);
b->collision_act = colact_gulag;
+ b->isdoor = 0;
}
}
fgetc(f);
diff --git a/src/player.c b/src/player.c
index a1c7dfc..da5c97e 100644
--- a/src/player.c
+++ b/src/player.c
@@ -47,8 +47,13 @@ void tt_player_draw()
(b->txrcol * b->anim + b->rem / b->rate % b->anim) * 16,
b->txrrow * 16, 16, 16
};
- SDL_Rect d = { 14 + b->x, 14 + b->y, 32, 32 };
- SDL_RenderCopy(ttrdr, tttxr, &s, &d);
+ if (b->isdoor) {
+ SDL_Rect d = { 14 + b->x, 14 + b->y, 32, 32 };
+ SDL_RenderCopy(ttrdr, tttxr, &s, &d);
+ } else {
+ SDL_Rect d = { 14 + b->x, 14 + b->y, 32, 32 };
+ SDL_RenderCopy(ttrdr, tttxr, &s, &d);
+ }
if (b->msg) {
SDL_Color c = { 255, 255, 255, 255 };
SDL_Surface *s = TTF_RenderText_Blended(ttfont, b->msg, c);