summaryrefslogtreecommitdiff
path: root/src/player.c
diff options
context:
space:
mode:
authorAleksey Veresov <aleksey@veresov.pro>2021-03-02 18:19:35 +0300
committerAleksey Veresov <aleksey@veresov.pro>2021-03-02 18:19:35 +0300
commit9d08026e70c3a474182a7b76c25fd9cf53abdf57 (patch)
treee4e764f1c2fe49b8602a2b488c06f43c83fa1f86 /src/player.c
parent4eee65fb27adab195301c77e6f8b250972061172 (diff)
downloadtakethis-9d08026e70c3a474182a7b76c25fd9cf53abdf57.tar
takethis-9d08026e70c3a474182a7b76c25fd9cf53abdf57.tar.xz
takethis-9d08026e70c3a474182a7b76c25fd9cf53abdf57.zip
Fullscreen, etc...
Diffstat (limited to 'src/player.c')
-rw-r--r--src/player.c156
1 files changed, 72 insertions, 84 deletions
diff --git a/src/player.c b/src/player.c
index da5c97e..93c4778 100644
--- a/src/player.c
+++ b/src/player.c
@@ -1,24 +1,22 @@
#include "player.h"
-#include <math.h>
#include "globals.h"
-
+#include <math.h>
void tt_player_draw()
{
- int i, j;
+ int i, j;
tt_room *r = ttplayer.room;
for (i = 0; i != TT_ROOM_H; ++i) {
for (j = 0; j != TT_ROOM_W; ++j) {
- SDL_Rect d = { 14 + j * 32, 14 + i * 32, 32, 32 };
+ SDL_Rect d = {14 + j * 32, 14 + i * 32, 32, 32};
SDL_Rect *f = r->floor[i][j];
- tt_body *w = r->walls[i][j];
+ tt_body * w = r->walls[i][j];
if (f) SDL_RenderCopy(ttrdr, tttxr, f, &d);
if (w) {
SDL_Rect s = {
(w->txrcol * w->anim + w->rem / w->rate % w->anim) * 16,
- w->txrrow * 16, 16, 16
- };
+ w->txrrow * 16, 16, 16};
SDL_RenderCopy(ttrdr, tttxr, &s, &d);
}
}
@@ -26,82 +24,76 @@ void tt_player_draw()
if (ttplayer.lenin_zhiv) {
{
- SDL_Rect src = { 32 + 32 * (ttplayer.lenin_rem / 200 % 2),
- 16 * 12 + 4, 32, 38 };
- SDL_Rect dst = { 14 + ttplayer.lenin_pos,
- 14 + 32 + 96 - 8 - 38 * 2, 64, 38 * 2 };
+ SDL_Rect src = {32 + 32 * (ttplayer.lenin_rem / 200 % 2),
+ 16 * 12 + 4, 32, 38};
+ SDL_Rect dst = {14 + ttplayer.lenin_pos, 14 + 32 + 96 - 8 - 38 * 2,
+ 64, 38 * 2};
SDL_RenderCopy(ttrdr, tttxr, &src, &dst);
}
{
- SDL_Rect src = { 96 + 64 * (ttplayer.lenin_rem / 200 % 2),
- 16 * 12, 64, 48 };
- SDL_Rect dst = { 14 + ttplayer.lenin_pos - 32,
- 110, 128, 96 };
+ SDL_Rect src = {96 + 64 * (ttplayer.lenin_rem / 200 % 2), 16 * 12,
+ 64, 48};
+ SDL_Rect dst = {14 + ttplayer.lenin_pos - 32, 110, 128, 96};
SDL_RenderCopy(ttrdr, tttxr, &src, &dst);
}
}
for (i = 0; i != r->bodies_count; ++i) {
tt_body *b = r->bodies + i;
- SDL_Rect s = {
- (b->txrcol * b->anim + b->rem / b->rate % b->anim) * 16,
- b->txrrow * 16, 16, 16
- };
+ SDL_Rect s = {(b->txrcol * b->anim + b->rem / b->rate % b->anim) * 16,
+ b->txrrow * 16, 16, 16};
if (b->isdoor) {
- SDL_Rect d = { 14 + b->x, 14 + b->y, 32, 32 };
+ 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_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);
- SDL_Texture *t = SDL_CreateTextureFromSurface(ttrdr, s);
- SDL_Rect dst = { 50 + b->x, 20 + b->y, s->w, s->h };
+ SDL_Color c = {255, 255, 255, 255};
+ SDL_Surface *s = TTF_RenderText_Blended(ttfont, b->msg, c);
+ SDL_Texture *t = SDL_CreateTextureFromSurface(ttrdr, s);
+ SDL_Rect dst = {50 + b->x, 20 + b->y, s->w, s->h};
SDL_RenderCopy(ttrdr, t, 0, &dst);
SDL_DestroyTexture(t);
SDL_FreeSurface(s);
}
}
- SDL_Rect d = { 14 + ttplayer.x, 14 + ttplayer.y, 32, 32 };
- int dir = 0;
+ SDL_Rect d = {14 + ttplayer.x, 14 + ttplayer.y, 32, 32};
+ int dir = 0;
if (ttplayer.xwalk == 1) dir = 6;
- else if (ttplayer.xwalk == -1) dir = 2;
- else if (ttplayer.ywalk == -1) dir = 4;
- SDL_Rect s = { 16 * (8 * ttplayer.variant +
- dir + (ttplayer.rem / 100 % 2)),
- 16 * 6,
- 16, 16 };
+ else if (ttplayer.xwalk == -1)
+ dir = 2;
+ else if (ttplayer.ywalk == -1)
+ dir = 4;
+ SDL_Rect s = {16 * (8 * ttplayer.variant + dir + (ttplayer.rem / 100 % 2)),
+ 16 * 6, 16, 16};
SDL_RenderCopy(ttrdr, tttxr, &s, &d);
if (ttplayer.until_gulag > 0) {
double r = ttplayer.until_gulag / 10;
- double f = (double)(ttplayer.until_gulag) / 3000 *
- 2 * 3.14159265358979323846;
- SDL_Rect s = { 0, 16 * 12, 32, 48 };
- SDL_Rect d = { ttplayer.x - 16 + r * cos(f),
- ttplayer.y - 32 + r * sin(f),
- 64, 96 };
+ double f =
+ (double)(ttplayer.until_gulag) / 3000 * 2 * 3.14159265358979323846;
+ SDL_Rect s = {0, 16 * 12, 32, 48};
+ SDL_Rect d = {ttplayer.x - 16 + r * cos(f),
+ ttplayer.y - 32 + r * sin(f), 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_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 count = ttplayer.keys[0];
int digits = 1;
while (count / 10) {
++digits;
count /= 10;
}
char *text = malloc(3 + digits);
- text[0] = 'x';
- text[1] = ' ';
+ text[0] = 'x';
+ text[1] = ' ';
int i;
count = ttplayer.keys[0];
for (i = digits + 1; i != 1; --i) {
@@ -109,30 +101,27 @@ void tt_player_draw()
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_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_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 count = ttplayer.keys[1];
int digits = 1;
while (count / 10) {
++digits;
count /= 10;
}
char *text = malloc(3 + digits);
- text[0] = 'x';
- text[1] = ' ';
+ text[0] = 'x';
+ text[1] = ' ';
int i;
count = ttplayer.keys[1];
for (i = digits + 1; i != 1; --i) {
@@ -140,26 +129,25 @@ void tt_player_draw()
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_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 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 ? '-' : ' ';
+ 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) {
@@ -167,29 +155,29 @@ void tt_player_draw()
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_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 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] = ' ';
+ 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) {
@@ -197,11 +185,11 @@ void tt_player_draw()
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_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);