style: format in 2 spaces instead

This commit is contained in:
2025-03-01 18:12:58 +01:00
parent b0e5dc8cb0
commit f11b8a4a60
2 changed files with 91 additions and 98 deletions

View File

@@ -1,6 +1,6 @@
# Common settings
BasedOnStyle: llvm # WebKit
TabWidth: 4
IndentWidth: 4
TabWidth: 2
IndentWidth: 2
UseTab: Never
ColumnLimit: 80
ColumnLimit: 100

View File

@@ -7,14 +7,15 @@
static SDL_Window *window = NULL;
static SDL_Renderer *renderer = NULL;
static int width = 640;
static int height = 480;
static int window_width = 640;
static int window_height = 480;
static int grid_width = 32;
static int grid_height = 24;
static Uint64 last;
enum TILES { EMPTY, SNAKE, FRUIT };
enum PARTS { TAIL, HEAD, BODY };
typedef enum DIRECTION { LEFT, RIGHT, UP, DOWN } DIRECTION;
@@ -37,13 +38,9 @@ void log_game_grid(int *game_grid) {
SDL_free(buf);
}
void set_grid_at(int *grid, int row, int col, int value) {
grid[row * grid_width + col] = value;
}
void set_grid_at(int *grid, int row, int col, int value) { grid[row * grid_width + col] = value; }
int get_grid_at(int *grid, int row, int col) {
return grid[row * grid_width + col];
}
int get_grid_at(int *grid, int row, int col) { return grid[row * grid_width + col]; }
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) {
if (!SDL_Init(SDL_INIT_VIDEO)) {
@@ -51,8 +48,8 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) {
return SDL_APP_FAILURE;
}
if (!SDL_CreateWindowAndRenderer("examples/renderer/clear", width, height,
0, &window, &renderer)) {
if (!SDL_CreateWindowAndRenderer("examples/renderer/clear", window_width, window_height, 0,
&window, &renderer)) {
SDL_Log("Couldn't create window/renderer: %s", SDL_GetError());
return SDL_APP_FAILURE;
}
@@ -86,8 +83,7 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) {
}
SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) {
if ((event->type == SDL_EVENT_KEY_UP &&
event->key.scancode == SDL_SCANCODE_ESCAPE) ||
if ((event->type == SDL_EVENT_KEY_UP && event->key.scancode == SDL_SCANCODE_ESCAPE) ||
event->type == SDL_EVENT_QUIT) {
return SDL_APP_SUCCESS;
}
@@ -104,22 +100,19 @@ SDL_AppResult SDL_AppIterate(void *appstate) {
SDL_RenderClear(renderer);
SDL_FRect rect;
rect.w = (float)width / grid_width;
rect.h = (float)height / grid_height;
rect.w = (float)window_width / grid_width;
rect.h = (float)window_height / grid_height;
for (int i = 0; i < grid_height; i++) {
for (int j = 0; j < grid_width; j++) {
switch (get_grid_at(game_grid, i, j)) {
case EMPTY:
SDL_SetRenderDrawColorFloat(renderer, 0, 0, 0,
SDL_ALPHA_OPAQUE_FLOAT);
SDL_SetRenderDrawColorFloat(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE_FLOAT);
break;
case SNAKE:
SDL_SetRenderDrawColorFloat(renderer, 255, 255, 255,
SDL_ALPHA_OPAQUE_FLOAT);
SDL_SetRenderDrawColorFloat(renderer, 255, 255, 255, SDL_ALPHA_OPAQUE_FLOAT);
break;
case FRUIT:
SDL_SetRenderDrawColorFloat(renderer, 255, 0, 0,
SDL_ALPHA_OPAQUE_FLOAT);
SDL_SetRenderDrawColorFloat(renderer, 255, 0, 0, SDL_ALPHA_OPAQUE_FLOAT);
break;
}
rect.x = j * rect.w;