mirror of
https://github.com/fredrikr79/SnakeDL3.git
synced 2025-12-24 03:00:21 +01:00
style: format in 2 spaces instead
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# Common settings
|
||||
BasedOnStyle: llvm # WebKit
|
||||
TabWidth: 4
|
||||
IndentWidth: 4
|
||||
TabWidth: 2
|
||||
IndentWidth: 2
|
||||
UseTab: Never
|
||||
ColumnLimit: 80
|
||||
ColumnLimit: 100
|
||||
|
||||
33
src/main.c
33
src/main.c
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user