#include "PreCompile.h"
#include "Game.h"
#include "Util.h"
#include "ResManager.h"
#include "AtlasImage.h"
#include "AtlasMaster.h"
Game::Game()
{
}
Game::~Game()
{
g_resManager.Release();
}
void Game::Init(const string& dirResources, const string& dirUser, int screenWidth, int screenHeight)
{
#ifndef APPSTORE_BUILD
int timeNow = GetMilliSeconds();
#endif
try
{
g_resManager.Init(dirResources, dirUser, screenWidth, screenHeight);
const char* szAnim[NUM_FRAMES] = {"earflap02", "earflap04", "earflap06",
"earflap08", "earflap06", "earflap04", "earflap02", "base", "base", "base",
"base", "base", "base", "base", "base", "base",
"trunk_swing01", "trunk_swing03", "trunk_swing05",
"trunk_swing03", "trunk_swing01", "base", "trunk_swing13",
"trunk_swing15", "trunk_swing17", "trunk_swing15", "trunk_swing13", "base",
"base", "base", "base", "base", "base", "base",
"base", "base", "base", "base", "base", "base"
};
m_currFrame = 0;
m_age = 0;
for (int n = 0; n < NUM_FRAMES; n++)
{
m_pImage[n] = g_resManager.GetAtlasMaster()->GetImage(szAnim[n]);
}
// m_pImage[0] = g_resManager.GetAtlasMaster()->GetImage("mercYob");
}
catch(RacException ex)
{
m_strErr = ex.GetStrErr();
cout << ex.GetStrErr() << endl;
return;
}
m_timeLast = GetMilliSeconds();
#ifndef APPSTORE_BUILD
int timeElapsed = abs(m_timeLast-timeNow);
cout << "startup time:" << timeElapsed << "ms" << endl;
#endif
} // Init
void Game::Render()
{
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
int timeNow = GetMilliSeconds();
int timeElapsed = abs(timeNow - m_timeLast);
m_age += timeElapsed;
// 12 frames per second
m_currFrame = m_age*12/1000;
if (m_currFrame >= NUM_FRAMES)
{
m_currFrame = 0;
m_age = 0;
}
m_pImage[m_currFrame]->Render(10, 10);
// m_pImage[0]->Render(10, 10);
m_timeLast = timeNow;
}
int Game::GetWaitTime(int timeRender)
{
int waitTime;
waitTime = GetReqFrameTime()-timeRender;
if (waitTime < 1) waitTime = 1;
return waitTime;
}
int Game::GetReqFrameTime()
{
return 15;
}