resize screen
This commit is contained in:
38
snake/snek.c
38
snake/snek.c
@@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
/* } Map; */
|
/* } Map; */
|
||||||
|
|
||||||
const int screenHeight = 800;
|
int screenHeight = 800;
|
||||||
const int screenWidth = 800;
|
int screenWidth = 800;
|
||||||
int fps = 60;
|
int fps = 60;
|
||||||
int rows = 10;
|
int rows = 10;
|
||||||
int cols = 10;
|
int cols = 10;
|
||||||
@@ -187,25 +187,25 @@ void draw_grid(int size){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_game(){
|
void calculate_tile_size(){
|
||||||
InitWindow(screenHeight, screenHeight, "Snek");
|
|
||||||
SetTargetFPS(fps);
|
|
||||||
|
|
||||||
int width = screenWidth / cols;
|
int width = screenWidth / cols;
|
||||||
int height = screenHeight / rows;
|
int height = screenHeight / rows;
|
||||||
size = height > width ? width : height;
|
size = height > width ? width : height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void init_game(){
|
||||||
|
InitWindow(screenHeight, screenHeight, "Snek");
|
||||||
|
SetTargetFPS(fps);
|
||||||
|
calculate_tile_size();
|
||||||
|
}
|
||||||
|
|
||||||
int main(void){
|
int main(void){
|
||||||
|
|
||||||
init_game();
|
init_game();
|
||||||
Snake snek = make_snake(100, 5);
|
Snake snek = make_snake(100, 5);
|
||||||
|
int b;
|
||||||
while (!WindowShouldClose()){
|
while (!WindowShouldClose()){
|
||||||
BeginDrawing();
|
|
||||||
|
|
||||||
ClearBackground(WHITE);
|
|
||||||
draw_grid(size);
|
|
||||||
if (snek.alive){
|
if (snek.alive){
|
||||||
update_snake(&snek);
|
update_snake(&snek);
|
||||||
} else {
|
} else {
|
||||||
@@ -214,6 +214,24 @@ int main(void){
|
|||||||
if (food_x >= 0){
|
if (food_x >= 0){
|
||||||
DrawRectangle(size * food_x, size * food_y, size, size, RED);
|
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);
|
draw_snake(&snek);
|
||||||
DrawText(score_text, 0, 0, 20, BLACK);
|
DrawText(score_text, 0, 0, 20, BLACK);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user