diff options
-rw-r--r-- | snake/snek.c | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/snake/snek.c b/snake/snek.c index 1021015..7868c0d 100644 --- a/snake/snek.c +++ b/snake/snek.c @@ -6,8 +6,8 @@ /* } Map; */ -const int screenHeight = 800; -const int screenWidth = 800; +int screenHeight = 800; +int screenWidth = 800; int fps = 60; int rows = 10; int cols = 10; @@ -187,25 +187,25 @@ void draw_grid(int size){ } } -void init_game(){ - InitWindow(screenHeight, screenHeight, "Snek"); - SetTargetFPS(fps); - +void calculate_tile_size(){ int width = screenWidth / cols; int height = screenHeight / rows; size = height > width ? width : height; } +void init_game(){ + InitWindow(screenHeight, screenHeight, "Snek"); + SetTargetFPS(fps); + calculate_tile_size(); +} + int main(void){ init_game(); Snake snek = make_snake(100, 5); - + int b; while (!WindowShouldClose()){ - BeginDrawing(); - ClearBackground(WHITE); - draw_grid(size); if (snek.alive){ update_snake(&snek); } else { @@ -214,6 +214,24 @@ int main(void){ if (food_x >= 0){ DrawRectangle(size * food_x, size * food_y, size, size, RED); } + + if (IsKeyPressed(KEY_R)){ + if (b){ + screenWidth = screenHeight = 500; + /* MinimizeWindow(); */ + } else { + screenWidth = screenHeight = 800; + /* MaximizeWindow(); */ + } + SetWindowSize(screenWidth, screenHeight); + calculate_tile_size(); + b = !b; + } + + BeginDrawing(); + + ClearBackground(WHITE); + draw_grid(size); draw_snake(&snek); DrawText(score_text, 0, 0, 20, BLACK); |