diff options
| -rw-r--r-- | cetris.c | 158 | ||||
| -rw-r--r-- | cetris.h | 31 | ||||
| -rw-r--r-- | frontend/ncurses/ncurses_ui.c | 42 | ||||
| -rw-r--r-- | frontend/sdl/.border.jpeg-autosave.kra | bin | 0 -> 71027 bytes | |||
| -rw-r--r-- | frontend/sdl/sdl_ui.c | 99 | ||||
| -rw-r--r-- | meson.build | 3 |
6 files changed, 213 insertions, 120 deletions
@@ -17,11 +17,10 @@ static void init_piece_queue(struct cetris_game* g); static void shuffle_queue(struct cetris_game* g);
static void next_piece(struct cetris_game* g);
static void move_current(struct cetris_game* g, vec2 offset);
-static int check_new_matrix(struct cetris_game* g, piece_matrix m);
-static void wipe_board(struct cetris_game* g, int did_move);
+static int8_t check_new_matrix(struct cetris_game* g, piece_matrix m);
+static void wipe_board(struct cetris_game* g);
static void set_constants(struct cetris_game* g);
static void rotate_matrix(struct cetris_game* g, int clockwise);
-//static void clear_move_queue(struct cetris_game* g);
static void overlay_current_matrix(struct cetris_game* g);
/* DEFAULT MATRIX FOR EACH POSSIBLE TETRIMINO */
@@ -78,7 +77,7 @@ static const piece_matrix default_matrices[7] = { };
/* LEVEL DROP SPEED VALUES */
-static const int level_drop_delay[20] = {
+static const uint8_t level_drop_delay[20] = {
48, 43, 38, 33, 28, 23, 18, 13, 8, 6, 5, 5, 5, 4, 4, 4, 3, 3, 3, 3
};
@@ -117,7 +116,7 @@ void move_current(struct cetris_game* g, vec2 offset) { g->current.pos.y += offset.y;
g->current.pos.x += offset.x;
- int check = check_new_matrix(g, g->current.mat);
+ int8_t check = check_new_matrix(g, g->current.mat);
if (check <= 0) {
g->current.pos.y -= offset.y;
g->current.pos.x -= offset.x;
@@ -125,18 +124,18 @@ void move_current(struct cetris_game* g, vec2 offset) { if (check == -1 && g->current.lock_tick == 0) {
g->current.lock_tick = g->tick + 30;
}
-
- //clear_move_queue(g);
}
}
void move_hard_drop(struct cetris_game* g) {
- int drop = 0;
- int drop_count = 0;
+ if (g->game_over) return;
+
+ uint8_t drop = 0;
+ uint8_t drop_count = 0;
while (!drop) {
g->current.pos.y++;
drop_count++;
- int check = check_new_matrix(g, g->current.mat);
+ int8_t check = check_new_matrix(g, g->current.mat);
if (check <= 0) {
g->current.pos.y--;
drop_count--;
@@ -146,12 +145,12 @@ void move_hard_drop(struct cetris_game* g) { g->score += 2 * drop_count; // 2 score for each harddrop cell
- wipe_board(g, 1);
+ wipe_board(g);
next_piece(g);
}
void move_down(struct cetris_game* g) {
- g->queued_move = DOWN;
+ g->queued_move = USER_DOWN;
}
void move_right(struct cetris_game* g) {
@@ -164,10 +163,7 @@ void move_left(struct cetris_game* g) { void rotate_matrix(struct cetris_game* g, int clockwise) {
if (g->current.t == O) return;
-
- piece_matrix m;
- memset(m, 0, sizeof(piece_matrix));
-
+
rstate next;
switch (g->current.r) {
case INIT:
@@ -184,21 +180,26 @@ void rotate_matrix(struct cetris_game* g, int clockwise) { break;
}
- for (int x = 0; x < 4; x++) {
- for (int y = 0; y < 4; y++) {
+ piece_matrix m;
+ memset(m, 0, sizeof(piece_matrix));
+
+ for (uint8_t x = 0; x < 4; x++) {
+ for (uint8_t y = 0; y < 4; y++) {
if (g->current.mat[y][x]) {
- int new_x = (clockwise) ? 1 - (y - 2) : 1 + (y - 2);
- int new_y = (clockwise) ? 2 + (x - 1) : 2 - (x - 1);
+ uint8_t new_x = (clockwise) ? 1 - (y - 2) : 1 + (y - 2);
+ uint8_t new_y = (clockwise) ? 2 + (x - 1) : 2 - (x - 1);
+
if (g->current.t == I) {
if (clockwise) new_y--;
else new_x++;
}
+
m[new_y][new_x] = 1;
}
}
}
- int wall_kick;
+ uint8_t wall_kick;
switch (g->current.r) {
case INIT:
wall_kick = (next == RRIGHT) ? 0 : 7;
@@ -212,14 +213,14 @@ void rotate_matrix(struct cetris_game* g, int clockwise) { case TWO:
wall_kick = (next == RRIGHT) ? 3 : 4;
break;
- default: // check for UB causing invalid rotations
+ default: // check for invalid rotations
assert(0);
}
vec2 kick;
- int set_current = 0;
- int did_kick = 0;
- for (int i = 0; i < 5; i++) {
+ uint8_t set_current = 0;
+ uint8_t did_kick = 0;
+ for (uint8_t i = 0; i < 5; i++) {
if (g->current.t == I) {
kick = srs_wall_kicks_i[wall_kick][i];
} else {
@@ -240,8 +241,8 @@ void rotate_matrix(struct cetris_game* g, int clockwise) { if (set_current) {
/* check for tspin */
if (g->current.t == T) {
- int did_tspin = 1;
- for (int i = 0; i < 4; i++) {
+ uint8_t did_tspin = 1;
+ for (uint8_t i = 0; i < 4; i++) {
g->current.pos.x += cardinal_movements[i].x;
g->current.pos.y += cardinal_movements[i].y;
if (check_new_matrix(g, m) == 1) {
@@ -258,6 +259,7 @@ void rotate_matrix(struct cetris_game* g, int clockwise) { g->current.r = next;
memcpy(g->current.mat, m, sizeof(piece_matrix));
+ wipe_board(g);
}
}
@@ -269,10 +271,10 @@ void rotate_counterclockwise(struct cetris_game* g) { rotate_matrix(g, 0);
}
-int check_new_matrix(struct cetris_game* g, piece_matrix m) {
+int8_t check_new_matrix(struct cetris_game* g, piece_matrix m) {
vec2 r;
- for (int x = 0; x < 4; x++) {
- for (int y = 0; y < 4; y++) {
+ for (uint8_t x = 0; x < 4; x++) {
+ for (uint8_t y = 0; y < 4; y++) {
r = (vec2){g->current.pos.x + x, g->current.pos.y + y};
if (m[y][x]) {
if (r.x > BOARD_X - 1 || r.x < 0) return 0;
@@ -295,7 +297,7 @@ void init_game(struct cetris_game* g) { memset(g->board, 0, sizeof(slot) * BOARD_X * BOARD_Y);
#ifdef BUILD_TESTS
- apply_test_board(g, TSPIN_NO_LINES);
+ //aply_test_board(g, TSPIN_NO_LINES);
#endif
g->tick = 0;
@@ -306,10 +308,10 @@ void init_game(struct cetris_game* g) { g->queued_move = 0;
g->prev_move = 0;
g->move_repeat = 0;
- //clear_move_queue(g);
g->lines = 0;
g->level = 1;
+ g->game_over = 0;
g->tspin = 0;
g->mini_tspin = 0;
@@ -322,16 +324,8 @@ void init_game(struct cetris_game* g) { next_piece(g);
}
-/*
-void clear_move_queue(struct cetris_game* g) {
- memset(g->move_queue, 0, sizeof(enum movements) * 20);
- g->move_queue_count = 0;
- g->move_queue_pos = 0;
-}
-*/
-
void init_piece_queue(struct cetris_game* g) {
- for (int i = 0; i < 7; i++) {
+ for (uint8_t i = 0; i < 7; i++) {
switch (i) {
case 0:
g->piece_queue[i].t = O;
@@ -370,17 +364,22 @@ void init_piece_queue(struct cetris_game* g) { }
void shuffle_queue(struct cetris_game* g) {
- for (int i = 0; i < 7; i++) {
+ for (uint8_t i = 0; i < 7; i++) {
struct tetrimino t = g->piece_queue[i];
- int rand_index = rand() % 7;
+ uint8_t rand_index = rand() % 7;
g->piece_queue[i] = g->piece_queue[rand_index];
g->piece_queue[rand_index] = t;
}
}
void update_game_tick(struct cetris_game* g) {
+ if (g->game_over) return;
+
+ uint8_t did_move = 0;
if (g->tick == g->next_drop_tick) {
- move_down(g);
+ move_current(g, cardinal_movements[0]);
+ did_move = 1;
+ //g->queued_move = DOWN;
g->next_drop_tick = g->tick + level_drop_delay[g->level - 1];
}
@@ -393,12 +392,11 @@ void update_game_tick(struct cetris_game* g) { g->current.lock_tick = 0;
}
- //enum movements current_move = g->move_queue[g->move_queue_pos];
-
- /* input independedent das movement */
- int delay = 0;
- if (g->move_repeat > 0) {
- if (g->queued_move == g->prev_move) {
+ /* input independedent das */
+ if (g->queued_move) {
+ uint8_t delay = 0;
+ if (g->queued_move != DOWN &&
+ g->queued_move == g->prev_move) {
g->move_repeat++;
} else {
g->move_repeat = 0;
@@ -408,16 +406,13 @@ void update_game_tick(struct cetris_game* g) { } else if (g->move_repeat > 1) {
delay = CETRIS_DAS_PERIOD;
}
- }
- int did_move = 0;
- if (!delay || g->tick % delay == 0) {
- if (g->queued_move > 0) {
+ if (!delay || g->tick % delay == 0) {
did_move = 1;
switch (g->queued_move) {
- case DOWN:
+ case USER_DOWN:
+ g->score++;
move_current(g, cardinal_movements[0]);
- g->score++; // 1 score for each softdrop
break;
case LEFT:
move_current(g, cardinal_movements[3]);
@@ -429,24 +424,25 @@ void update_game_tick(struct cetris_game* g) { did_move = 0;
break;
}
- if (did_move) {
- g->prev_move = g->queued_move;
- g->queued_move = 0;
- }
- //g->current.lock_tick = 0;
}
- wipe_board(g, did_move);
+ }
+
+ if (did_move) {
+ g->prev_move = g->queued_move;
+ g->queued_move = 0;
+ wipe_board(g);
}
g->tick++;
}
void next_piece(struct cetris_game* g) {
- //clear_move_queue(g);
-
set_constants(g);
g->current = g->piece_queue[g->current_index];
+ if (check_new_matrix(g, g->current.mat) <= 0) {
+ g->game_over = 1;
+ }
g->current_index++;
if (g->current_index >= 7) {
@@ -456,8 +452,8 @@ void next_piece(struct cetris_game* g) { }
void set_constants(struct cetris_game* g) {
- for (int x = 0; x < BOARD_X; x++) {
- for (int y = 0; y < BOARD_Y; y++) {
+ for (uint8_t x = 0; x < BOARD_X; x++) {
+ for (uint8_t y = 0; y < BOARD_Y; y++) {
if (g->board[x][y].occupied) g->board[x][y].constant = 1;
}
}
@@ -491,8 +487,8 @@ void add_score(struct cetris_game* g, int lines) { void overlay_current_matrix(struct cetris_game* g) {
vec2 r;
- for (int y = 0; y < 4; y++) {
- for (int x = 0; x < 4; x++) {
+ for (uint8_t y = 0; y < 4; y++) {
+ for (uint8_t x = 0; x < 4; x++) {
r = (vec2){x + g->current.pos.x, y + g->current.pos.y};
if (g->current.mat[y][x]) {
g->board[r.x][r.y].occupied = 1;
@@ -502,35 +498,29 @@ void overlay_current_matrix(struct cetris_game* g) { }
}
-void wipe_board(struct cetris_game* g, int did_move) {
- for (int y = 0; y < BOARD_Y; y++) {
- for (int x = 0; x < BOARD_X; x++) {
-
+void wipe_board(struct cetris_game* g) {
+ uint8_t lines_cleared = 0;
+ for (uint8_t y = 0; y < BOARD_Y; y++) {
+ uint8_t clear_line = 1;
+ for (uint8_t x = 0; x < BOARD_X; x++) {
if (!g->board[x][y].constant) {
memset(&g->board[x][y], 0, sizeof(slot));
}
if (g->board[x][y].remove_tick && g->board[x][y].remove_tick <= g->tick) {
memset(&g->board[x][y], 0, sizeof(slot));
- for (int s = y - 1; s >= 0; s--) {
+ for (int8_t s = y - 1; s >= 0; s--) {
g->board[x][s + 1] = g->board[x][s];
}
}
- }
- }
- int lines_cleared = 0;
- for (int y = 0; y < BOARD_Y; y++) {
- int clear_line = 1;
- for (int x = 0; x < BOARD_X; x++) {
- if (!g->board[x][y].occupied ||
- g->board[x][y].remove_tick > 0 ||
- !g->board[x][y].constant)
+ if (!g->board[x][y].occupied || g->board[x][y].remove_tick > 0) {
clear_line = 0;
+ }
}
if (clear_line) {
lines_cleared++;
- for (int x = 0; x < BOARD_X; x++) {
+ for (uint8_t x = 0; x < BOARD_X; x++) {
g->board[x][y].remove_tick = g->tick + CETRIS_LINE_CLEAR_DELAY;
}
}
@@ -539,7 +529,7 @@ void wipe_board(struct cetris_game* g, int did_move) { overlay_current_matrix(g);
assert(lines_cleared <= 4);
- if (did_move || lines_cleared > 0) {
+ if (lines_cleared > 0) {
add_score(g, lines_cleared);
if (lines_cleared > 0) {
g->lines += lines_cleared;
@@ -1,17 +1,20 @@ #pragma once
+#include <stdint.h>
+
#define BOARD_X 10
#define BOARD_Y 43
#define BOARD_VISABLE 23
#define CETRIS_HZ 60
-#define CETRIS_DAS_DELAY 11
-#define CETRIS_DAS_PERIOD 5
+#define CETRIS_DAS_DELAY 6
+#define CETRIS_DAS_PERIOD 3
#define CETRIS_LINE_CLEAR_DELAY 40
+#define CETRIS_WAIT_ON_CLEAR 0
typedef struct {
- int x;
- int y;
+ int8_t x;
+ int8_t y;
} vec2;
typedef enum {
@@ -36,7 +39,7 @@ typedef enum { TWO
} rstate;
-typedef int piece_matrix[4][4];
+typedef uint8_t piece_matrix[4][4];
struct tetrimino {
type t;
@@ -48,8 +51,8 @@ struct tetrimino { };
typedef struct {
- int occupied;
- int constant;
+ uint8_t occupied;
+ uint8_t constant;
int remove_tick;
color c;
} slot;
@@ -57,7 +60,8 @@ typedef struct { enum movement {
DOWN = 1,
LEFT = 2,
- RIGHT = 3
+ RIGHT = 3,
+ USER_DOWN = 4
};
struct cetris_game {
@@ -69,11 +73,11 @@ struct cetris_game { /* current tetrimino */
struct tetrimino current;
- int current_index;
+ uint8_t current_index;
enum movement queued_move;
enum movement prev_move;
- int move_repeat;
+ uint16_t move_repeat;
/* internal game tick */
int tick;
@@ -81,11 +85,12 @@ struct cetris_game { /* progress trackers */
int lines;
- int level;
+ uint8_t level;
+ uint8_t game_over;
/* scoring flags */
- int tspin;
- int mini_tspin;
+ uint8_t tspin;
+ uint8_t mini_tspin;
/* long int just incase */
long int score;
diff --git a/frontend/ncurses/ncurses_ui.c b/frontend/ncurses/ncurses_ui.c index d3d0e36..b1407f6 100644 --- a/frontend/ncurses/ncurses_ui.c +++ b/frontend/ncurses/ncurses_ui.c @@ -58,6 +58,8 @@ #define X_OFFSET 8
#define Y_OFFSET 0
+struct cetris_game game;
+
void curses_init() {
setlocale(LC_CTYPE, "");
initscr();
@@ -78,29 +80,29 @@ void curses_init() { clear();
}
-void draw_board(struct cetris_game* g) {
+void draw_board() {
mvaddstr(0, 0, PLAY_FIELD_STR);
for (int x = 0; x < BOARD_X; x++) {
for (int y = BOARD_VISABLE; y < BOARD_Y; y++) {
- if (g->board[x][y].occupied) {
- attron(COLOR_PAIR(g->board[x][y].c));
- if (g->board[x][y].remove_tick > 0) {
- if (g->tick % 2 == 0) {
+ if (game.board[x][y].occupied) {
+ attron(COLOR_PAIR(game.board[x][y].c));
+ if (game.board[x][y].remove_tick > 0) {
+ if (game.tick % 2 == 0) {
mvaddstr((y - BOARD_VISABLE) + 1, x * 2 + X_OFFSET, BLOCK);
}
} else {
mvaddstr((y - BOARD_VISABLE) + 1, x * 2 + X_OFFSET, BLOCK);
}
- attroff(COLOR_PAIR(g->board[x][y].c));
+ attroff(COLOR_PAIR(game.board[x][y].c));
}
}
- int index = g->current_index;
- attron(COLOR_PAIR(g->piece_queue[index].c));
+ int index = game.current_index;
+ attron(COLOR_PAIR(game.piece_queue[index].c));
for (int x = 0; x < 4; x++) {
for (int y = 0; y < 4; y++) {
- if (g->piece_queue[index].mat[y][x]) {
- if (g->piece_queue[index].t == I) {
+ if (game.piece_queue[index].mat[y][x]) {
+ if (game.piece_queue[index].t == I) {
mvaddstr(6 + y, (x * 2) + 36, BLOCK);
} else {
mvaddstr(6 + y, (x * 2) + 37, BLOCK);
@@ -108,19 +110,24 @@ void draw_board(struct cetris_game* g) { }
}
}
- attroff(COLOR_PAIR(g->piece_queue[index].c));
+ attroff(COLOR_PAIR(game.piece_queue[index].c));
attron(A_BOLD);
char score[50];
- sprintf(score, "%li", g->score);
+ sprintf(score, "%li", game.score);
mvaddstr(1, (39 + X_OFFSET) - strlen(score), score);
char level[20];
- sprintf(level, "%i", g->level);
+ sprintf(level, "%i", game.level);
mvaddstr(3, 37, "Level");
mvaddstr(4, 40 - strlen(level), level);
+ if (game.game_over) {
+ mvaddstr(10, 6 + X_OFFSET, "GAME OVER");
+ mvaddstr(11, 5 + X_OFFSET, "r to restart");
+ }
+
attroff(A_BOLD);
}
}
@@ -128,7 +135,6 @@ void draw_board(struct cetris_game* g) { int main(void) {
curses_init();
- struct cetris_game game;
init_game(&game);
int c;
@@ -145,9 +151,15 @@ int main(void) { case KEY_UP:
rotate_clockwise(&game); break;
case ' ':
- move_hard_drop(&game);
+ move_hard_drop(&game); break;
+ case 'r':
+ if (game.game_over) {
+ init_game(&game);
+ }
+ break;
}
update_game_tick(&game);
+ erase();
draw_board(&game);
refresh();
}
diff --git a/frontend/sdl/.border.jpeg-autosave.kra b/frontend/sdl/.border.jpeg-autosave.kra Binary files differnew file mode 100644 index 0000000..69f596a --- /dev/null +++ b/frontend/sdl/.border.jpeg-autosave.kra diff --git a/frontend/sdl/sdl_ui.c b/frontend/sdl/sdl_ui.c index 012255a..f862244 100644 --- a/frontend/sdl/sdl_ui.c +++ b/frontend/sdl/sdl_ui.c @@ -1,15 +1,19 @@ #include <SDL2/SDL.h> +#include <SDL2/SDL_ttf.h> #include "cetris.h" -#define W 360 -#define H 640 +#define W 430 +#define H 550 +#define BOARD_OFFSET_X 25 +#define BOARD_OFFSET_Y 20 struct cetris_game g; SDL_Renderer* render; SDL_Texture* block; SDL_Event e; +TTF_Font* font; typedef struct { int r; @@ -31,22 +35,103 @@ sdl_color colors[8] = { void setup() { SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO); SDL_Window* win = SDL_CreateWindow("Cetris", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, W, H, SDL_WINDOW_SHOWN); - render = SDL_CreateRenderer(win, -1, SDL_RENDERER_PRESENTVSYNC); + render = SDL_CreateRenderer(win, -1, SDL_RENDERER_PRESENTVSYNC|SDL_RENDERER_ACCELERATED); + SDL_RenderSetLogicalSize(render, W, H); if (!render) exit(fprintf(stderr, "[Error] Could not create SDL renderer\n")); SDL_Surface* s = SDL_LoadBMP("block.bmp"); block = SDL_CreateTextureFromSurface(render, s); SDL_FreeSurface(s); + + TTF_Init(); + font = TTF_OpenFont("LiberationMono-Regular.ttf", 18); +} + +void draw_text(char* string, int x, int y) { + int w, h; + char msg[80]; + snprintf(msg, 80, string); + TTF_SizeText(font, msg, &w, &h); + SDL_Surface *msgsurf = TTF_RenderText_Blended(font, msg, (SDL_Color){255, 255, 255, 255}); + SDL_Texture *msgtex = SDL_CreateTextureFromSurface(render, msgsurf); + SDL_Rect fromrec = {0, 0, msgsurf->w, msgsurf->h}; + SDL_Rect torec = {x, y, msgsurf->w, msgsurf->h}; + SDL_RenderCopy(render, msgtex, &fromrec, &torec); + SDL_DestroyTexture(msgtex); + SDL_FreeSurface(msgsurf); } void draw_stuff() { + SDL_SetRenderDrawColor(render, 100, 100, 112, 255); SDL_RenderClear(render); + SDL_Rect b = {BOARD_OFFSET_X, BOARD_OFFSET_Y, 250, 500}; + SDL_SetRenderDrawColor(render, 120, 120, 132, 255); + SDL_RenderFillRect(render, &b); + SDL_RenderDrawRect(render, &b); + + + SDL_Rect next = {294, 20, 125, 125}; + SDL_RenderFillRect(render, &next); + SDL_RenderDrawRect(render, &next); + int index = g.current_index; + sdl_color nc = colors[g.piece_queue[index].c]; + SDL_SetTextureColorMod(block, nc.r, nc.g, nc.b); + SDL_Rect p = {294, 20, 25, 25}; + for (int x = 0; x < 4; x++) { + for (int y = 0; y < 4; y++) { + if (g.piece_queue[index].mat[y][x]) { + p.x = 319 + (x * 25); + p.y = 30 + (y * 25); + if (g.piece_queue[index].t == I) { + p.x = 306 + (x * 25); + } + if (g.piece_queue[index].t == O) { + p.x = 306 + (x * 25); + } + SDL_RenderCopy(render, block, NULL, &p); + } + } + } + + SDL_SetRenderDrawColor(render, 76, 70, 72, 255); + + int y_off = 140; + + SDL_Rect s = {290, 20 + y_off, 135, 42}; + SDL_RenderFillRect(render, &s); + SDL_RenderDrawRect(render, &s); + draw_text("SCORE", 295, 23 + y_off); + char* score = malloc(sizeof(char) * 25); + sprintf(score, "%li", g.score); + draw_text(score, 294 + strlen(score), 40 + y_off); + free(score); + + SDL_Rect l = {290, 70 + y_off, 135, 42}; + SDL_RenderFillRect(render, &l); + SDL_RenderDrawRect(render, &l); + draw_text("LEVEL", 295, 73 + y_off); + char* level = malloc(sizeof(char) * 25); + sprintf(level, "%i", g.level); + draw_text(level, 294 + strlen(level), 90 + y_off); + free(level); + + SDL_Rect l1 = {290, 120 + y_off, 135, 42}; + SDL_RenderFillRect(render, &l1); + SDL_RenderDrawRect(render, &l1); + draw_text("LINES", 295, 123 + y_off); + char* lines = malloc(sizeof(char) * 25); + sprintf(lines, "%i", g.lines); + draw_text(lines, 294 + strlen(lines), 140 + y_off); + free(lines); + SDL_SetRenderDrawColor(render, 255, 255, 255, 124); for (int x = 0; x < BOARD_X + 1; x++) { - SDL_RenderDrawLine(render, 1 + (x * 25), 1, 1 + (x * 25), 500); + int rx = BOARD_OFFSET_X + 1 + (x * 25); + SDL_RenderDrawLine(render, rx, BOARD_OFFSET_Y + 1, rx, BOARD_OFFSET_Y + 500); } for (int y = 0; y < BOARD_Y - BOARD_VISABLE + 1; y++) { - SDL_RenderDrawLine(render, 1, 1 + (y * 25), 250, 1 + (y * 25)); + int ry = BOARD_OFFSET_Y + (y * 25); + SDL_RenderDrawLine(render, BOARD_OFFSET_X + 1, ry, BOARD_OFFSET_X + 250, ry); } SDL_SetRenderDrawColor(render, 0, 0, 0, 255); @@ -57,8 +142,8 @@ void draw_stuff() { if (g.board[x][y].occupied) { c = colors[g.board[x][y].c]; SDL_SetTextureColorMod(block, c.r, c.g, c.b); - r.x = x * 25; - r.y = (y - BOARD_VISABLE) * 25; + r.x = BOARD_OFFSET_X + x * 25; + r.y = BOARD_OFFSET_Y + (y - BOARD_VISABLE) * 25; SDL_RenderCopy(render, block, NULL, &r); } } diff --git a/meson.build b/meson.build index 4c5351d..4678f20 100644 --- a/meson.build +++ b/meson.build @@ -18,10 +18,11 @@ if get_option('build_frontends') == true curses = dependency('ncursesw')
endif
sdl = dependency('sdl2')
+ sdl2_ttf = meson.get_compiler('c').find_library('SDL2_ttf')
executable('cetris_curses', [src, 'frontend/ncurses/ncurses_ui.c'],
dependencies: curses,
install : false)
executable('cetris_sdl', [src, 'frontend/sdl/sdl_ui.c'],
- dependencies: sdl,
+ dependencies: [sdl, sdl2_ttf],
install : false)
endif
|