Archived
1
Fork 0
This repository has been archived on 2024-10-07. You can view files and clone it, but cannot push or open issues or pull requests.
game_of_life/src/game.cpp
2024-09-11 22:48:22 +05:00

43 lines
801 B
C++

#include <SDL.h>
#include "drawing.h" // Draw in game loop
#include "events.h" // Handle events in loop
#include "game.h" // This file
#include "globals.h" // Timing macros
#include "grid.h" // Iterate the grid
#include "timing.h" // Timings
// Public
bool paused;
// Private
const double req_update_time = 1.0 / UPDATES_PER_SECOND;
double time_since_update;
void start_game() {
clear_grid();
paused = true;
time_since_update = 0;
while(true) {
game_loop();
limit_fps();
}
}
void game_loop() {
handle_events();
if (!paused) if ((time_since_update += delta_time) >= req_update_time) {
iterate_grid();
time_since_update -= req_update_time;
}
draw();
}
void toggle_pause() {
paused = !paused;
time_since_update = 0;
}