diff options
author | Aleksey Veresov <aleksey@veresov.pro> | 2021-03-02 14:52:14 +0300 |
---|---|---|
committer | Aleksey Veresov <aleksey@veresov.pro> | 2021-03-02 14:52:14 +0300 |
commit | 8889468f6af3ad184acfc39e0beaff503b10e3c1 (patch) | |
tree | f96071472318cd61db8818d37bf3a5e62c19dd90 /src | |
parent | 31f5b4cb47f0ac3d2b1f94979725d48340b5c57b (diff) | |
download | takethis-8889468f6af3ad184acfc39e0beaff503b10e3c1.tar takethis-8889468f6af3ad184acfc39e0beaff503b10e3c1.tar.xz takethis-8889468f6af3ad184acfc39e0beaff503b10e3c1.zip |
The UI!
Diffstat (limited to 'src')
-rw-r--r-- | src/body.h | 6 | ||||
-rw-r--r-- | src/game.c | 29 | ||||
-rw-r--r-- | src/map.c | 34 | ||||
-rw-r--r-- | src/player.c | 122 | ||||
-rw-r--r-- | src/player.h | 2 |
5 files changed, 183 insertions, 10 deletions
@@ -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; @@ -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(); } @@ -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; |