remove x2, y2

main
Henri Vasserman 2025-01-07 18:04:48 +02:00
parent 97aa787cae
commit 313191aaa1
4 changed files with 15 additions and 22 deletions

10
field.c
View File

@ -19,7 +19,7 @@ void Field_init(Field *f, SDL_Renderer *rend, int w, int h) {
void Field_scroll(Field *f, SDL_Renderer *rend) {
int w = f->pics[0]->w;
int h = f->pics[0]->h;
if (f->offset.y < f->tl->y1) {
if (f->offset.y < f->tl->y) {
SWAP(f->tl, f->bl);
SWAP(f->tr, f->br);
Picture_move(f->tl, 0, -2*h);
@ -27,7 +27,7 @@ void Field_scroll(Field *f, SDL_Renderer *rend) {
Picture_render(f->tl, rend);
Picture_render(f->tr, rend);
}
if (f->offset.x < f->tl->x1) {
if (f->offset.x < f->tl->x) {
SWAP(f->tl, f->tr);
SWAP(f->bl, f->br);
Picture_move(f->tl, -2*w, 0);
@ -35,7 +35,7 @@ void Field_scroll(Field *f, SDL_Renderer *rend) {
Picture_render(f->tl, rend);
Picture_render(f->bl, rend);
}
if (f->offset.y >= f->br->y1) {
if (f->offset.y >= f->br->y) {
SWAP(f->tl, f->bl);
SWAP(f->tr, f->br);
Picture_move(f->bl, 0, 2*h);
@ -43,7 +43,7 @@ void Field_scroll(Field *f, SDL_Renderer *rend) {
Picture_render(f->bl, rend);
Picture_render(f->br, rend);
}
if (f->offset.x >= f->br->x1) {
if (f->offset.x >= f->br->x) {
SWAP(f->tl, f->tr);
SWAP(f->bl, f->br);
Picture_move(f->tr, 2*w, 0);
@ -57,7 +57,7 @@ void Field_draw(Field *f, SDL_Renderer *rend) {
for (int i = 0; i < 4; i++) {
Picture *p = f->pics[i];
SDL_FRect dst = {
p->x1 - f->offset.x, p->y1 - f->offset.y, p->w, p->h,
p->x - f->offset.x, p->y - f->offset.y, p->w, p->h,
};
SDL_RenderTexture(rend, p->texture, NULL, &dst);
}

View File

@ -8,10 +8,8 @@ Picture *Picture_new(SDL_Renderer *rend,
Picture *p = calloc(1, sizeof(Picture));
p->x1 = x;
p->x2 = x + w;
p->y1 = y;
p->y2 = y + h;
p->x = x;
p->y = y;
p->w = w;
p->h = h;
p->color = color;
@ -37,9 +35,9 @@ void Picture_render(Picture *p, SDL_Renderer *rend) {
};
const uint32_8 y0 = { 0, 0, 0, 0, 0, 0, 0, 0 };
const uint32_8 x0 = { 0, 1, 2, 3, 4, 5, 6, 7 };
uint32_8 y = y0 + p->y1;
uint32_8 y = y0 + p->y;
for (int j = 0, r = 0; j < h; j++, y += 1) {
uint32_8 x = x0 + p->x1;
uint32_8 x = x0 + p->x;
for (int i = 0; i < w; i += 8, r += 8, x += 8) {
uint32_8 z = (x ^ y) % 9;
uint32_8 f = (z==0) & c;
@ -56,9 +54,7 @@ void Picture_render(Picture *p, SDL_Renderer *rend) {
}
void Picture_move(Picture *p, int x, int y) {
p->x1 += x;
p->x2 += x;
p->y1 += y;
p->y2 += y;
p->x += x;
p->y += y;
}

View File

@ -4,10 +4,8 @@
#include <SDL3/SDL.h>
typedef struct {
int x1;
int y1;
int x2;
int y2;
int x;
int y;
int w;
int h;
int s;

View File

@ -72,7 +72,7 @@ int main() {
Field_draw(&f, rend);
if (debug) {
char buf[72];
char buf[52];
SDL_SetRenderDrawColor(rend, 0, 0, 0, 255);
SDL_RenderFillRect(rend, &(SDL_FRect) {
0, 0, sizeof(buf)*font_w, 8*font_h
@ -87,8 +87,7 @@ int main() {
char *q[] = {"TL", "TR", "BL", "BR"};
for (int i = 0; i < 4; i++) {
Picture *p = f.pics[i];
len = snprintf(buf, sizeof(buf), "%s \xB3 x1: %05d, x2: %05d, y1: %05d, y2: %05d, p: %p",
q[i], p->x1, p->x2, p->y1, p->y2, p);
len = snprintf(buf, sizeof(buf), "%s \xB3 x: %05d, y: %05d, p: %p", q[i], p->x, p->y, p);
draw_text(rend, buf, len, RC(3+i, 1), 255, 255, 255);
}
}