43 lines
801 B
C++
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;
|
|
}
|