Compare commits

..

2 Commits

Author SHA1 Message Date
Justin 72a07395c7 Added the game loop the game. 2025-05-11 18:06:28 -05:00
Justin ee934b2d26 Added game.d to the list that was not needed. 2025-05-11 18:05:29 -05:00
5 changed files with 44 additions and 2 deletions

1
.gitignore vendored
View File

@ -6,3 +6,4 @@ banner.txt
print.d print.d
intro.d intro.d
sleep.d sleep.d
game.d

View File

@ -0,0 +1,26 @@
#include "include/game.h"
void Game::gameloop(){
//This is the main game loop.
const int target_fps = 15;
const std::chrono::duration<double> target_frame_duration = chrono::duration<double>(1.0 / target_fps);
auto previous_time = std::chrono::steady_clock::now();
while(true){
auto current_time = std::chrono::steady_clock::now();
chrono::duration<double> elapsed_time = current_time - previous_time;
// Game logic and rendering here
system("clear");
cout << "Frame time: " << elapsed_time.count() << " seconds" << endl;
if (elapsed_time < target_frame_duration) {
chrono::duration<double> sleep_time = target_frame_duration - elapsed_time;
this_thread::sleep_for(sleep_time);
}
previous_time = chrono::steady_clock::now();
}
}

View File

@ -0,0 +1,12 @@
#include <iostream>
#include <chrono>
#include <thread>
#include <cstdlib>
using namespace std;
class Game{
public:
void gameloop();
};

View File

@ -2,4 +2,5 @@
#include "intro.h" #include "intro.h"
#include "title.h" #include "title.h"
#include <cstdlib> #include <cstdlib>
#include "game.h"
using namespace std; using namespace std;

View File

@ -5,7 +5,9 @@ int main (){
//Title title; //Title title;
Title::mainTitle(); Title::mainTitle();
//Intro intro; //Intro intro;
Intro::mainIntro(); //Intro::mainIntro();
//cin >> ; Game game;
game.gameloop();
cin.get();
return 0; return 0;
} }