summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Veresov <aleksey@veresov.pro>2021-03-02 14:52:14 +0300
committerAleksey Veresov <aleksey@veresov.pro>2021-03-02 14:52:14 +0300
commit8889468f6af3ad184acfc39e0beaff503b10e3c1 (patch)
treef96071472318cd61db8818d37bf3a5e62c19dd90
parent31f5b4cb47f0ac3d2b1f94979725d48340b5c57b (diff)
downloadtakethis-8889468f6af3ad184acfc39e0beaff503b10e3c1.tar
takethis-8889468f6af3ad184acfc39e0beaff503b10e3c1.tar.xz
takethis-8889468f6af3ad184acfc39e0beaff503b10e3c1.zip
The UI!
-rw-r--r--data/map/03
-rw-r--r--src/body.h6
-rw-r--r--src/game.c29
-rw-r--r--src/map.c34
-rw-r--r--src/player.c122
-rw-r--r--src/player.h2
6 files changed, 185 insertions, 11 deletions
diff --git a/data/map/0 b/data/map/0
index 4cd1817..d6ce717 100644
--- a/data/map/0
+++ b/data/map/0
@@ -4,7 +4,7 @@ r0r4r4r4r4r4r4r4r4r4r4r4r4r4r4r4r4r4r4r1
r7= . . . . . . . . . . . . . . . . . r5
r7= . . . . . . . $1. . ^3. . . . . . r5
r7. . ^1. . . . . . . . . . . . . . . r5
-r7. . . . . . . . . . . . . . . . . . r5
+r7. . . . . . . k . . . . . . . . . . r5
r7. . . . . . . . . . . . . . . $ . . r5
r7. . . . . . . . . . . . . . . . . . ra
r7. . . $1. . . . . . . . . . . . . . .0
@@ -22,3 +22,4 @@ r2r6r6r6r6r6r6r6r6r6r6r6r6r6r6r6r6r6r6r3
+000+000
+000+000
+000+000
++000+000
diff --git a/src/body.h b/src/body.h
index 441190e..ed72a26 100644
--- a/src/body.h
+++ b/src/body.h
@@ -2,7 +2,11 @@
#define TT_INCLUDED_BODY
-enum { colact_grib = 1, colact_gulag, colact_instgulag };
+enum { colact_grib = 1,
+ colact_gulag,
+ colact_instgulag,
+ colact_key,
+ colact_door };
typedef struct tt_body {
int x;
diff --git a/src/game.c b/src/game.c
index e47e6b0..d433ffe 100644
--- a/src/game.c
+++ b/src/game.c
@@ -87,7 +87,7 @@ static void save()
outnum(f, ttplayer.lenin_pos);
outnum(f, ttplayer.lenin_pos_rem);
outnum(f, ttplayer.lenin_vel);
- outnum(f, ttplayer.zhiv_lenin);
+ outnum(f, ttplayer.lenin_zhiv);
outnum(f, ttplayer.lenin_rem);
int i;
for (i = '0'; i != '~'; ++i) {
@@ -196,7 +196,7 @@ static void load()
ttplayer.lenin_pos = readnum(f);
ttplayer.lenin_pos_rem = readnum(f);
ttplayer.lenin_vel = readnum(f);
- ttplayer.zhiv_lenin = readnum(f);
+ ttplayer.lenin_zhiv = readnum(f);
ttplayer.lenin_rem = readnum(f);
tt_map_free();
int i;
@@ -300,6 +300,20 @@ static void gribtake(tt_body *b)
magic = tt_gotofirstroom;
}
+static void keytake(tt_body *b)
+{
+ ttplayer.keys[b->txrcol]++;
+ b->collision_act = 0;
+ b->txrrow = 0;
+ b->txrcol = 15;
+ b->msg = 0;
+ b->msglen = 0;
+}
+
+static void doorcol(tt_body *b)
+{
+}
+
static void step(int d)
{
int xw = ttplayer.xwalk * 200;
@@ -307,7 +321,7 @@ static void step(int d)
if (xw || yw) {
ttplayer.rem += d;
}
- if (ttplayer.zhiv_lenin) {
+ if (ttplayer.lenin_zhiv) {
int oldpos = ttplayer.lenin_pos;
ttplayer.lenin_rem += d;
ttplayer.lenin_pos_rem += d * ttplayer.lenin_vel;
@@ -377,6 +391,7 @@ static void step(int d)
SDL_Rect box = { ttplayer.x, ttplayer.y, 32, 32 };
int out = tt_room_out(ttplayer.room, &box);
if (out) {
+ ttplayer.money--;
if (ttplayer.room->neighbours[out - 1] == ttmap + 'L') {
Mix_PauseMusic();
curmus = 0;
@@ -403,8 +418,10 @@ static void step(int d)
if (SDL_HasIntersection(&body, &box)) {
switch (b->collision_act) {
case colact_grib: gribtake(b); break;
- case colact_gulag: togulag(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;
}
}
}
@@ -516,7 +533,7 @@ static void gotogulag()
if (!roomchanged) {
roomchanged = 1;
ttplayer.room = ttmap + 'G';
- ttplayer.zhiv_lenin = 0;
+ ttplayer.lenin_zhiv = 0;
ttplayer.x = 32 * 13;
ttplayer.y = 32 * 11;
}
@@ -664,7 +681,7 @@ static void mausoleum()
SDL_RenderPresent(ttrdr);
newticks = SDL_GetTicks();
}
- ttplayer.zhiv_lenin = 1;
+ ttplayer.lenin_zhiv = 1;
magic = 0;
ticks = SDL_GetTicks();
}
diff --git a/src/map.c b/src/map.c
index dc3b114..632a355 100644
--- a/src/map.c
+++ b/src/map.c
@@ -62,7 +62,7 @@ static void loadroom(tt_room *r, FILE *f)
ttplayer.keys[1] = 0;
ttplayer.lenin_pos = 32 * 9;
ttplayer.lenin_pos_rem = 0;
- ttplayer.zhiv_lenin = 0;
+ ttplayer.lenin_zhiv = 0;
ttplayer.lenin_rem = 0;
ttplayer.lenin_vel = -53;
ttplayer.variant = 0;
@@ -211,6 +211,38 @@ static void loadroom(tt_room *r, FILE *f)
b->anim = 1;
b->rate = 100;
b->collision_act = 0;
+ } else if (type == 'k') {
+ r->floor[i][j] = newtile(0, default_floor_id);
+ r->bodies_count++;
+ r->bodies = realloc(r->bodies,
+ sizeof(tt_body) * r->bodies_count);
+ tt_body *b = r->bodies + r->bodies_count - 1;
+ b->x = j * 32;
+ b->y = i * 32;
+ b->xrem = 0;
+ b->yrem = 0;
+ b->rem = 0;
+ b->txrrow = 11;
+ b->txrcol = id;
+ b->anim = 1;
+ b->rate = 100;
+ b->collision_act = colact_key;
+ } else if (type == 'd') {
+ r->floor[i][j] = newtile(0, default_floor_id);
+ r->bodies_count++;
+ r->bodies = realloc(r->bodies,
+ sizeof(tt_body) * r->bodies_count);
+ tt_body *b = r->bodies + r->bodies_count - 1;
+ b->x = j * 32;
+ b->y = i * 32;
+ b->xrem = 0;
+ b->yrem = 0;
+ b->rem = 0;
+ b->txrrow = 4;
+ b->txrcol = id;
+ b->anim = 1;
+ b->rate = 100;
+ b->collision_act = colact_door;
} else if (type == '$') {
r->floor[i][j] = newtile(0, default_floor_id);
r->bodies_count++;
diff --git a/src/player.c b/src/player.c
index d0ab5b1..a1c7dfc 100644
--- a/src/player.c
+++ b/src/player.c
@@ -24,7 +24,7 @@ void tt_player_draw()
}
}
- if (ttplayer.zhiv_lenin) {
+ if (ttplayer.lenin_zhiv) {
{
SDL_Rect src = { 32 + 32 * (ttplayer.lenin_rem / 200 % 2),
16 * 12 + 4, 32, 38 };
@@ -81,4 +81,124 @@ void tt_player_draw()
64, 96 };
SDL_RenderCopy(ttrdr, tttxr, &s, &d);
}
+
+ {
+ SDL_Rect src = { 0, 16 * 11, 16, 16 };
+ SDL_Rect d = { 20 + TT_ROOM_W * 32 + 32,
+ 12 + 32,
+ 64, 64 };
+ SDL_RenderCopy(ttrdr, tttxr, &src, &d);
+ int count = ttplayer.keys[0];
+ int digits = 1;
+ while (count / 10) {
+ ++digits;
+ count /= 10;
+ }
+ char *text = malloc(3 + digits);
+ text[0] = 'x';
+ text[1] = ' ';
+ int i;
+ count = ttplayer.keys[0];
+ for (i = digits + 1; i != 1; --i) {
+ text[i] = count % 10 + '0';
+ count /= 10;
+ }
+ text[digits + 2] = 0;
+ SDL_Color c = { 255, 255, 255, 255 };
+ SDL_Surface *s = TTF_RenderText_Blended(ttfont, text, c);
+ SDL_Texture *t = SDL_CreateTextureFromSurface(ttrdr, s);
+ SDL_Rect dst = { 50 + 32 * TT_ROOM_W + 64, 20 + 32,
+ s->w * 2, s->h * 2 };
+ SDL_RenderCopy(ttrdr, t, 0, &dst);
+ SDL_DestroyTexture(t);
+ SDL_FreeSurface(s);
+ }
+ {
+ SDL_Rect src = { 16, 16 * 11, 16, 16 };
+ SDL_Rect d = { 20 + TT_ROOM_W * 32 + 32,
+ 12 + 96,
+ 64, 64 };
+ SDL_RenderCopy(ttrdr, tttxr, &src, &d);
+ int count = ttplayer.keys[1];
+ int digits = 1;
+ while (count / 10) {
+ ++digits;
+ count /= 10;
+ }
+ char *text = malloc(3 + digits);
+ text[0] = 'x';
+ text[1] = ' ';
+ int i;
+ count = ttplayer.keys[1];
+ for (i = digits + 1; i != 1; --i) {
+ text[i] = count % 10 + '0';
+ count /= 10;
+ }
+ text[digits + 2] = 0;
+ SDL_Color c = { 255, 255, 255, 255 };
+ SDL_Surface *s = TTF_RenderText_Blended(ttfont, text, c);
+ SDL_Texture *t = SDL_CreateTextureFromSurface(ttrdr, s);
+ SDL_Rect dst = { 50 + 32 * TT_ROOM_W + 64, 20 + 96,
+ s->w * 2, s->h * 2 };
+ SDL_RenderCopy(ttrdr, t, 0, &dst);
+ SDL_DestroyTexture(t);
+ SDL_FreeSurface(s);
+ }
+ {
+ int count = ttplayer.money;
+ int digits = 1;
+ while (count / 10) {
+ ++digits;
+ count /= 10;
+ }
+ char *text = malloc(4 + digits);
+ text[0] = '$';
+ text[1] = ' ';
+ text[2] = ttplayer.money < 0 ? '-' : ' ';
+ int i;
+ count = ttplayer.money * (ttplayer.money < 0 ? -1 : 1);
+ for (i = digits + 2; i != 2; --i) {
+ text[i] = count % 10 + '0';
+ count /= 10;
+ }
+ text[digits + 3] = 0;
+ SDL_Color c = { 255, 255, 255, 255 };
+ SDL_Surface *s = TTF_RenderText_Blended(ttfont, text, c);
+ SDL_Texture *t = SDL_CreateTextureFromSurface(ttrdr, s);
+ SDL_Rect dst = { 50 + 32 * TT_ROOM_W + 16, 20 + 96 + 96,
+ s->w * 2, s->h * 2 };
+ SDL_RenderCopy(ttrdr, t, 0, &dst);
+ SDL_DestroyTexture(t);
+ SDL_FreeSurface(s);
+ }
+ if (ttplayer.lenin_rem) {
+ int count = ttplayer.lenin_rem / 1000;
+ int digits = 1;
+ while (count / 10) {
+ ++digits;
+ count /= 10;
+ }
+ char *text = malloc(7 + digits);
+ text[0] = 'T';
+ text[1] = 'i';
+ text[2] = 'm';
+ text[3] = 'e';
+ text[4] = ':';
+ text[5] = ' ';
+ int i;
+ count = ttplayer.lenin_rem / 1000;
+ for (i = digits + 5; i != 5; --i) {
+ text[i] = count % 10 + '0';
+ count /= 10;
+ }
+ text[digits + 6] = 0;
+ SDL_Color c = { 255, 255, 255, 255 };
+ SDL_Surface *s = TTF_RenderText_Blended(ttfont, text, c);
+ SDL_Texture *t = SDL_CreateTextureFromSurface(ttrdr, s);
+ SDL_Rect dst = { 50 + 32 * TT_ROOM_W + 16, 20 + 96 + 96 + 96,
+ s->w * 2, s->h * 2 };
+ SDL_RenderCopy(ttrdr, t, 0, &dst);
+ SDL_DestroyTexture(t);
+ SDL_FreeSurface(s);
+ }
}
diff --git a/src/player.h b/src/player.h
index ea1b687..b6bb697 100644
--- a/src/player.h
+++ b/src/player.h
@@ -23,7 +23,7 @@ typedef struct tt_player {
int lenin_pos;
int lenin_pos_rem;
int lenin_vel;
- int zhiv_lenin;
+ int lenin_zhiv;
int lenin_rem;
} tt_player;