63 lines
1.7 KiB
C
63 lines
1.7 KiB
C
//
|
|
// Created by tony on 11/28/2024.
|
|
//
|
|
|
|
#include "game.h"
|
|
|
|
void gameINIT(Game *pGame)
|
|
{
|
|
pGame->hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
GetConsoleScreenBufferInfo(&pGame->hConsole, &pGame->csbi);
|
|
clearConsole();
|
|
|
|
SMALL_RECT region = {
|
|
.Top = 0,
|
|
.Left = 0,
|
|
.Bottom = 29,
|
|
.Right = 180
|
|
};
|
|
|
|
// INIT Entities
|
|
const int MAX_ENTITIES = 10;
|
|
Entity *entities = NULL;
|
|
append(&entities, 0, 'X', 'P', (COORD) {(SHORT) 20, (SHORT) 20});
|
|
append(&entities, 1, 'N', 'N', (COORD) {10, 10});
|
|
append(&entities, 2, 'N', 'N', (COORD) {11, 10});
|
|
append(&entities, 3, 'N', 'N', (COORD) {12, 10});
|
|
append(&entities, 4, 'N', 'N', (COORD) {13, 10});
|
|
struct Entity *bufferEntity;
|
|
|
|
// 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)
|
|
{
|
|
clock_t startTime = clock();
|
|
GetConsoleScreenBufferInfo(&pGame->hConsole, &pGame->csbi);
|
|
|
|
getUserInput(&entities[0], ®ion);
|
|
|
|
printList(&pGame->hConsole,*pGame->charsWritten,&entities);
|
|
|
|
// 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();
|
|
}
|
|
|
|
freeList(&entities);
|
|
} |