Updated code
This commit is contained in:
79
game.c
Normal file
79
game.c
Normal file
@@ -0,0 +1,79 @@
|
||||
//
|
||||
// Created by tony on 11/28/2024.
|
||||
//
|
||||
|
||||
#include "game.h"
|
||||
|
||||
void gameINIT(Game *pGame)
|
||||
{
|
||||
Game game = *pGame;
|
||||
//HANDLE hConsole = &pGame->hConsole;
|
||||
//CONSOLE_SCREEN_BUFFER_INFO *pCsbi = &game.csbi;
|
||||
//GetConsoleScreenBufferInfo(hConsole, pCsbi);
|
||||
clearConsole();
|
||||
|
||||
SMALL_RECT region = {
|
||||
.Top = 0,
|
||||
.Left = 0,
|
||||
.Bottom = 29,
|
||||
.Right = 180
|
||||
};
|
||||
|
||||
// INIT Entities
|
||||
// const int MAX_ENTITIES = 10;
|
||||
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}};
|
||||
// append(&pEntities, 0, (char)'X', (char)'P', (COORD) {(SHORT) 20,(SHORT) 20});
|
||||
/*append(&pEntities, 1, (char)'N', (char)'N', (COORD) {(SHORT) 10,(SHORT) 10});
|
||||
append(&pEntities, 2, (char)'N', (char)'N', (COORD) {(SHORT) 11,(SHORT) 10});
|
||||
append(&pEntities, 3, (char)'N', (char)'N', (COORD) {(SHORT) 12,(SHORT) 10});
|
||||
append(&pEntities, 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(&pGame->hConsole,
|
||||
&pGame->csbi);
|
||||
|
||||
//printBoundsToConsole(&pGame->hConsole,
|
||||
// pGame->charsWritten,
|
||||
// game.csbi.srWindow);
|
||||
|
||||
getUserInput(&pEntities[0],
|
||||
®ion);
|
||||
|
||||
printList(&pGame->hConsole,
|
||||
pGame->charsWritten,
|
||||
&entities);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
//freeList(&entities);
|
||||
}
|
||||
Reference in New Issue
Block a user