The code now properly updates and writes to the console.
This commit is contained in:
64
main.c
64
main.c
@@ -13,13 +13,69 @@ int randomSeed[78] = {
|
||||
int main()
|
||||
{
|
||||
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
COORD coordScreen = {0, 0};
|
||||
//COORD coordScreen = {0, 0};
|
||||
DWORD cCharsWritten;
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
GetConsoleScreenBufferInfo(hConsole, &csbi);
|
||||
DWORD dwConSize;
|
||||
struct Game game = {0, GetStdHandle(STD_OUTPUT_HANDLE), csbi, &cCharsWritten};
|
||||
Game *pGame = &game;
|
||||
gameINIT(pGame);
|
||||
//struct ConsoleApp game = {0, hConsole, &csbi, &cCharsWritten};
|
||||
//ConsoleApp *pGame = &game;
|
||||
//consoleInit(pGame);
|
||||
Entity entities[10];
|
||||
//Entity *pEntities = &entities;
|
||||
entities[0] = (Entity) {0, (char)'X', (char)'P', (COORD) {(SHORT) 20,(SHORT) 20}};
|
||||
entities[1] = (Entity) {1, (char)'N', (char)'N', (COORD) {(SHORT) 10,(SHORT) 10}};
|
||||
entities[2] = (Entity) {2, (char)'N', (char)'N', (COORD) {(SHORT) 11,(SHORT) 10}};
|
||||
entities[3] = (Entity) {3, (char)'N', (char)'N', (COORD) {(SHORT) 12,(SHORT) 10}};
|
||||
entities[4] = (Entity) {4, (char)'N', (char)'N', (COORD) {(SHORT) 13,(SHORT) 10}};
|
||||
|
||||
// INIT Clock targeting
|
||||
const int targetFPS = 60; // Target frames per second
|
||||
const int frameDelay = 1000 / targetFPS; // Frame duration in milliseconds
|
||||
|
||||
// Main Loop
|
||||
bool run = true;
|
||||
while (run)
|
||||
{
|
||||
|
||||
//GetConsoleScreenBufferInfo(hConsole, &csbi);
|
||||
|
||||
// printList(&hConsole,
|
||||
// &cCharsWritten,
|
||||
// entities);
|
||||
|
||||
getUserInput(&entities[0],&csbi.srWindow);
|
||||
|
||||
for (int counter = 0; counter < 5 ;counter++)
|
||||
{
|
||||
WriteConsoleOutputCharacter(hConsole,
|
||||
&entities[counter].avatar,
|
||||
1,
|
||||
entities[counter].position,
|
||||
&cCharsWritten);
|
||||
}
|
||||
|
||||
clock_t startTime = clock();
|
||||
// Calculate the elapsed time and delay if necessary
|
||||
clock_t elapsedTime = clock() - startTime;
|
||||
int delayTime = frameDelay - (elapsedTime * 1000 / CLOCKS_PER_SEC);
|
||||
|
||||
// Ensure the frame time does not exceed the target FPS
|
||||
if (delayTime > 0)
|
||||
{
|
||||
Sleep(delayTime);
|
||||
}
|
||||
|
||||
if (GetAsyncKeyState(VK_ESCAPE))
|
||||
{
|
||||
run = false;
|
||||
}
|
||||
clearConsole();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user