mirror of
https://github.com/fredrikr79/SnakeDL3.git
synced 2026-01-11 20:03:07 +01:00
--wip-- [skip ci]
This commit is contained in:
3
Makefile
3
Makefile
@@ -5,6 +5,9 @@ clean:
|
||||
compile:
|
||||
gcc -W -Wall -Wextra -pedantic -o out/main src/main.c src/utils/arena.c src/utils/vector.c -Iinclude -Iutils -lpthread -Llib -lSDL3
|
||||
|
||||
debug:
|
||||
gcc -W -Wall -Wextra -pedantic -g -O0 -o out/main_debug src/main.c src/utils/arena.c src/utils/vector.c -Iinclude -Iutils -lpthread -Llib -lSDL3
|
||||
|
||||
run:
|
||||
make compile
|
||||
./out/main
|
||||
|
||||
11
src/main.c
11
src/main.c
@@ -1,4 +1,3 @@
|
||||
#include "SDL3/SDL_stdinc.h"
|
||||
#define SDL_MAIN_USE_CALLBACKS 1
|
||||
#include "utils/arena.h"
|
||||
#include "utils/vector.h"
|
||||
@@ -44,10 +43,10 @@ typedef struct State {
|
||||
static Arena arena;
|
||||
|
||||
#define INDEX_AT(row, col) ((row) * GRID_WIDTH + (col))
|
||||
#define ROW_AT(index) (index / GRID_WIDTH)
|
||||
#define COL_AT(index) (index % GRID_WIDTH)
|
||||
#define SET_GRID_AT(grid, row, col, value) grid[INDEX_AT(row, col)] = value
|
||||
#define GET_GRID_AT(grid, row, col) grid[INDEX_AT(row, col)]
|
||||
#define ROW_AT(index) ((index) / GRID_WIDTH)
|
||||
#define COL_AT(index) ((index) % GRID_WIDTH)
|
||||
#define SET_GRID_AT(grid, row, col, value) (grid)[INDEX_AT((row), (col))] = (value)
|
||||
#define GET_GRID_AT(grid, row, col) (grid)[INDEX_AT((row), (col))]
|
||||
|
||||
void log_game_grid(Uint8 *game_grid) {
|
||||
char buf[GRID_WIDTH * 2];
|
||||
@@ -184,7 +183,7 @@ SDL_AppResult SDL_AppIterate(void *appstate) {
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, COLOR_SNAKE);
|
||||
for (int i = 0; i < playerptr->length; i++) {
|
||||
int b = vector_pop(playerptr->body);
|
||||
int b = playerptr->body->data[i];
|
||||
rect.x = startx + ROW_AT(b) * (rect.w + GRID_PADDING);
|
||||
rect.y = starty + COL_AT(b) * (rect.h + GRID_PADDING);
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
|
||||
@@ -48,6 +48,10 @@ void vector_pusha(Vector *v, int *vals, int n) {
|
||||
}
|
||||
|
||||
int vector_pop(Vector *v) {
|
||||
if (v->size < 1) {
|
||||
printf("vector_pop: popping empty vector");
|
||||
return 0;
|
||||
}
|
||||
int val = v->data[v->size - 1];
|
||||
v->size--;
|
||||
return val;
|
||||
|
||||
Reference in New Issue
Block a user