summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPreston Pan <preston@nullring.xyz>2023-02-06 12:03:16 -0800
committerPreston Pan <preston@nullring.xyz>2023-02-06 12:03:16 -0800
commit59dd4d68c95142ceca1539491b0017985bd96357 (patch)
tree335f6e24c0303fb04fb6d8e55512bffa5e41e1bc
parent60992c31734d233d0cc8c3e8942fa1c173a67fde (diff)
add compiler flags for warnings for bad practice; snake game now gets harder the longer you go
-rw-r--r--Makefile4
-rw-r--r--snake.c5
-rw-r--r--snake.h2
3 files changed, 8 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index b4f7654..8a8265b 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,6 @@
-CFLAGS=-I. -pthread -Wall -Wextra -std=c99 -Wpedantic
+CFLAGS=-I. -pthread -Wall -Wextra -Wpedantic -std=c99 -march=native -O3
+CFLAGS+= -Wshadow -Wstrict-prototypes -Wundef -Wpointer-arith -Wcast-align -Wstrict-overflow=5 -Wswitch-default
+CFLAGS+= -Wunreachable-code -Wswitch-enum -Wformat=2
PREFIX ?= /usr
BINDIR ?= ${PREFIX}/bin
MANDIR = ${PREFIX}/share/man/
diff --git a/snake.c b/snake.c
index ec1f79f..5a021a5 100644
--- a/snake.c
+++ b/snake.c
@@ -18,7 +18,7 @@ volatile sig_atomic_t INT_CTRL_C = 0; //flag for ctrl-c interrupt
int SCORE = 0;
int boardSize = 15;
-const int updateInterval = 300000000L;
+int updateInterval = 300000000L;
vectorp_t snakePositions;
vector_t foodPos;
@@ -115,6 +115,9 @@ int main(int argc, char **argv) {
if((snakePositions.vectors[0].mx + lastMoveDir.mx == foodPos.mx) && (snakePositions.vectors[0].my + lastMoveDir.my == foodPos.my)) {
ateFood = 1;
SCORE = SCORE + 1;
+ if (updateInterval > 50000000) {
+ updateInterval -= 20000000;
+ }
//move the food
while(1) {
foodPos = init_vector(1 + (rand() % (boardSize - 2)), 1 + (rand() % (boardSize - 2)));
diff --git a/snake.h b/snake.h
index 9675a17..3663456 100644
--- a/snake.h
+++ b/snake.h
@@ -8,5 +8,5 @@ typedef struct ThreadArg {
void* get_dir_loop(void* threadArg);
vector_t parse_dir(char cDir);
vectorp_t move_snake(vector_t dir, int lengthen);
-void draw_board();
+void draw_board(void);
#endif