anonymous
2009-02-14 12:15:34 UTC
game.cpp
#include
#include
#include
using namespace std;
#include "game.h"
#define GAME_SPEED 33.3333 //this gives 30fps
bool game::run()
{
drawArea.DrawEngine();
level = new Level(&drawArea, 30, 20);
drawArea.createBackTile(TILE_EMPTY, ' ');
drawArea.createBackTile(TILE_WALL, 219);
drawArea.createSprite(SPRITE_PLAYER, 1);
drawArea.createSprite(SPRITE_ENEMY, '$');
player = new Character(level, &drawArea, 0);
level->draw();
level->addPlayer(player);
level->addEnemies(3);
char key = ' ';
startTime = timeGetTime();
frameCount = 0;
lastTime = 0;
posx = 0;
player->move(0, 0);
while(key != 'q')
{
while(!getInput(&key))
{
timerUpdate();
}
level->keyPress(key);
}
delete player;
// cout << frameCount / ((timeGetTime() - startTime) / 1000) << " fps" << endl;
return true;
}
bool game::getInput(char *c)
{
if(_kbhit())
{
*c = _getch();
return true;
}
return false;
}
void game::timerUpdate(void)
{
double currentTime = timeGetTime() - lastTime;
level->update();
if(currentTime < GAME_SPEED)
return;
frameCount++;
lastTime = timeGetTime();
}
however, I get this when I debug:
Unhandled exception at 0x00418305 in evilMonkies.exe: 0xC0000005: Access violation reading location 0x808e6398.
It then closes the window.
Any help?