/*******************************************************************
  Clean up DirectX
*******************************************************************/
void CGraphics::CleanupDirectX(){
  CLog *pLog = CLog::Instance();
  pLog->Log("Cleanup");

  DeleteLost();
  pLog->Log("cleanup 1");
  m_d3ddev->Release(); // close and release the 3D device
  m_d3d->Release(); // close and release Direct3D
  
  pLog->Log("cleanup 2");
    return;
}
void CGraphics::ReloadLost(){
  CLog *pLog = CLog::Instance();
  pLog->Log("Reloading sprite and fonts");
  if(FAILED( D3DXCreateSprite(m_d3ddev, &m_pSprite)) )
  {
    ::MessageBox(m_hWnd, "Failed to create a sprite!", "Fatal Error!", 0);//MB_OK | MB_ICONSTOP | MB_APPLMODAL);
    return;
  }
  InitializeFonts();
  SetupStuff();

  //lighting stuff
  m_d3ddev->SetRenderState(D3DRS_LIGHTING, true);
  D3DLIGHT9 dir;
  ::ZeroMemory(&dir, sizeof(dir));
  dir.Type = D3DLIGHT_DIRECTIONAL;
  dir.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
  dir.Specular = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f) * 0.3f;
  dir.Ambient = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f) * 2.6f;
  dir.Direction = D3DXVECTOR3(0.0f, -100.0f, 0.0f);

  m_d3ddev->SetLight(0, &dir);
  m_d3ddev->LightEnable(0, true);
  m_d3ddev->SetRenderState(D3DRS_NORMALIZENORMALS, true);
  m_d3ddev->SetRenderState(D3DRS_SPECULARENABLE, true);
}
/****************************************************
 Loads texture files and skins
****************************************************/
bool CGraphics::LoadTextureFile(int fileID, std::string filename){
  S_TEXTURE temp;

  CLog *pLog = CLog::Instance();
  HRESULT hr = D3DXCreateTextureFromFile(m_d3ddev, filename.c_str(),&temp.pBuffer);
  
  if(FAILED(hr)){
    pLog->Log("Failed to load texture file ", filename);
    return false;
  }
  else{
    pLog->Log("Texture loaded correctly!");
  }
  temp.id = fileID;
  m_texture.push_back(temp);
  return true;
}
bool CAudioManager::LoadAssetFile(std::string filename){
  CLog *pLog = CLog::Instance();

  //read assets.dat file
  CFileReader cfr(filename);
  if(cfr.IsValid() == false)
    return false; //file is invalid or contains no usable data

  //validate asset data and add to appropriate vectors
  std::string parameter;
  std::string assetType;
  SOUND_FILE_DATA     tempSound;

  for(int i = 0; i < cfr.GetNumberOfLines(); ++i){

    //process only lines with 2 or more terms
    if(cfr.GetNumberOfTermsFromLine(i) > 1){
      assetType = cfr.GetTerm(cfr.GetLineFromFile(i), 1);
     
      if(assetType == "soundfile" && cfr.GetNumberOfTermsFromLine(i) == 4){
        parameter = cfr.GetTerm(cfr.GetLineFromFile(i), 2);//sound ID
        tempSound.soundID = atoi(parameter.c_str());
        parameter = cfr.GetTerm(cfr.GetLineFromFile(i), 3);//filename
        tempSound.filename = parameter;
        parameter = cfr.GetTerm(cfr.GetLineFromFile(i), 4);//description
        tempSound.description = parameter;
        m_assetSoundData.push_back(tempSound);
        pLog->Log("****** soundfile added *******");
        pLog->Log("soundID", tempSound.soundID);
        pLog->Log("filename", tempSound.filename);
        pLog->Log("description", tempSound.description);        
      }
    }
  }

  //load sound information
  for(int i = 0; i < m_assetSoundData.size(); ++i){
    LoadSample(m_assetSoundData[i].soundID,
               "assets\\sounds\\" + m_assetSoundData[i].filename);
    pLog->Log("Loaded into memory", m_assetSoundData[i].filename);
  }

  return true;
}
void CGameStateIntro::Activate(CGameData &data, CConfigData &cfg, CGraphics &con){
  CLog *pLog = CLog::Instance();

  //pyro setup
  //**********************
  m_effect.Init(con.m_d3ddev);
  m_effect.LoadFile(cfg.EffectsFileI);//"assets\\data\\effects_i.dat");
  m_effectNumber = 0;
  m_effectMax = m_effect.GetNumberEffects();
  pLog->Log("******* Number of Intro Screen effects loaded", m_effectMax);

  m_startTime = ::timeGetTime();
}
void cGameStateIntro::render(CGraphics &con, Camera &cam, CGameData &data){
  ::ShowCursor(false);
  CLog *pLog = CLog::Instance();
  static bLostDevice = false;

  HRESULT hr;

  if(FAILED(hr = con.m_d3ddev->TestCooperativeLevel())){
    pLog->Log("Failed test");
    if(hr == D3DERR_DEVICELOST)
      return;
    pLog->Log("No lost");
    if( hr == D3DERR_DEVICENOTRESET ){
      pLog->Log("Time to reset");
      con.DeleteLost();
      pLog->Log("Deleted everything");
      hr = con.m_d3ddev->Reset(&con.GetDPP());
      pLog->Log("Dev reset");
      con.ReloadLost();
      pLog->Log("ReloadLost");
      bLostDevice = false;
      return;
    }
  }

  D3DXMATRIX V;
  cam.getViewMatrix(&V, 0);
  con.m_d3ddev->SetTransform(D3DTS_VIEW, &V);

  // clear the window to a deep blue
  con.m_d3ddev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 30, 0), 1.0f, 0);
  con.m_d3ddev->BeginScene();    // begins the 3D scene

  GRAPHIC_IMAGE gi;
  gi = con.GetSprite(20);
  con.RenderGraphicModulate(gi, data.m_screenWidth/2 - gi.width/2, data.m_screenHeight/2 - gi.height/2, 255, 255, 255);
  con.Print("Press SPACEBAR to Continue!", F_V20B, data.m_screenWidth/2 - 130, data.m_screenHeight - 60, 255, 255, 0, 255);

  if(data.m_displayDebugInfo == true){
    con.Print("Version", data.m_version, F_V16, 10, 10,  255, 255, 255, 255);
    con.Print("FPS", data.m_FPS , F_V16, 10, 30,  255, 255, 255, 255);
  }

  con.m_d3ddev->EndScene();    // ends the 3D scene
  hr = con.m_d3ddev->Present(NULL, NULL, NULL, NULL);   // displays the created frame on the screen

  if(FAILED(hr = con.m_d3ddev->TestCooperativeLevel())){
    if(hr == D3DERR_DEVICELOST)
      bLostDevice = true;
  }

  return;
}
Пример #7
0
void Shutdown()
{
  CLog *pLog = CLog::Instance();
  CAudioManager *pAudio = CAudioManager::Instance();
  pLog->Log("************ Shutting Down ************");
	// Properly shut down the current game object first
	g_pCurrent->deactivate();
	delete g_pStatePlay;
  delete g_pStateMain;
  delete g_pStateIntro;
  delete g_pStateHistory;
  delete g_pStateReload;
  delete g_pStateCredits;
  delete g_pStateSelect;
  delete g_pStateAwards;
  delete g_pStateWin;
  delete g_pStateLose;
  delete g_pStateStatus;
  delete g_pStateChart;
  delete g_pStateControl;
  delete g_pStateEnd;
  delete g_pStateScope;
  delete g_pStateSonar;
  delete g_pStateFireControl;
  delete g_pStateRadar;

  pLog->Log("Game state pointers deleted!");
  pAudio->KillAll();
  ::ShowCursor(false);
	//::Sleep(2000);
	//::ShowCursor(true); //turn mouse cursor back on
	pLog->Log("Audio sounds are all killed!");
	pLog->Log("*************************************");
	pLog->Log("Program ended!");
	pLog->Log("*************************************");

	// Kill the main window
	DestroyWindow( g_hWnd );
	g_hWnd = NULL;
}
Пример #8
0
/**************************************************************
  Used to determine if player collides with a game object. The
  only game objects of concern are those on layer 6.  The next
  factor is the radius. 
  radius = 0 no risk of collision, ignore
  radius = -1, treat player and object as rectangles, look
           for overlap
  radius > 0, treat object and player as points with radii

**************************************************************/
bool CGameData::IsPlayerCollision(int index){
  CLog *pLog = CLog::Instance();
  GAME_OBJECT lastGo =  m_player.go;
  if(index < 0 || index > m_pObject.size() - 1)
    return false;

  if(m_pObject[index]->go.radius == 0)
    return false;

  float radius = 0;
  float distance = 0;
  float ax,ay,aw,ah,bx,by,bw,bh;
  float cx,cy,cw,ch;            
  float sl, sr, st, sb, sw, sh; //defines new rect
  float dx, dy;
  float ox, oy;
  float mx, my;

  //rectangular collision - radius == -1
  if(m_pObject[index]->go.radius == -1 && m_pObject[index]->go.layer != 7){
    
    //step 1 of algorithm
    ox = m_pObject[index]->go.pos.x - m_player.go.pos.x;
    oy = m_pObject[index]->go.pos.y - m_player.go.pos.y;

    //step #2 of algorithm
    if(abs(ox) < 32 && abs(oy) < 32){
      
      //step #3 of algorithm
      mx = 0;
      my = 0;
      if(oy >= 0)
        my = oy - 32;
      if(oy < 0)
        my = oy + 32;
      if(ox >= 0)
        mx = ox -32;
      if(ox < 0)
        mx = ox + 32;

      //step #4 of algorithm
      m_player.go.pos.x += mx/2;
      m_player.go.pos.y += my/2;

      return true;
  
    }

    /*
    dx = abs(m_player.go.pos.x - m_pObject[index]->go.pos.x);
    dy = abs(m_player.go.pos.y - m_pObject[index]->go.pos.y);
    cx = m_pObject[index]->go.width/2 + 16;
    cy = m_pObject[index]->go.height/2 + 16;

    if(dx < (cx - 4) && dy < (cy - 4)){  //6
      if(m_player.go.pos.x <= m_pObject[index]->go.pos.x)      
        m_player.go.pos.x -= 8;
      else
        m_player.go.pos.x += 8;

      if(m_player.go.pos.y <= m_pObject[index]->go.pos.y)      
        m_player.go.pos.y -= 8;
      else
        m_player.go.pos.y += 8;

      return true;   
    }
    */
  }

  //distance - radius > 0
  else if(m_pObject[index]->go.layer != 7){
  
    radius =  m_pObject[index]->go.radius + 16; //replace with player radius
    distance = sqrt( ((m_player.go.pos.x - m_pObject[index]->go.pos.x) *
                      (m_player.go.pos.x - m_pObject[index]->go.pos.x)) +
                     ((m_player.go.pos.y - m_pObject[index]->go.pos.y) *
                      (m_player.go.pos.y - m_pObject[index]->go.pos.y)) );

    if(distance < radius){
      return true;
    }
  }

  //these are power ups
  else if(m_pObject[index]->go.radius == -1 && m_pObject[index]->go.layer == 7){
    radius =  m_pObject[index]->go.radius + 32; //replace with player radius
    distance = sqrt( ((m_player.go.pos.x - m_pObject[index]->go.pos.x) *
                      (m_player.go.pos.x - m_pObject[index]->go.pos.x)) +
                     ((m_player.go.pos.y - m_pObject[index]->go.pos.y) *
                      (m_player.go.pos.y - m_pObject[index]->go.pos.y)) );

    if(distance < radius){
      pLog->Log("Delete weapon find!");
      return true;
    }
  }
  return false;
}
Пример #9
0
cGameStateObject* cGameStateChart::update(double timeDifference){
  m_event = EVENT_GO_NO_WHERE;
  //loads mouse position into global variable.
  
  POINT pt;
  POINT *ppt = &pt;
  ::GetCursorPos(ppt);
  RECT rct;
  ::GetWindowRect(g_hWnd, &rct);
  g_Global.g_mouse.x = pt.x - rct.left;
  g_Global.g_mouse.y = pt.y - rct.top;
  
  CGameData *pData = CGameData::Instance();
  //start ambient sound loop
  CAudioManager *pAudio = CAudioManager::Instance();
  if(pAudio->IsPlaying(SOUND_AMBIENCE1) == false)
    pAudio->PlaySoundClip(SOUND_AMBIENCE1, 1);

  if(pData->m_bAttack == true){
    if(pAudio->IsPlaying(SOUND_PING) == false)
      pAudio->PlaySoundClip(SOUND_PING,0);
  }

  if(pData->m_bDropped == true && pAudio->IsPlaying(SOUND_DEPTH_CHARGE2) == false)
        pAudio->PlaySoundClip(SOUND_DEPTH_CHARGE2, 0);

  //update all targets, sub, torpedos, and depth charges
  pData->Update(timeDifference);

  static double timeDiffTotal = 0;
  timeDiffTotal += timeDifference;
  if(timeDiffTotal > .11){
    timeDiffTotal = 0;

    if(keyDown(VK_SPACE) == true && ::GetActiveWindow() == g_hWnd){
      CLog *pLog = CLog::Instance();
      pLog->Log("Tautog ...............");
      pLog->Log("subX", (long)pData->m_Player.m_posX);
      pLog->Log("subY", (long)pData->m_Player.m_posY);
      pLog->Log("subH", pData->m_Player.m_heading);
      pLog->Log("subS", pData->m_Player.m_speed);
      pLog->Log("..............");

      for(int i = 0; i < pData->m_targets.size(); ++i){
        pLog->Log("target", i);
        pLog->Log("targetX", (long)pData->m_targets[i].m_posX);
        pLog->Log("targetY", (long)pData->m_targets[i].m_posY);
        pLog->Log("targetH", pData->m_targets[i].m_heading);
        pLog->Log("targetS", pData->m_targets[i].m_speed);
        pLog->Log("targetTB", pData->m_targets[i].m_trueBearing);
        pLog->Log("targetRB", pData->m_targets[i].m_relativeBearing);
        pLog->Log("targetAOB",(int)pData->m_targets[i].m_AOB);
        pLog->Log("targetAOBindex", pData->m_targets[i].m_AOBindex);
        pLog->Log(".......................");
      }
    }

    //process short cut buttons
    if(g_Global.g_mouse.y > 10 && g_Global.g_mouse.y < 130 
      && g_Global.g_bLeftMouseDown == true && ::GetActiveWindow() == g_hWnd){
      //if(g_Global.g_mouse.x > 10 && g_Global.g_mouse.x < 110)
      //  m_event = EVENT_GO_SONAR;
      //else if(g_Global.g_mouse.x > 120 && g_Global.g_mouse.x < 220)
      //  m_event = EVENT_GO_RADAR;
      if(g_Global.g_mouse.x > 230 && g_Global.g_mouse.x < 330)
        m_event = EVENT_GO_CONTROL;
      //else if(g_Global.g_mouse.x > 694 && g_Global.g_mouse.x < 794)
      //  m_event = EVENT_GO_FIRECONTROL;
      //else if(g_Global.g_mouse.x > 804 && g_Global.g_mouse.x < 904)
      //  m_event = EVENT_GO_STATUS;
    } 
    else if(g_Global.g_mouse.x > 806 && g_Global.g_mouse.x < 1006 
      && g_Global.g_bLeftMouseDown == true && ::GetActiveWindow() == g_hWnd){
        if(g_Global.g_mouse.y > 134 && g_Global.g_mouse.y < 249){//zoom in
          m_chartScaleIndex++;
          if(m_chartScaleIndex > 4)
            m_chartScaleIndex = 4;
        }
        else if(g_Global.g_mouse.y > 269 && g_Global.g_mouse.y < 384){//zoom out
          m_chartScaleIndex--;
          if(m_chartScaleIndex < 0)
            m_chartScaleIndex = 0;
        }
    }
  }
  
  //this controls game states
  if(pData->m_missionOver == MISSION_OVER_WIN  )
    m_event = EVENT_GO_WIN;
  else if(pData->m_missionOver == MISSION_OVER_DEAD || pData->m_missionOver == MISSION_OVER_TIMEOVER || pData->m_missionOver == MISSION_OVER_COLLISION )
    m_event = EVENT_GO_LOSE;

  for(unsigned int i=0; i< m_TE.size(); i++){
    if (m_TE[i].event == m_event){
      return m_TE[i].p_gso;
    }
  }
  return 0;
}
Пример #10
0
/***********************************************************************************
WinMain - Entry point for program.
***********************************************************************************/
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine, int nCmdShow)
{
    
    CLog *pLog = CLog::Instance();
    pLog->Log(" ");
    pLog->Log("***************************************");
    pLog->Log("Program Start"); 
    pLog->LogDate();   
    pLog->Log("***************************************");
    
    //request player choose fullscreen or windowed mode
    CConfigData cfg;
    cfg.LoadConfigFile("assets//data//config.cfg");
    bool bFullscreen = false;
    
    bFullscreen = cfg.FullScreen;
    int msgReturn = ::MessageBox(NULL, "Fullscreen? (Y/N)", "Select Display Option", MB_YESNO);
    if(msgReturn == IDYES)
      bFullscreen = true;

    //variable declarations
    CGameData gameData;
    CTimer gTimerFPS;
    int gLoopCount = 0;
    int gSecondCount = 0;
    bool g_bRunning = true;
    bool gExitProgram = false; //this is set true with ESC, for rendering to stop properly
    if(bFullscreen == true)
      gameData.m_windowedYOffset = 0;
    else
      gameData.m_windowedYOffset = 21;

    //determine if we play new or saved game
    /*
    gameData.m_playNewGame = true;
    HRESULT hr = ::MessageBox(0, "Play new game?", "New or saved game!", MB_YESNO);
    if(hr == IDYES)
      gameData.m_playNewGame = true;
    else
      gameData.m_playNewGame = false;
    */
    //gameData.m_playNewGame = true;

    //setup game data    

    pLog->Log("Program Name", cfg.ProgramName);
    pLog->Log("Version", cfg.ProgramVersion);

    //create window
    HWND hWnd;
    WNDCLASSEX wc;
    ZeroMemory(&wc, sizeof(WNDCLASSEX));
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = (WNDPROC)WindowProc;
    wc.hInstance = hInstance;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.lpszClassName = "WindowClass";
    wc.hIconSm = LoadIcon (hInstance, MAKEINTRESOURCE(IDI_ICON1)); 
    RegisterClassEx(&wc);
      
    /*
    //screen data - need at least 800x600 
    int cxScreen = ::GetSystemMetrics(SM_CXFULLSCREEN);
    int cyScreen = ::GetSystemMetrics(SM_CYFULLSCREEN);

    if(cfg.ScreenWidth < 800 || cfg.ScreenWidth > cxScreen)
      cfg.ScreenWidth = cxScreen;   
    if(cfg.ScreenHeight < 600 || cfg.ScreenHeight > cyScreen)
      cfg.ScreenHeight = cyScreen;    
    cfg.ScreenLeft = cxScreen/2 - cfg.ScreenWidth/2;
    cfg.ScreenTop = cyScreen/2 - cfg.ScreenHeight/2;
    */

    if(!bFullscreen)
       {
          if(cfg.ScreenWidth < 800)
          {
             cfg.ScreenWidth = 800; 
          }
                   if(cfg.ScreenHeight < 600)
          {
             cfg.ScreenHeight = 600;   
          }
       }
    cfg.ScreenLeft = 0;
    cfg.ScreenTop = 0;

/*
    // set up and initialize Direct3D
    CGraphics con();// cfg.FullScreen);
    int screenWidth = 0;
    int screenHeight = 0;
    if(con.InitializeDirectX(screenWidth, screenHeight, bFullscreen) == false){
      pLog->Log("Failure initializing DirectX!");
      ::MessageBox(0,"Failed to initialize DirectX", "Error", 0);
      return 0;
    }
    pLog->Log("DirectX Initialized");
*/

    int cxScreen = ::GetSystemMetrics(SM_CXFULLSCREEN);
    int cyScreen = ::GetSystemMetrics(SM_CYFULLSCREEN);
    if(cfg.ScreenWidth < 800 || cfg.ScreenWidth > cxScreen)
      cfg.ScreenWidth = cxScreen;   
    if(cfg.ScreenHeight < 600 || cfg.ScreenHeight > cyScreen)
      cfg.ScreenHeight = cyScreen;    
    cfg.ScreenLeft = cxScreen/2 - cfg.ScreenWidth/2;
    cfg.ScreenTop = cyScreen/2 - cfg.ScreenHeight/2;

    //create window
    std::string sCaption = cfg.ProgramName + " - " + cfg.ProgramVersion;
    hWnd = CreateWindowEx(NULL,
                          "WindowClass",
                          sCaption.c_str(), //cfg.ProgramVersion.c_str(),  
                          bFullscreen == true ? WS_EX_TOPMOST | WS_POPUP : WS_BORDER | WS_CAPTION | WS_SYSMENU,  
                          cfg.ScreenLeft, cfg.ScreenTop, 
                          /*0, 0, screenWidth, screenHeight,*/
                          
                          bFullscreen == true ? CW_USEDEFAULT : cfg.ScreenWidth, 
                          bFullscreen == true ? CW_USEDEFAULT : cfg.ScreenHeight,
                          
                          NULL,NULL,hInstance,NULL);
    ShowWindow(hWnd, nCmdShow);
    pLog->Log("Window Loaded and Displayed!");
    gameData.m_hWnd = hWnd;
/*
    // set up and initialize Direct3D
    CGraphics con(hWnd, cfg.ScreenWidth, cfg.ScreenHeight,bFullscreen);// cfg.FullScreen);
    if(con.InitializeDirectX() == false){
      pLog->Log("Failure initializing DirectX!");
      ::MessageBox(hWnd,"Failed to initialize DirectX", "Error", 0);
      return 0;
    }
    pLog->Log("DirectX Initialized");
 */
    CGraphics con(hWnd, cfg.ScreenWidth, cfg.ScreenHeight, bFullscreen);

    if(con.InitializeDirectX() == false)
    {
        ::MessageBox(hWnd, "Failed to Create IDirect3D9 Interface.", "Error", 0);
        return 0;
    }
    if(con.IsDisplayModeSupported() == false)
    {
        ::MessageBox(hWnd, "Display mode not supported.", "Error", 0);
        return 0;
    }
    if(con.InitializeDevice() == false)
    {
        ::MessageBox(hWnd, "Could not create IDirect3DDevice9 Device.", "Error", 0);
        return 0;
    }

    //load framework assets
    if(con.LoadAssetFile(cfg.FrameworkAssetFile) == false){
      pLog->Log("Failure loading " + cfg.FrameworkAssetFile);
      ::MessageBox(hWnd,"Failed to load editor.dat file", "Error", 0);
      return 0;
    }
    else
      pLog->Log(cfg.FrameworkAssetFile + " (frame graphics) was loaded successfully!");

    //load game play assets
    if(con.LoadAssetFile(cfg.GamePlayAssetFile) == false){
      pLog->Log("Failure loading " + cfg.GamePlayAssetFile);
      ::MessageBox(hWnd,"Failed to load assets.dat file", "Error", 0);
      return 0;
    }
    else
      pLog->Log(cfg.GamePlayAssetFile + " (game play graphics) was loaded successfully!");

     //load objects
    //***************************************************************************
    if(gameData.LoadObjectFile(cfg.GameObjectFile) == false){
      pLog->Log("Failure loading " + cfg.GameObjectFile);
      //::MessageBox(hWnd,"Failed to load objects.dat file", "Error", 0);
     // return 0;
    }
    else{
      pLog->Log(cfg.GameObjectFile + " (objects file) was loaded successfully!");
     // for(int i = 0; i < gameData.m_catalog.GetTableSize();++i){
//        pLog->Log("object", gameData.m_catalog.GetTerm(i, 0), gameData.m_catalog.GetTerm(i, 2));
     // }
    }

    gTimerKey.Initialize();
    gTimerKey.ResetTimer();
    mouse.SetHandle(hWnd);
    gTimerFPS.Initialize();
    
    //game timer for update
    CTimer timerGame;
    timerGame.Initialize();

    //define events for changing game states
    //*************************************************************************
    //g_pStateIntro->AddTransitionEvent(EVENT_GO_PLAY1, g_pStatePlay1);
    //g_pStatePlay1->AddTransitionEvent(EVENT_GO_CREDITS, g_pStateCredits);   
    g_pStateIntro->AddTransitionEvent(EVENT_GO_MAIN, g_pStateMain);
    g_pStateMain->AddTransitionEvent(EVENT_GO_PLAY1, g_pStatePlay1);
    g_pStateMain->AddTransitionEvent(EVENT_GO_HELP, g_pStateHelp);
    g_pStateMain->AddTransitionEvent(EVENT_GO_CREDITS, g_pStateCredits);
    g_pStatePlay1->AddTransitionEvent(EVENT_GO_QUIT, g_pStateQuit);
    //g_pStatePlay1->AddTransitionEvent(EVENT_GO_MAIN, g_pStateMain);

    g_pStateHelp->AddTransitionEvent(EVENT_GO_MAIN, g_pStateMain);
    g_pStateCredits->AddTransitionEvent(EVENT_GO_QUIT, g_pStateQuit);    
    g_pCurrent = g_pStatePlay1;// g_pStateIntro;


    // enter the main loop
    //************************************** M A I N  L O O P *****************
    MSG msg;
    pLog->Log("Entering Main Control Loop");
    float timeDiff = 0.0f;
    g_pCurrent->Activate(gameData, cfg, con);


    while(g_bRunning)
    {
      DWORD starting_point = GetTickCount();
      ::Sleep(0);
      if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
      {
          if (msg.message == WM_QUIT)
              break;

          TranslateMessage(&msg);
          DispatchMessage(&msg);
      }

      //manage frame count determination
      gLoopCount++;
      if(gTimerFPS.getTimer(1.0) == true){
        gameData.m_FPS = static_cast<float>(gLoopCount);
        gLoopCount = 0;   
        gSecondCount++;
        if(gSecondCount > 30){ //log every 30 seconds
          gSecondCount = 0;
          if(cfg.LogDebugInfo == true)
            pLog->Log("FPS",gameData.m_FPS);
        }
      }

      //stores mouse button status for use in other classes
      gameData.m_bLeftMouseDown =  mouse.LeftButtonDown();
      gameData.m_bRightMouseDown = mouse.RightButtonDown();
      
      //update
      g_pLast = g_pCurrent;
      g_pNext = g_pCurrent->Update(timerGame.getTimeDifference(), gameData, cfg, con);

      if(g_pNext == g_pStateQuit)
        g_bRunning = false;
      else if(NULL != g_pNext)
	    {
        if(g_pNext != g_pLast){
          g_pLast->Deactivate(gameData, cfg, con);
          g_pCurrent = g_pNext;
          g_pCurrent->Activate(gameData, cfg, con);
        }
      }  
      
      //render
      g_pCurrent->Render(con, gameData, cfg);

      // check the 'escape' key
      if(g_bRunning == false){
        gExitProgram = true;
        PostMessage(hWnd, WM_DESTROY, 0, 0);
      }
    }
    pLog->Log("Exited main loop");
    

    
    // clean up DirectX and COM
    con.CleanupDirectX();
    Shutdown();

    pLog->Log("DirectX Cleaned Up");
    pLog->Log("Shutdown complete!");
    pLog->Log("***************************************");
    pLog->Log(" Program Terminated Normally");
    pLog->Log("***************************************");

    return static_cast<int>(msg.wParam);
}
Пример #11
0
//********************************************************************
// main()
//********************************************************************
int main(){

  //instantiate log object and log
  CLog *pLog = CLog::Instance();
  pLog->Log("*********************************************************");
  pLog->Log("Program starting..................");
  pLog->SetDelimiter(':');
  pLog->LogDate();
  pLog->LogTime();
  pLog->Log("************************ *********************************");
   
  cout << "Enter name: ";
  cin >> g_playerName;
  //system("cls");

  //initialize console
  Console con(80, 25);//50);
  con.SetConsolePosition(0,0);
  con.CenterConsoleWindow();
  con.cls();

  Initialize();
  
  CONSOLE_SCREEN_BUFFER_INFO csbi = con.GetScreenBufferInfo();
  pLog->LogPair("Screen Buffer Size",csbi.dwSize.X, csbi.dwSize.Y);
  pLog->LogPair("Window Size",csbi.dwMaximumWindowSize.X, csbi.dwMaximumWindowSize.Y);
  pLog->LogPair("Left-Top",csbi.srWindow.Left, csbi.srWindow.Top);
  pLog->LogPair("Right-Bottom",csbi.srWindow.Right, csbi.srWindow.Bottom);
  pLog->LogPair("Maximum Window Size", csbi.dwMaximumWindowSize.X, csbi.dwMaximumWindowSize.Y);
  COORD maxSize = con.GetMaximumScreenSize();
  pLog->LogPair("Max Size",maxSize.X, maxSize.Y);

  //game timer
  CTimer loopTimer;
  CTimer renderTimer;
  loopTimer.Initialize();
  renderTimer.Initialize();
  double timeDelta = 0;

  char buffer[] = "Chuck's Factory Game";
  con.setTitle(buffer);

  //main game loop
  //********************************************
  bool quit = false;    
  while(!quit){ 
    timeDelta = loopTimer.GetTimeDifference();
    g_pNext = g_pCurrent->Update(timeDelta);
	  if(NULL != g_pNext)
	  {
      g_pCurrent = g_pNext;
    }
     
    if(g_pCurrent == g_pStateQuit )
      quit = true;

  	// Render our current game object
    //if(renderTimer.GetTimer(0.1)== true)
      g_pCurrent->Render(con);
  }
  //********************************************
  //end game loop

  //free resources
  delete g_pStateIntro;
  delete g_pStateMenu;
  delete g_pStateQuit;
  delete g_pStateRules;
  delete g_pStateScore;
  delete g_pStatePlay;

  for(int i = 0; i < 9; ++i)
    g_audio.StopSoundClip(i);

  system("cls");
  
  //normal termination of game
  pLog->Log("*********************************************************");
  pLog->Log("Program terminating normally..................");
  pLog->SetDelimiter(':');
  pLog->LogTime();
  pLog->Log("*********************************************************");
  
  return 0;
}
//***************************************************************
//                         R E N D E R 
//***************************************************************
void cGameStateEditor::render(CGraphics &con, Camera &cam, CGameData &data){
  CLog *pLog = CLog::Instance();

  //variables
  static bLostDevice = false;
  static int lostCount = 0;
  GRAPHIC_IMAGE gi;
  GAME_OBJECT go;
  HRESULT hr;
  GAME_OBJECT temp;

  ::ShowCursor(false);

  //first time code
  static bool bFirstTime = true;
  if(bFirstTime == true){

    //look for animated data...and load GI stuff into GO
    for(int i = 0; i < data.LevelSize(); ++i){
      go = data.GetLevelData(i);
      if(go.asset == C_SPRITE){
        for(int j = 2; j < 7; ++j){
          gi = con.GetSprite(go.spriteID);
          go.maxFrames = gi.maxFrames;
          go.updateInterval = gi.updateInterval;
          data.UpdateLevelData(i, go);          
        }
      }
    }
    bFirstTime = false;

    gi = con.GetSprite(42);
    m_panelX = con.GetScreenWidth() - 50 - gi.width;
    m_panelY = 50;
    gi = con.GetSprite(47);
    m_fileBarY = con.GetScreenHeight() - 50 - gi.height;

  }

  if(FAILED(hr = con.m_d3ddev->TestCooperativeLevel())){
    pLog->Log("Failed test");
    if(hr == D3DERR_DEVICELOST)
      return;
    pLog->Log("No lost");
    if( hr == D3DERR_DEVICENOTRESET){// && bLostDevice == true  ){
      lostCount++;
      pLog->Log("Time to reset");
      con.DeleteLost();
      pLog->Log("Deleted everything");
      data.LoadConfigFile("data//config.txt");
      data.LoadGameLevel("data//level1.dat", con);

      hr = con.m_d3ddev->Reset(&con.GetDPP());
      pLog->Log("Dev reset");
      con.ReloadLost();
      pLog->Log("ReloadLost");
      bLostDevice = false;
      return;
    }
  }

  D3DXMATRIX V;
  D3DXVECTOR3 pos;
  cam.getPosition(&pos);  
  cam.getViewMatrix(&V, m_viewChoice);
  con.m_d3ddev->SetTransform(D3DTS_VIEW, &V);

  // clear the window to a deep blue
  con.m_d3ddev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
  con.m_d3ddev->BeginScene();    // begins the 3D scene
  
  //render layer 0 
  for(int i = 0; i < data.LevelSize(); ++i){
    temp = data.GetLevelData(i);
    if(temp.asset == C_SPLATTER)
      con.RenderSplatter(temp.meshID, temp.x, temp.y, temp.z, temp.rx, temp.ry, temp.rz);//, temp.ry);
  }

  //render layer 1
  for(int i = 0; i < data.LevelSize(); ++i){
    temp = data.GetLevelData(i);
    if(temp.asset == C_MESH){
      if(temp.meshID == 1){//BADGE test
        temp.rx = 0;//m_badgeAngleX;
        temp.ry = 0;//m_badgeAngleZ;
        con.RenderMesh(temp);
      }
      else
        con.RenderMesh(temp);//.meshID, temp.rx, temp.ry, temp.rz);
    }
  }
    
  //render grid points
  if(m_gridOn == true){
    int maxPoints = (2560 / m_gridSpace) + 1;
    gi = con.GetSprite(40);
    float px = 0;
    float py = 0;
    int lowerX = 0;
    int upperX = 0;
    int lowerY = 0;
    int upperY = 0;
    int w = con.GetScreenWidth()/2/m_gridSpace;
    int h = con.GetScreenHeight()/2/m_gridSpace;
    lowerX = data.m_playerX/m_gridSpace - w;
    upperX = data.m_playerX/m_gridSpace + w;
    lowerY = data.m_playerY/m_gridSpace - h;
    upperY = data.m_playerY/m_gridSpace + h;
    if(m_gridSpace > 1){
      for(int i = 0; i < maxPoints; ++i){
        for(int j = 0; j < maxPoints; ++j){
          px = con.GetScreenWidth()/2 + ((i * m_gridSpace) - data.m_playerX);
          py = con.GetScreenHeight()/2 + ((j * m_gridSpace) - data.m_playerY);
          if(i > lowerX && i <= upperX && j > lowerY && j <= upperY)
            con.DrawRect(px, py, px+1, py+1, 0, 255, 255);
        }
      }
    }
  }
  
  //********************************************************************************************
  // R E N D E R              R E N D E R               R E N D E R              R E N D E R  //
  //********************************************************************************************
  //render all objects
  int w = con.GetScreenWidth()/2;
  int h = con.GetScreenHeight()/2;
  int px = data.m_playerX;
  int py = data.m_playerY;

  data.m_screen.clear(); //clear before each render
  for(int j = 2; j < 5; ++j){
    for(int i = 0; i < data.m_pObject.size(); ++i){
      if(data.m_pObject[i]->go.layer == j && data.m_pObject[i]->go.alive == true ){
        if(data.m_pObject[i]->go.pos.x > px - w - 128  && data.m_pObject[i]->go.pos.x < px + w &&
          data.m_pObject[i]->go.pos.y > py - h - 128 && data.m_pObject[i]->go.pos.y < py + h){
          con.RenderGraphicModulate(data.m_pObject[i]->go, con.GetScreenWidth()/2 + (data.m_pObject[i]->go.pos.x - data.m_playerX), con.GetScreenHeight()/2 + (data.m_pObject[i]->go.pos.y - data.m_playerY), 255, 255, 255);
          data.m_screen.push_back(i); //add this to list of things on the screen
          }
      }
    }
  }

  //draws cindy's face as a graphic place holder
  //gi = con.GetSprite(21);
  //gi.scale = 0.75f/2.0f;//pos.y;
  //con.RenderGraphicModulate(gi, con.GetScreenWidth()/2 - (gi.scale * gi.width)/2 , con.GetScreenHeight()/2 - (gi.scale * gi.height)/2, 255, 255, 255);

  for(int j = 5; j < 9; ++j){
    for(int i = 0; i < data.m_pObject.size(); ++i){
      if(data.m_pObject[i]->go.layer == j && data.m_pObject[i]->go.alive == true){
        if(data.m_pObject[i]->go.pos.x > px - w - 128  && data.m_pObject[i]->go.pos.x < px + w &&
          data.m_pObject[i]->go.pos.y > py - h - 128 && data.m_pObject[i]->go.pos.y < py + h){
          con.RenderGraphicModulate(data.m_pObject[i]->go, con.GetScreenWidth()/2 + (data.m_pObject[i]->go.pos.x - data.m_playerX), con.GetScreenHeight()/2 + (data.m_pObject[i]->go.pos.y - data.m_playerY), 255, 255, 255);
          data.m_screen.push_back(i); //add this to list of things on the screen
          }
      }
    }
  }

  //draws player position...always (280, 280)
  gi = con.GetSprite(21);
  gi.scale = 0.75f/2.0f;//pos.y;
  con.RenderGraphicModulate(gi, con.GetScreenWidth()/2 + (280 - data.m_playerX), con.GetScreenHeight()/2 + (280 - data.m_playerY), 255, 255, 255);
  con.DrawCircle(con.GetScreenWidth()/2 + (290 - data.m_playerX), con.GetScreenHeight()/2 + (290 - data.m_playerY),0,255,255,20);
  
  //draws a circle around Cindy's position
  //con.DrawCircle(data.m_screenWidth/2, data.m_screenHeight/2, 155, 155, 155, 40);
  //con.DrawCircle(data.m_screenWidth/2, data.m_screenHeight/2, 200, 200, 200, 44);
  //con.DrawCircle(data.m_screenWidth/2, data.m_screenHeight/2, 255, 255, 255, 48);
  
  //draw rectangle around screen
  con.DrawRect(3, 3, data.m_screenWidth - 6, data.m_screenHeight - 6, 255, 255, 255);

  //sprite attached to mouse
  go = data.GetObjectInfo(m_currentObjectID);
  if(go.spriteID > -1){
    gi = con.GetSprite(go.spriteID);
    go.angle = 0; //m_angle;
    go.pos.x = m_mouse.MouseX();
    go.pos.y = m_mouse.MouseY();
    con.RenderGraphicModulate(go, 255,255,255);
  }

  //draw control panel
  gi = con.GetSprite(42);
  con.RenderGraphicModulate(gi, m_panelX, m_panelY, 255, 255, 255);

  //draw file bar
  gi = con.GetSprite(47);
  con.RenderGraphicModulate(gi, m_fileBarX, m_fileBarY, 255, 255,255);

  //draw rectangles on top of control panel
  if(m_gridOn == true)
    con.DrawRect((float)(m_panelX + 99), (float)(m_panelY + 554), (float)(m_panelX + 157),(float)(m_panelY + 592),255,0,0);
  else
    con.DrawRect((float)(m_panelX + 158), (float)(m_panelY + 554), (float)(m_panelX + 225),(float)(m_panelY + 592),255,0,0);

  if(m_snapOn == true)
    con.DrawRect((float)(m_panelX + 99), (float)(m_panelY + 593), (float)(m_panelX + 157),(float)(m_panelY + 635),255,0,0);
  else
    con.DrawRect((float)(m_panelX + 158), (float)(m_panelY + 593), (float)(m_panelX + 225),(float)(m_panelY + 635),255,0,0);

  if(m_gridSpace == 32)
    con.DrawRect((float)(m_panelX + 28), (float)(m_panelY + 642), (float)(m_panelX + 84),(float)(m_panelY + 686),255,0,0);
  else if(m_gridSpace == 64)
    con.DrawRect((float)(m_panelX + 85), (float)(m_panelY + 642), (float)(m_panelX + 145),(float)(m_panelY + 686),255,0,0);
  else if(m_gridSpace == 128)
    con.DrawRect((float)(m_panelX + 146), (float)(m_panelY + 642), (float)(m_panelX + 217),(float)(m_panelY + 686),255,0,0);

  //render list of available game objects
  for(int i = 0; i < data.m_objectType.size(); ++i){
    if(i < 30)
      con.Print(data.m_objectType[i].name, F_V16B, m_panelX + 16, m_panelY + 65 + (i * 16), 255, 255, 255);
    else
      break;
  }

  //highlight selected object type
  con.Print(data.m_objectType[m_currentObjectID].name, F_V16B, m_panelX + 16, m_panelY + 65 + (m_currentObjectID * 16), 0, 0, 255);

  //draw on filebar
  con.Print(data.GetLevelFilename(m_editLevel),F_V14B, m_fileBarX + 299, m_fileBarY + 28, 255, 255, 0);

  //clear
  if(m_mouse.MouseX() > m_fileBarX + 16 && m_mouse.MouseX() < m_fileBarX + 103 &&
    m_mouse.MouseY() > m_fileBarY + 15 && m_mouse.MouseY() < m_fileBarY + 55){
    con.DrawRect((float)m_fileBarX + 16, (float)m_fileBarY + 15, (float)m_fileBarX + 103, (float)m_fileBarY + 55, 0, 255, 0);
  }

  //open level file 1
  if(m_mouse.MouseX() > m_fileBarX + 195 && m_mouse.MouseX() < m_fileBarX + 217 &&
    m_mouse.MouseY() > m_fileBarY + 15 && m_mouse.MouseY() < m_fileBarY + 55){
    con.DrawRect((float)m_fileBarX + 195, (float)m_fileBarY + 15, (float)m_fileBarX + 217, (float)m_fileBarY + 55, 0, 255, 0);
  }

  //open level file 2
  if(m_mouse.MouseX() > m_fileBarX + 223 && m_mouse.MouseX() < m_fileBarX + 245 &&
    m_mouse.MouseY() > m_fileBarY + 15 && m_mouse.MouseY() < m_fileBarY + 55){
    con.DrawRect((float)m_fileBarX + 223, (float)m_fileBarY + 15, (float)m_fileBarX + 245, (float)m_fileBarY + 55, 0, 255, 0);
  }

  //open level file 3
  if(m_mouse.MouseX() > m_fileBarX + 251 && m_mouse.MouseX() < m_fileBarX + 273 &&
    m_mouse.MouseY() > m_fileBarY + 15 && m_mouse.MouseY() < m_fileBarY + 55){
    con.DrawRect((float)m_fileBarX + 251, (float)m_fileBarY + 15, (float)m_fileBarX + 273, (float)m_fileBarY + 55, 0, 255, 0);
  }

  //save level file
  if(m_mouse.MouseX() > m_fileBarX + 434 && m_mouse.MouseX() < m_fileBarX + 514 &&
    m_mouse.MouseY() > m_fileBarY + 15 && m_mouse.MouseY() < m_fileBarY + 55){
    con.DrawRect((float)m_fileBarX + 434, (float)m_fileBarY + 15, (float)m_fileBarX + 514, (float)m_fileBarY + 55, 0, 255, 0);
  }

  //undo last game object
  if(m_mouse.MouseX() > m_fileBarX + 520 && m_mouse.MouseX() < m_fileBarX + 615 &&
    m_mouse.MouseY() > m_fileBarY + 15 && m_mouse.MouseY() < m_fileBarY + 55){
    con.DrawRect((float)m_fileBarX + 520, (float)m_fileBarY + 15, (float)m_fileBarX + 615, (float)m_fileBarY + 55, 0, 255, 0);
  }  
    

  //draw mouse cursor
  con.DrawLine(m_mouse.MouseX()+ 5, m_mouse.MouseY(), m_mouse.MouseX()+ 25 , m_mouse.MouseY(),0, 255, 255);
  con.DrawLine(m_mouse.MouseX()- 5, m_mouse.MouseY(), m_mouse.MouseX() - 25 , m_mouse.MouseY(),0, 255, 255);
  con.DrawLine(m_mouse.MouseX(), m_mouse.MouseY() + 5, m_mouse.MouseX(), m_mouse.MouseY() + 25,0, 255, 255);
  con.DrawLine(m_mouse.MouseX(), m_mouse.MouseY() - 5, m_mouse.MouseX(), m_mouse.MouseY() - 25,0, 255, 255);

  //editor label at top
  gi = con.GetSprite(45);
  con.RenderGraphicModulate(gi, m_editorX, m_editorY, 255, 255, 255);
  con.Print(data.m_playerX + (m_mouse.MouseX() - data.m_screenWidth/2), F_V20, m_editorX + 144, m_editorY + 68, 255, 255, 255);
  con.Print(data.m_playerY + (m_mouse.MouseY() - data.m_screenHeight/2), F_V20,  m_editorX + 391, m_editorY + 68, 255, 255, 255);
  con.Print(data.m_pObject.size(), F_V20, m_editorX + 440, m_editorY + 22, 0, 255, 255);

  //map
  gi = con.GetSprite(45);
  m_mapX = m_editorX + gi.width + 20;
  m_mapY = m_editorY + 30;
  con.DrawRect((float)m_mapX, (float)m_mapY, (float)(m_mapX + 80), (float)(m_mapY + 80), 255,0,0);//draw map
  int smallW = con.GetScreenWidth()/64;
  int smallH = con.GetScreenHeight()/85;
  
  con.DrawRect((float)m_mapX + data.m_playerX/32 - smallW, (float)m_mapY + data.m_playerY/32 - smallH, 
               (float)m_mapX + data.m_playerX/32 + smallW, (float)m_mapY + data.m_playerY/32 + smallH,255, 255, 255); //draw player

  //print text to display
  if(data.m_displayDebugInfo == true){
    con.Print("EDITOR STATE - Version", data.m_version, F_V16, 50, 10,  255, 255, 255, 255);
    con.Print("FPS", data.m_FPS , F_V16B, 530, 10,  255, 255, 0, 255);
  }
  
  //mouse coordinates
  con.Print("Press ESC to quit", F_V20, data.m_screenWidth/2 - 100, data.m_screenHeight/2 + 200, 255, 0, 0, 255);

  //finish rendering
  con.m_d3ddev->EndScene();                             // ends the 3D scene
  hr = con.m_d3ddev->Present(NULL, NULL, NULL, NULL);   // displays the created frame on the screen
  
  if(FAILED(hr = con.m_d3ddev->TestCooperativeLevel())){
    if(hr == D3DERR_DEVICELOST)
      bLostDevice = true;
      lostCount++;
  }
  return;  
}
void cGameStateHelp::render(CGraphics &con, Camera &cam, CGameData &data){
  CLog *pLog = CLog::Instance();
  static bLostDevice = false;

  HRESULT hr;

  if(FAILED(hr = con.m_d3ddev->TestCooperativeLevel())){

    pLog->Log("Failed test");
    if(hr == D3DERR_DEVICELOST)
      return;
    pLog->Log("No lost");
    if( hr == D3DERR_DEVICENOTRESET ){
      pLog->Log("Time to reset");
      con.DeleteLost();
      pLog->Log("Deleted everything");
      hr = con.m_d3ddev->Reset(&con.GetDPP());
      pLog->Log("Dev reset");
      con.ReloadLost();
      pLog->Log("ReloadLost");
      bLostDevice = false;
      return;
    }
  }

  D3DXMATRIX V;
  cam.getViewMatrix(&V, 0);
  con.m_d3ddev->SetTransform(D3DTS_VIEW, &V);
  GRAPHIC_IMAGE gi;
  // clear the window to a deep blue
  con.m_d3ddev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(160, 0, 0), 1.0f, 0);
  con.m_d3ddev->BeginScene();    // begins the 3D scene

      con.Print("Cindy and the Cookie Stealing Ogre", F_V20, 380, 10, 255, 255, 255, 255);      

      con.Print("Cindy is a Rainbow Scout. She has sold 99 boxes of Rainbow Scout Cookies.  She needed to sell 100 boxes", F_V20, 10, 50, 0, 255, 0);
      con.Print("in order to receive her Rainbow Scout \"Little Miss\" badge.  Cindy was standing in front of the local", F_V20, 10, 70, 0, 255, 0);
      con.Print("grocery store selling cookies. SUDDENLY a mean Ogre came running past her stealing her very last box of", F_V20, 10, 90, 0, 255, 0);
      con.Print("cookies.  Cindy began yelling obscenities and ran in pursuit of the Ogre. She chased him into the Enchanted", F_V20, 10, 110, 0, 255, 0);
      con.Print("forest.", F_V20, 10, 130, 0, 255, 0);
      con.Print("You are Cindy. Your goal is to get past the flesh eating elves,      fairies,       and witches       .  ", F_V20, 10, 160, 0, 255, 255);
      gi = con.GetSprite(90);
      con.RenderGraphicModulate(gi, 542, 155, 255, 255, 255);
      gi = con.GetSprite(91);
      con.RenderGraphicModulate(gi, 642, 155, 255, 255, 255);
      gi = con.GetSprite(92);
      con.RenderGraphicModulate(gi, 782, 155, 255, 255, 255);

      con.Print("You must work through 3 levels. In levels 1 and 2 you must find the gate         out of the level.", F_V20, 10, 200, 0, 255, 255);
      con.Print("In level 3 you must get very close to the Ogre            and he will return the box of cookies.", F_V20, 10, 240, 0, 255, 255);
      
      con.Print("You must be very careful. Watch the status of the Time remaining, Health, and Kindness.  Health is reduced", F_V20, 10, 280, 0, 255, 255);
      con.Print("when the elves, fairies, and witches bite Cindy. Kindness is reduced each time Cindy uses a weapon.", F_V20, 10, 300, 0, 255, 255);
      con.Print("You can increase your health by collecting first aid.      You can increase your kindness by visiting.", F_V20, 10, 320, 0, 255, 255);
      con.Print("Grandma       .  Kindness increases as long as you stand close to here. The white circle will flash.  You can", F_V20, 10, 340, 0, 255, 255);
      con.Print("still shoot all weapons while visiting Grandma. Grandma cannot be harmed by your weapons.", F_V20, 10, 360, 0, 255, 255);

      gi = con.GetSprite(111);
      con.RenderGraphicModulate(gi, 450, 315, 255, 255, 255);//health
      gi = con.GetSprite(112);
      con.RenderGraphicModulate(gi, 89, 330, 255, 255, 255);//grandma
      gi = con.GetSprite(113);
      con.RenderGraphicModulate(gi, 417, 220, 255, 255, 255);//ogre
      gi = con.GetSprite(83);
      con.RenderGraphicModulate(gi, 662, 190, 255, 255, 255);//door


      con.Print("Use WASD keys to move around. Cindy is only 10 years-old so she doesn't run very fast.  Use the Arrow keys", F_V20, 10, 400, 0, 255, 255);
      con.Print("to fire weapons.  Spacebar may also be used to fire weapons.  Keys 1, 2, 3, 4, and 5 may be used to select", F_V20, 10, 420, 0, 255, 255);
      con.Print("the weapons: 9mm pistol,     shotgun,     machine gun,     rocket launcher,     and flamethrower     .", F_V20, 10, 440, 0, 255, 255);

      gi = con.GetSprite(75);
      con.RenderGraphicModulate(gi, 242, 435, 255, 255, 255);
      gi = con.GetSprite(76);
      con.RenderGraphicModulate(gi, 342, 435, 255, 255, 255);
      gi = con.GetSprite(77);
      con.RenderGraphicModulate(gi, 487, 435, 255, 255, 255);
      gi = con.GetSprite(78);
      con.RenderGraphicModulate(gi, 662, 435, 255, 255, 255);
      gi = con.GetSprite(79);
      con.RenderGraphicModulate(gi, 862, 435, 255, 255, 255);

      con.Print("Ammo for pistol         shotgun       and machine gun.", F_V20, 10, 480, 0, 255, 255);
      gi = con.GetSprite(80);
      con.RenderGraphicModulate(gi, 145, 470, 255, 255, 255);
      gi = con.GetSprite(81);
      con.RenderGraphicModulate(gi, 270, 470, 255, 255, 255);
      gi = con.GetSprite(82);
      con.RenderGraphicModulate(gi, 470, 470, 255, 255, 255);
      
      con.Print("Press ESC to continue...", F_V20, 410, 740, 255, 0, 0, 255);
  
  con.m_d3ddev->EndScene();    // ends the 3D scene
  hr = con.m_d3ddev->Present(NULL, NULL, NULL, NULL);   // displays the created frame on the screen

  if(FAILED(hr = con.m_d3ddev->TestCooperativeLevel())){
    if(hr == D3DERR_DEVICELOST)
      bLostDevice = true;
  }

  return;
}
//***************************************************************
//                         R E N D E R 
//***************************************************************
void cGameStatePlay2::render(CGraphics &con, Camera &cam, CGameData &data){
  CLog *pLog = CLog::Instance();

  //variables
  static bLostDevice = false;
  static int lostCount = 0;
  GRAPHIC_IMAGE gi;
  GAME_OBJECT go;
  HRESULT hr;
  GAME_OBJECT temp;

  ::ShowCursor(false);
 
  //first time code
  static bool bFirstTime = true;
  if(bFirstTime == true){

    //look for animated data...and load GI stuff into GO
    for(int i = 0; i < data.LevelSize(); ++i){
      go = data.GetLevelData(i);
      if(go.asset == C_SPRITE){
        for(int j = 2; j < 7; ++j){
          gi = con.GetSprite(go.spriteID);
          go.maxFrames = gi.maxFrames;
          go.updateInterval = gi.updateInterval;
          data.UpdateLevelData(i, go);          
        }
      }
    }
    bFirstTime = false;
  }

  if(FAILED(hr = con.m_d3ddev->TestCooperativeLevel())){
    pLog->Log("Failed test");
    if(hr == D3DERR_DEVICELOST)
      return;
    pLog->Log("No lost");
    if( hr == D3DERR_DEVICENOTRESET){// && bLostDevice == true  ){
      lostCount++;
      pLog->Log("Time to reset");
      con.DeleteLost();
      pLog->Log("Deleted everything");
      data.LoadConfigFile("data//config.txt");
      data.LoadGameLevel("data//level1.dat", con);

      hr = con.m_d3ddev->Reset(&con.GetDPP());
      pLog->Log("Dev reset");
      con.ReloadLost();
      pLog->Log("ReloadLost");
      bLostDevice = false;
      return;
    }
  }

  D3DXMATRIX V;
  D3DXVECTOR3 pos;
  cam.getPosition(&pos);  
  cam.getViewMatrix(&V, m_viewChoice);
  con.m_d3ddev->SetTransform(D3DTS_VIEW, &V);

  // clear the window to a deep blue
  //con.m_d3ddev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
  con.m_d3ddev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
  con.m_d3ddev->BeginScene();    // begins the 3D scene
  
  //render layer 0 
  for(int i = 0; i < data.LevelSize(); ++i){
    temp = data.GetLevelData(i);
    if(temp.asset == C_SPLATTER)
      con.RenderSplatter(temp.meshID, temp.x, temp.y, temp.z, temp.rx, temp.ry, temp.rz);//, temp.ry);
  }

  //render layer 1
  for(int i = 0; i < data.LevelSize(); ++i){
    temp = data.GetLevelData(i);
    if(temp.asset == C_MESH){
      if(temp.meshID == 1){//BADGE test
        temp.rx = 0;//m_badgeAngleX;
        temp.ry = 0;//m_badgeAngleZ;
        con.RenderMesh(temp);
      }
      else
        con.RenderMesh(temp);//.meshID, temp.rx, temp.ry, temp.rz);
    }
  }
    
  //render all objects
  int w = con.GetScreenWidth()/2;
  int h = con.GetScreenHeight()/2;
  int px = data.m_player.go.pos.x;
  int py = data.m_player.go.pos.y;

  go = data.m_player.GetGameObject();

  for(int j = 3; j <= 6; ++j){//3..4
    for(int i = 0; i < data.m_pObject.size(); ++i){
      if(data.m_pObject[i]->go.layer == j && data.m_pObject[i]->go.alive == true ){
        if(data.m_pObject[i]->go.pos.x > px - w - 128  && data.m_pObject[i]->go.pos.x < px + w + 128 &&
           data.m_pObject[i]->go.pos.y > py - h - 128 && data.m_pObject[i]->go.pos.y < py + h + 128)
          con.RenderGraphicModulate(data.m_pObject[i]->go, con.GetScreenWidth()/2 + (data.m_pObject[i]->go.pos.x - go.pos.x) - 16, con.GetScreenHeight()/2 + (data.m_pObject[i]->go.pos.y - go.pos.y) - 16, 255, 255, 255);
      }
    }
  }

  //draws cindy's face as a graphic place holder
  go.width = 32;
  go.height = 32;
  go.pos.x = con.GetScreenWidth()/2 ;//- gi.width/2;
  go.pos.y = con.GetScreenHeight()/2 ;// - gi.height/2;
  con.RenderGraphicModulate(go, 255, 255, 255);

  //draws cindy's face as a graphic place holder
  //gi = con.GetSprite(21);
  //gi.scale = 0.75f/2.0f;//pos.y;
  //con.RenderGraphicModulate(gi, con.GetScreenWidth()/2 - (gi.scale * gi.width)/2 , con.GetScreenHeight()/2 - (gi.scale * gi.height)/2, 255, 255, 255);


  go = data.m_player.GetGameObject();

  for(int j = 7; j <= 8; ++j){//5..9
    for(int i = 0; i < data.m_pObject.size(); ++i){
      if(data.m_pObject[i]->go.layer == j ){//&& data.m_pObject[i]->go.alive == true){
        if(data.m_pObject[i]->go.pos.x > px - w - 128  && data.m_pObject[i]->go.pos.x < px + w + 128 &&
           data.m_pObject[i]->go.pos.y > py - h - 128 && data.m_pObject[i]->go.pos.y < py + h + 128)
          con.RenderGraphicModulate(data.m_pObject[i]->go, con.GetScreenWidth()/2 + (data.m_pObject[i]->go.pos.x - go.pos.x) - 16, con.GetScreenHeight()/2 + (data.m_pObject[i]->go.pos.y - go.pos.y) - 16, 255, 255, 255);
      }
    }
  }
   
  //render grandmas
  for(int i = 0; i < data.m_grandma.size(); ++i){
   // pLog->Log(data.m_grandma[i].go.objectID, data.m_grandma[i].go.spriteID, data.m_grandma[i].go.pos.x, data.m_grandma[i].go.pos.y);
    con.RenderGraphicModulate(data.m_grandma[i].go, con.GetScreenWidth()/2 + (data.m_grandma[i].go.pos.x - go.pos.x) - 16, con.GetScreenHeight()/2 + (data.m_grandma[i].go.pos.y - go.pos.y) - 16, 255, 255, 255);
  }


  //draw projectiles
  for(int i = 0; i < data.m_projectiles.size(); ++i){
    gi = con.GetSprite(data.m_projectiles[i].m_WO.spriteID);
    if(data.m_projectiles[i].go.alive == true)
      con.RenderGraphicModulate(data.m_projectiles[i].go, con.GetScreenWidth()/2 + (data.m_projectiles[i].go.pos.x - go.pos.x) - 16, con.GetScreenHeight()/2 + (data.m_projectiles[i].go.pos.y - go.pos.y) - 16, 255, 255, 255);
  }

  //draws a circle around Cindy's position
  if(data.m_player.m_rechargeKindness == false)
    con.DrawCircle(data.m_screenWidth/2, data.m_screenHeight/2, 255, 255, 255, 48);
  else
    con.DrawCircle(data.m_screenWidth/2, data.m_screenHeight/2, 0, 0, 255, 48);

  //draw rectangle around screen
  if(m_bInventory == true)
    con.DrawRect(3, 3, data.m_screenWidth - 6, data.m_screenHeight - 6, 255, 255, 255);
  
  //map
  //************************************************
  gi = con.GetSprite(45);
  go = data.m_player.GetGameObject();

  m_mapX = 10 + gi.width + 220;
  m_mapY = 10;
  if(m_bInventory == true)
    con.DrawRect((float)m_mapX, (float)m_mapY, (float)(m_mapX + 80), (float)(m_mapY + 80), 255,0,0);//draw map
  int smallW = con.GetScreenWidth()/64;
  int smallH = con.GetScreenHeight()/85;
  if(m_bInventory == true)
    con.DrawRect((float)m_mapX + data.m_player.go.pos.x/32 - smallW, (float)m_mapY + data.m_player.go.pos.y/32 - smallH, 
                 (float)m_mapX + data.m_player.go.pos.x/32 + smallW, (float)m_mapY + data.m_player.go.pos.y/32 + smallH,255, 255, 255); //draw player

  //inventory
  //*******************************************************************************
  int transParency = 120;
  if(m_bInventory == true && m_bHelp == false){
    gi = con.GetSprite(58);
    gi.alpha = transParency;
    con.RenderGraphicModulate(gi, m_inventoryX, m_inventoryY, 255, 255, 255);
    if(data.m_weapons[1].exists == true && data.m_weapons[1].rounds > 0 )
      gi = con.GetSprite(65);
    else
      gi = con.GetSprite(64);
    gi.alpha = transParency;
    con.RenderGraphicModulate(gi, m_inventoryX + 14, m_inventoryY + 63,  255, 255, 255);
    if(data.m_weapons[2].exists == true && data.m_weapons[2].rounds > 0)
      gi = con.GetSprite(67);
    else
      gi = con.GetSprite(66);
    gi.alpha = transParency;
    con.RenderGraphicModulate(gi, m_inventoryX + 14, m_inventoryY + 192,  255, 255, 255);
    if(data.m_weapons[3].exists == true  && data.m_weapons[3].rounds > 0)
      gi = con.GetSprite(69);
    else
      gi = con.GetSprite(68);
    gi.alpha = transParency;
    con.RenderGraphicModulate(gi, m_inventoryX + 14, m_inventoryY + 321,  255, 255, 255);

    if(data.m_weapons[4].exists == true  && data.m_weapons[4].rounds > 0)
      gi = con.GetSprite(71);
    else
      gi = con.GetSprite(70);
    gi.alpha = transParency;
    con.RenderGraphicModulate(gi, m_inventoryX + 14, m_inventoryY + 450, 255, 255, 255);
    if(data.m_weapons[5].exists == true  && data.m_weapons[5].rounds > 0)
      gi = con.GetSprite(73);
    else
      gi = con.GetSprite(72);
    gi.alpha = transParency;
    con.RenderGraphicModulate(gi, m_inventoryX + 14, m_inventoryY + 579, 255, 255, 255);
  }

  //display round count
  if(m_bInventory == true && m_bHelp == false){
    con.Print(data.m_weapons[1].rounds, F_V20, m_inventoryX + 24, m_inventoryY + 73, 255, 0, 0, 255);
    con.Print(data.m_weapons[2].rounds, F_V20, m_inventoryX + 24, m_inventoryY + 201, 255, 0, 0, 255);
    con.Print(data.m_weapons[3].rounds, F_V20, m_inventoryX + 24, m_inventoryY + 329, 255, 0, 0, 255);
    con.Print(data.m_weapons[4].rounds, F_V20, m_inventoryX + 24, m_inventoryY + 457, 255, 0, 0, 255);
    con.Print(data.m_weapons[5].rounds, F_V20, m_inventoryX + 24, m_inventoryY + 595, 255, 0, 0, 255);
  }

  //draws outline around selected weapon using m_weaponType;
  if(m_bInventory == true && m_bHelp == false){
    if(data.m_weaponType >= 0 && data.m_weaponType <= 5){
      con.DrawRect(m_inventoryX + 15, m_inventoryY + 64 + ((data.m_weaponType - 1) * 129), m_inventoryX + 139, m_inventoryY + 189 + ((data.m_weaponType - 1) * 129), 255, 0, 0);
      con.DrawRect(m_inventoryX + 16, m_inventoryY + 65 + ((data.m_weaponType - 1) * 129), m_inventoryX + 138, m_inventoryY + 188 + ((data.m_weaponType - 1) * 129), 255, 0, 0);
      con.DrawRect(m_inventoryX + 17, m_inventoryY + 66 + ((data.m_weaponType - 1) * 129), m_inventoryX + 137, m_inventoryY + 187 + ((data.m_weaponType - 1) * 129), 255, 0, 0);
    }
  }

  //status bar
  if(m_bHelp == false){
    gi = con.GetSprite(59);
    gi.alpha = transParency;
    con.RenderGraphicModulate(gi, m_statusX, m_statusY, 255, 255, 255);
   
    //health
    gi = con.GetSprite(60);
    gi.alpha = transParency;
    gi.width =  (float)gi.width * (float)data.m_player.m_health * 0.001;
    con.RenderGraphicModulate(gi, m_statusX + 113, m_statusY + 17, 255, 255, 255);
    gi = con.GetSprite(61);
    gi.alpha = transParency;
    gi.width =  (float)gi.width * (float)data.m_player.m_kindness * 0.001;
    con.RenderGraphicModulate(gi, m_statusX + 113, m_statusY + 43, 255, 255, 255);

    //time and score
    con.Print(data.m_player.m_time, F_V20, m_statusX + 580, m_statusY + 20, 255, 255, 255, 255);
    con.Print(data.m_player.m_score, F_V20, m_statusX + 570, m_statusY + 46, 255, 255, 255, 255);
  }
  //draw mouse cursor
  if(m_bInventory == true){
    con.DrawLine(m_mouse.MouseX(), m_mouse.MouseY(), m_mouse.MouseX() + 15, m_mouse.MouseY(),255,255,0);
    con.DrawLine(m_mouse.MouseX(), m_mouse.MouseY(), m_mouse.MouseX() - 15, m_mouse.MouseY(),255,255,0);
    con.DrawLine(m_mouse.MouseX(), m_mouse.MouseY(), m_mouse.MouseX(), m_mouse.MouseY() + 15,255,255,0);
    con.DrawLine(m_mouse.MouseX(), m_mouse.MouseY(), m_mouse.MouseX(), m_mouse.MouseY() - 15,255,255,0);
  }

  //print text to display
  if(data.m_displayDebugInfo == true){
    //con.Print("PLAY1 STATE - Version", data.m_version, F_V16, 10, 10,  255, 255, 255, 255);
    con.Print("FPS", data.m_FPS , F_V16, 510, 10,  255, 255, 0, 255);
    //con.Print("X", m_mouse.MouseX(), F_V16, 10, 30, 0, 255, 255, 255);
    //con.Print("Y", m_mouse.MouseY(), F_V16, 150, 30, 0, 255, 255, 255);
    //con.Print("X", data.m_player.go.pos.x, F_V16, 10, 50, 0, 255, 255, 255);
    //con.Print("Y", data.m_player.go.pos.y, F_V16, 150, 50, 0, 255, 255, 255);
    //con.Print("Projectiles", data.m_projectiles.size(), F_V16, 10, 70, 255, 0, 255);
  }
  
  //overlay help information
  if(m_bHelp == true){
    gi = con.GetSprite(106);
    con.RenderGraphicModulate(gi, 20, 20, 255, 255, 255);//number keys
    gi = con.GetSprite(107);
    con.RenderGraphicModulate(gi, 700, 20, 255, 255, 255);//H, I, P
    gi = con.GetSprite(108);
    con.RenderGraphicModulate(gi, 20, 250, 255, 255, 255);//W, A, S, D
    gi = con.GetSprite(110);
    con.RenderGraphicModulate(gi, 360, 450, 255, 255, 255);
    gi = con.GetSprite(109);
    con.RenderGraphicModulate(gi, 700, 250, 255, 255, 255);
  }


  if(m_bPause == true)
    con.Print("PAUSED!", F_V20, data.m_screenWidth/2 - 50, data.m_screenHeight/2 - 10, 255, 0, 0, 255);

  //mouse coordinates
  con.Print("Press ESC to quit", F_V20, data.m_screenWidth/2 - 100, data.m_screenHeight/2 + 260, 255, 0, 0, 255);

  //finish rendering
  con.m_d3ddev->EndScene();                             // ends the 3D scene
  hr = con.m_d3ddev->Present(NULL, NULL, NULL, NULL);   // displays the created frame on the screen
  
  if(FAILED(hr = con.m_d3ddev->TestCooperativeLevel())){
    if(hr == D3DERR_DEVICELOST)
      bLostDevice = true;
      lostCount++;
  }
  return;  
}
void CGameStateIntro::Render(CGraphics &con, CGameData &data, CConfigData &cfg){
  ::ShowCursor(false);
  CLog *pLog = CLog::Instance();
  static bool bLostDevice = false;

  //test to see if graphic device is lost, if so, deal with it
  //**********************************************************
  HRESULT hr;
  if(FAILED(hr = con.m_d3ddev->TestCooperativeLevel())){
    
    //device is lost...cannot be reset...exit Render() function
    if(hr == D3DERR_DEVICELOST){
      if(bLostDevice == false){
        bLostDevice = true;
        con.DeleteLost();    //delete one time per failure
        m_effect.Delete();
        pLog->Log("Deleted");
      }
      return;
    }

    //device was lost...but now can be RESET
    else if( hr == D3DERR_DEVICENOTRESET ){
      hr = con.m_d3ddev->Reset(&con.GetDPP());      
      if(SUCCEEDED(hr)){
        m_effect.Init(con.m_d3ddev);
        m_effect.LoadFile(cfg.EffectsFileI);// "assets\\data\\effects_i.dat");
        m_effectNumber = 0;
        m_effectMax = m_effect.GetNumberEffects();
        pLog->Log("******* Number of effects reloaded", m_effectMax);
        con.LoadAssetFile(cfg.GamePlayAssetFile);
        con.LoadAssetFile(cfg.FrameworkAssetFile);     
        con.ReloadLost();
        bLostDevice = false;
      }
      return;
    }
  }

  // clear the window to a deep blue
  //if(m_graphic == 0)
  //  con.m_d3ddev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 111, 255), 1.0f, 0);
  //else
  con.m_d3ddev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(106, 126, 67), 1.0f, 0);
  con.m_d3ddev->BeginScene();    // begins the 3D scene

  GRAPHIC_IMAGE gi;  
  con.BeginRender();
  
  //render title
  if(m_secondCounter < 3){
    gi = con.GetSprite(1000);
    con.RenderGraphicModulate(gi, con.GetScreenCenterX() - gi.width/2, con.GetScreenCenterY() - gi.height/2, 255, 255, 255);
  }
  else{
    gi = con.GetSprite(1001);
    con.RenderGraphicModulate(gi, con.GetScreenCenterX() - gi.width/2, con.GetScreenCenterY() - gi.height/2, 255, 255, 255);
  }
  if(m_secondCounter > 3){
    gi = con.GetSprite(1002);
    con.RenderGraphicModulate(gi, - 20 + con.GetScreenCenterX() - gi.width/2, 60 + con.GetScreenCenterY() - gi.height/2, 255, 255, 255);
  }

  con.EndRender();

  m_effect.Render(); 

  //mouse cursor
  con.DrawCircle(m_mouse.MouseX(), m_mouse.MouseY(), 255, 255, 255, 10);

  if(cfg.DisplayDebugInfo == true){
    con.Print("Mouse X", m_mouse.MouseX(), F_V16, 10, 30, 255, 255, 255, 255);
    con.Print("Mouse Y", m_mouse.MouseY(), F_V16, 10, 50, 255, 255, 255, 255);
  }

  //con.Print("Introduction Splash Screen", F_V20B, cfg.ScreenWidth/2 - 120, 100, 255, 255, 0, 255);
  //con.Print("Left Click to Continue", F_V20B, cfg.ScreenWidth/2 - 110, 130, 255, 255, 255, 255);
  //con.Print("FPS", data.m_FPS, F_V16, 30, 50, 255, 255, 255, 255);
  //if(cfg.DisplayDebugInfo == true){
   // con.Print("FPS", data.m_FPS , F_V16, 30, 30,  255, 255, 255, 255);
  //}  

  con.m_d3ddev->EndScene();    // ends the 3D scene
  hr = con.m_d3ddev->Present(NULL, NULL, NULL, NULL);   // displays the created frame on the screen
 
  return;
}
/*****************************************************
 Reads and loads data from assets.dat file into one of
 the vectors below.

 std::vector<GRAPHIC_FILE_DATA> m_assetFileData;
 std::vector<SPRITE_DATA> m_assetSpriteData;
 std::vector<MESH_DATA> m_assetMeshData;
 std::vector<SOUND_FILE_DATA> m_assetSoundData;

 Parameters in cfr begin with 1 not 0
*****************************************************/
bool CGraphics::LoadAssetFile(std::string filename){
  CLog *pLog = CLog::Instance();

  //validate asset data and add to appropriate vectors
  std::string parameter;
  std::string assetType;
  GRAPHIC_FILE_DATA   tempGraphic;
  SPRITE_DATA         tempSprite;  

  CCSVReader csv;
  csv.LoadFile(filename);

  //new stuff
  for(int i = 0; i < csv.GetTableSize(); ++i){

    if(csv.GetNumberParameters(i) > 1){
      assetType = csv.GetTerm(i, 0);

      if(assetType == "texture" && csv.GetNumberParameters(i) == 4){
        parameter = csv.GetTerm(i, 1);//fileID
        tempGraphic.fileID = atoi(parameter.c_str());
        parameter = csv.GetTerm(i, 2);//filename
        tempGraphic.filename = parameter;
        parameter = csv.GetTerm(i, 3);//description
        tempGraphic.description = parameter;
        m_assetFileData.push_back(tempGraphic);
      }

      else if(assetType == "sprite" && csv.GetNumberParameters(i) == 14 ){// && csv.GetNumberParameters(i) == 14){
        parameter = csv.GetTerm(i, 1);//spriteID
        tempSprite.spriteID = atoi(parameter.c_str());
        parameter = csv.GetTerm(i, 2);//fileID
        tempSprite.fileID = atoi(parameter.c_str());
        parameter = csv.GetTerm(i, 3);//left
        tempSprite.x = static_cast<float>(atof(parameter.c_str()));
        parameter = csv.GetTerm(i, 4);//right
        tempSprite.y = static_cast<float>(atof(parameter.c_str()));
        parameter = csv.GetTerm(i, 5);//width
        tempSprite.width = static_cast<float>(atof(parameter.c_str()));
        parameter = csv.GetTerm(i, 6);//height
        tempSprite.height = static_cast<float>(atof(parameter.c_str()));
        parameter = csv.GetTerm(i, 7);//scale
        tempSprite.scale =  static_cast<float>(atof(parameter.c_str()));
        parameter = csv.GetTerm(i, 8);//angle
        tempSprite.angle =  static_cast<float>(atof(parameter.c_str()));
        parameter = csv.GetTerm(i, 9);//alpha
        tempSprite.alpha = atoi(parameter.c_str());
        parameter = csv.GetTerm(i, 10);//total number of frames
        tempSprite.numberFrames = atoi(parameter.c_str());
        parameter = csv.GetTerm(i, 11);//framecount, starting frame
        tempSprite.frameCount = atoi(parameter.c_str());        
        parameter = csv.GetTerm(i, 12);//time between frames
        tempSprite.timeBetweenFrames = atof(parameter.c_str());// static_cast<float>(atof(parameter.c_str()));
        parameter = csv.GetTerm(i, 13);//description
        tempSprite.description = parameter;
        
        m_assetSpriteData.push_back(tempSprite);
      }
    }
  }

  //load graphics files
  for(unsigned int i = 0; i < m_assetFileData.size(); ++i){
    LoadTextureFile(m_assetFileData[i].fileID, "assets//graphics//" + m_assetFileData[i].filename);
  }

  pLog->Log("Exit loading of files");

  //load sprite information
  GRAPHIC_IMAGE gi;
  for(unsigned int i = 0; i < m_assetSpriteData.size(); ++i){
    gi.spriteID = m_assetSpriteData[i].spriteID;
    gi.fileID = m_assetSpriteData[i].fileID;
    gi.sourceX = static_cast<int>(m_assetSpriteData[i].x);
    gi.sourceY = static_cast<int>(m_assetSpriteData[i].y);
    gi.width = static_cast<int>(m_assetSpriteData[i].width);
    gi.height = static_cast<int>(m_assetSpriteData[i].height);
    gi.scale = m_assetSpriteData[i].scale;    
    gi.alpha = m_assetSpriteData[i].alpha;
    gi.angle = m_assetSpriteData[i].angle;
    gi.frameMax = m_assetSpriteData[i].numberFrames;
    gi.updateInterval = m_assetSpriteData[i].timeBetweenFrames;
    gi.frameCount = 0;
    gi.screenScale = 1.0; //added 4.8.09 by CB used in passing screen scale to render function
    
    //ensure the fileID really exists
    gi.bValid = false; //assume file is invalid
    for(unsigned int j = 0; j < m_assetFileData.size(); ++j){
      if(gi.fileID == m_assetFileData[j].fileID){
        gi.bValid = true;
        m_sprites.push_back(gi);
        break;
      }
    }
  }


  return true;
}
Пример #17
0
bool CConfigData::LoadConfigFile(std::string configFilename){
  CLog *pLog = CLog::Instance();

  //function variables
  std::string line;
  int equalCount = 0;
  std::ifstream file(configFilename.c_str());
  
  //open file for reading
  if(file.is_open()){

    //read one line at a time
    pLog->Log("Reading config file");
    while(!file.eof()){
      getline (file, line);
      line = RemoveSpaces(line);
      line = RemoveComments(line);
      equalCount = CountEqualSigns(line);
      if(line.size() != 0 && equalCount == 1){
        m_lines.push_back(line);
        equalCount = 0;
        pLog->Log("Config line", line);
      }
    }

    file.close();
  }

  //file doesn't exist
  else
    return false;

  //break string into key and value
  std::string key;
  std::string value;
  size_t equalPos = 0;
  bool bFound;
  
  pLog->Log("***************************************");
  pLog->Log("Configuration File Data (key = value)");
  pLog->Log("***************************************");

  for(size_t i = 0; i < m_lines.size(); ++i){
    
    equalPos = m_lines[i].find("=");
    if(equalPos > 0){
      key = m_lines[i].substr(0, equalPos);
      value = m_lines[i].substr(equalPos + 1);
      
      //load all config variables with values
      bFound = false;

      if(key == "ScreenLeft"){
        ScreenLeft = atoi(value.c_str());
        bFound = true;
      }
      else if(key == "ScreenTop"){
        ScreenTop = atoi(value.c_str());
        bFound = true;
      }
      else if(key == "ScreenWidth"){
        ScreenWidth = atoi(value.c_str());
        bFound = true;
      }
      else if(key == "ScreenHeight"){
        ScreenHeight = atoi(value.c_str());
        bFound = true;
      }
      else if(key == "FullScreen"){
        if(atoi(value.c_str()) == 1)
          FullScreen = true;
        else
          FullScreen = false;
        bFound = true;
      }
      else if(key == "DisplayDebugInfo"){
        if(atoi(value.c_str()) == 0)
          DisplayDebugInfo = false;
        else if(atoi(value.c_str()) == 1)
          DisplayDebugInfo = true;
        bFound = true;
      }
      else if(key == "LogDebugInfo"){
        if(atoi(value.c_str()) == 0)
          LogDebugInfo = false;
        else if(atoi(value.c_str()) == 1)
          LogDebugInfo = true;
        bFound = true;
      }
      else if(key == "PlaySounds"){
        if(atoi(value.c_str()) == 0)
          PlaySounds = false;
        else if(atoi(value.c_str()) == 1)
          PlaySounds = true;
        bFound = true;
      }
      else if(key == "PlayMusic"){
        if(atoi(value.c_str()) == 0)
          PlayMusic = false;
        else if(atoi(value.c_str()) == 1)
          PlayMusic = true;
        bFound = true;
      }
      else if(key == "FrameworkAssetFile"){
        FrameworkAssetFile = value;
        bFound = true;
      }
      else if(key == "GamePlayAssetFile"){
        GamePlayAssetFile = value;
        bFound = true;
      }
      else if(key == "SoundAssetFile"){
        SoundAssetFile = value;
        bFound = true;
      }

      else if(key == "ObjectsFile"){
        ObjectsFile = value;
        bFound = true;
      }
      else if(key == "EffectsFile"){
        EffectsFile = value;
        bFound = true;
      }
      else if(key == "EffectsFileI"){
        EffectsFileI = value;
        bFound = true;
      }
      else if(key == "CreditsFile"){
        CreditsFile = value;
        bFound = true;
      }
      else if(key == "TilesFile"){
        TilesFile = value;
        bFound = true;
      }
      else if(key == "ProgramName"){
        ProgramName = value;
        bFound = true;
      }
      else if(key == "ProgramVersion"){
        ProgramVersion = value;
        bFound = true;
      }     
      else if(key == "RootPath"){
        RootPath = value;
        bFound = true;
      }     

      /*
      else if(key == "Level1"){
        Level1 = value;
        bFound = true;
      }
      else if(key == "Level2"){
        Level2 = value;
        bFound = true;
      }
      else if(key == "Level3"){
        Level3 = value;
        bFound = true;
      }
      else if(key == "Level4"){
        Level4 = value;
        bFound = true;
      }
      else if(key == "Level5"){
        Level5 = value;
        bFound = true;
      }
      else if(key == "Level6"){
        Level6 = value;
        bFound = true;
      }
      else if(key == "Level7"){
        Level7 = value;
        bFound = true;
      }
      else if(key == "Level8"){
        Level8 = value;
        bFound = true;
      }
      else if(key == "Level9"){
        Level9 = value;
        bFound = true;
      }
      else if(key == "Level10"){
        Level10 = value;
        bFound = true;
      }
      */
      if(bFound == false)
        pLog->Log("No match for config file key", key);
    }
  }
}
Пример #18
0
void cGameStateCredits::render(CGraphics &con, Camera &cam, CGameData &data){

::ShowCursor(false);
  CLog *pLog = CLog::Instance();
  static bLostDevice = false;

  HRESULT hr;

  if(FAILED(hr = con.m_d3ddev->TestCooperativeLevel())){

    pLog->Log("Failed test");
    if(hr == D3DERR_DEVICELOST)
      return;
    pLog->Log("No lost");
    if( hr == D3DERR_DEVICENOTRESET ){
      pLog->Log("Time to reset");
      con.DeleteLost();
      pLog->Log("Deleted everything");
      hr = con.m_d3ddev->Reset(&con.GetDPP());
      pLog->Log("Dev reset");
      con.ReloadLost();
      pLog->Log("ReloadLost");
      bLostDevice = false;
      return;
    }
  }

  D3DXMATRIX V;
  cam.getViewMatrix(&V, 0);
  con.m_d3ddev->SetTransform(D3DTS_VIEW, &V);

  // clear the window to a deep blue
  con.m_d3ddev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 200, 200), 1.0f, 0);
  con.m_d3ddev->BeginScene();    // begins the 3D scene

  //render credits
  GRAPHIC_IMAGE gi;
  gi = con.GetSprite(2);
  //con.RenderGraphicModulate(gi, data.m_screenWidth - 240, 40, 255, 255, 255);

  //scrolls message
  int posY = 0;
  
  for(int i = 0; i < m_msg.size(); i++){
    posY = m_scrollValue + ((int)m_msg.size() - i * 20);
    if(m_msg[i].type == 0)  //font
      con.Print(m_msg[i].msg, m_msg[i].font , m_msg[i].x, con.GetScreenHeight() - posY, m_msg[i].red, m_msg[i].green, m_msg[i].blue,255);
    else{//graphic
      con.RenderGraphicModulate(m_msg[i].gi, m_msg[i].x, con.GetScreenHeight() -posY, 255, 255, 255);
    }
  }

  con.Print("Press ESCAPE to Continue!", F_V20B, data.m_screenWidth/2 - 130, data.m_screenHeight - 60, 255, 255, 0, 255);

  if(data.m_displayDebugInfo == true){
    con.Print("Version", data.m_version, F_V16, 40, 730,  255, 255, 255, 255);
    con.Print("FPS", data.m_FPS , F_V16, 930, 730,  255, 255, 255, 255);    
  }  

  con.m_d3ddev->EndScene();    // ends the 3D scene
  hr = con.m_d3ddev->Present(NULL, NULL, NULL, NULL);   // displays the created frame on the screen

  if(FAILED(hr = con.m_d3ddev->TestCooperativeLevel())){
    if(hr == D3DERR_DEVICELOST)
      bLostDevice = true;
  }

  return;
}
Пример #19
0
bool CGameData::LoadConfigFile(std::string filename){
  CLog *pLog = CLog::Instance();

  //load config.txt file to configure game
  CINIReader cir;
  cir.LoadFile(filename);

  if(cir.IsValid() == false){
    pLog->Log("INI File invalid!");
    return false;
  }
  if(cir.GetNumberOfLines() < 1){
    pLog->Log("No parameters in INI file!");
    return false;
  }

  std::string value;
  std::string key;
  pLog->Log("******** Loading Config.txt **********", filename);
  
  for(int i = 0; i < cir.GetNumberOfLines(); ++i){

      //read key and value from file
      key = cir.GetTerm(cir.GetLineFromFile(i),1);
      value = cir.GetTerm(cir.GetLineFromFile(i),2);
     // pLog->Log("config.txt data", key, value);

      //screen and window information
      if(key == "screen_left")
        m_screenLeft = atoi(value.c_str());
      if(key == "screen_top")
        m_screenTop = atoi(value.c_str());
      if(key == "screen_width")
        m_screenWidth = atoi(value.c_str());
      if(key == "screen_height")
        m_screenHeight = atoi(value.c_str());

      if(key == "full_screen")
        if(value == "1")
          m_bFullScreen = true;
        else
          m_bFullScreen = false;

      //display debug information
      if(key == "display_debug_info"){
        if(value == "1")
          m_displayDebugInfo = true;
        else
          m_displayDebugInfo = false;
      }

      //play background music
      if(key == "play_music"){
        if(value == "1")
          m_playMusic = true;
        else
          m_playMusic = false;
      }

      //level information
      if(key == "current_level")
        m_currentLevel = atoi(value.c_str());
      if(key == "max_levels")
        m_maxLevels = atoi(value.c_str());
      if(key == "level_file1")
        m_levelFilename[0] = value;
      if(key == "level_file2")
        m_levelFilename[1] = value;
      if(key == "level_file3")
        m_levelFilename[2] = value;
      if(key == "level_file4")
        m_levelFilename[3] = value;
      if(key == "level_file5")
        m_levelFilename[4] = value;
      if(key == "level_file6")
        m_levelFilename[5] = value;
      if(key == "level_file7")
        m_levelFilename[6] = value;
      if(key == "level_file8")
        m_levelFilename[7] = value;
      if(key == "level_file9")
        m_levelFilename[8] = value;
      if(key == "level_file10")
        m_levelFilename[9] = value;

  }

  //LogKeyValue();

  return true;
}
Пример #20
0
/************************************************************************************************
  WinMain (...)
************************************************************************************************/
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	// Always perform a leak check just before app exits.
	int nDbgFlags = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
	nDbgFlags |= _CRTDBG_LEAK_CHECK_DF;
	_CrtSetDbgFlag(nDbgFlags);

  //instantiate log object and log
  CLog *pLog = CLog::Instance();
  pLog->Log("*********************************************************");
  pLog->Log("Program starting..................");
  pLog->SetDelimiter(':');
  pLog->LogDate();
  pLog->LogTime();
  pLog->Log("************************ *********************************");


  pLog->Log ("***********************************************");
  pLog->Log("Game Challenge 6");
  pLog->LogDate();
  pLog->LogTime();
  pLog->Log("***********************************************");

  Graphics g_con;  
  CAudioManager *pAudio = CAudioManager::Instance();

  //***********************************************************************
  //read config.ini file
  // C O N F I G . I N I
  //***********************************************************************
  pLog->Log("************ Config.ini ************");
  CINIReader config;          //reads and stores INI file data
  config.LoadFile("config.ini");
  std::string sValue;
  std::string sParameter;
  int nParameterValue;

  //default values
  g_Global.g_screenWidth = 1024;
  g_Global.g_screenHeight = 768;

  if(config.IsValid() == true){
    pLog->Log("Valid config.ini file");
    pLog->Log("Numbers of lines in config file",config.GetNumberOfLines());

    for(int j=0; j< config.GetNumberOfLines();j++){
      sParameter = config.GetTerm(config.GetLineFromFile(j),1);
      sValue = config.GetTerm(config.GetLineFromFile(j),2);
      nParameterValue =  atoi(sValue.c_str());

      pLog->Log(sParameter, nParameterValue);      
      
      //load g_Global object with config.ini data
      if(sParameter == "WindowedMode" && nParameterValue == 1)
        g_Global.g_WindowedMode = true;
      else if(sParameter == "WindowedMode" && nParameterValue == 0)
        g_Global.g_WindowedMode = false;
      //else if(sParameter == "ScreenWidth" && nParameterValue > 0)
      //  g_Global.g_screenWidth = nParameterValue;
      //else if(sParameter == "ScreenHeight" && nParameterValue > 0)
      //  g_Global.g_screenHeight = nParameterValue;
      //else if(sParameter == "GameLevel" && nParameterValue > 0 && nParameterValue < 6)
      //  g_Global.g_GameLevel = nParameterValue;
      //else if(sParameter == "GameSnow" && nParameterValue == 1)
      //  g_Global.g_bGameSnow = true;
      //else if(sParameter == "GameSnow" && nParameterValue == 0)
      //  g_Global.g_bGameSnow = false;
      else if(sParameter == "GameAudio" && nParameterValue == 1)
        g_Global.g_bGameAudio = true;
      else if(sParameter == "GameAudio" && nParameterValue == 0)
        g_Global.g_bGameAudio = false;
      else if(sParameter == "FrameRate" && nParameterValue == 1)
        g_Global.g_bDisplayFramerate = true;
      else if(sParameter == "FrameRate" && nParameterValue == 0)
        g_Global.g_bDisplayFramerate = false;
    }
  } 
  pLog->Log("Reading Config.ini file is complete!");
	// Break on specific memory allocation number
	//_CrtSetBreakAlloc(175);
  
  MSG msg;    
  g_bRunning = true;//Start program running

  //Make a window and initialize DirectX in windowed mode
  MakeWindow(hInstance, g_Global.g_WindowedMode, g_con);

  //map game state information
  g_pStateIntro->addTransitionEvent(EVENT_GO_MAIN, g_pStateMain);
  g_pStateMain->addTransitionEvent(EVENT_GO_HISTORY, g_pStateHistory);
  g_pStateMain->addTransitionEvent(EVENT_GO_RELOAD, g_pStateReload);
  g_pStateMain->addTransitionEvent(EVENT_GO_CREDITS, g_pStateCredits);
  g_pStateMain->addTransitionEvent(EVENT_GO_SELECT, g_pStateSelect);
  g_pStateHistory->addTransitionEvent(EVENT_GO_MAIN, g_pStateMain);
  g_pStateReload->addTransitionEvent(EVENT_GO_MAIN, g_pStateMain);
  g_pStateCredits->addTransitionEvent(EVENT_GO_END, g_pStateEnd);
  g_pStateSelect->addTransitionEvent(EVENT_GO_AWARDS, g_pStateAwards);
  g_pStateAwards->addTransitionEvent(EVENT_GO_SELECT, g_pStateSelect);  
  g_pStateSelect->addTransitionEvent(EVENT_GO_PLAY, g_pStatePlay);
  g_pStateSelect->addTransitionEvent(EVENT_GO_MAIN, g_pStateMain);
  g_pStatePlay->addTransitionEvent(EVENT_GO_WIN, g_pStateWin);
  g_pStatePlay->addTransitionEvent(EVENT_GO_LOSE, g_pStateLose);
  g_pStateWin->addTransitionEvent(EVENT_GO_SELECT, g_pStateSelect);
  g_pStateLose->addTransitionEvent(EVENT_GO_SELECT, g_pStateSelect);
  g_pStatePlay->addTransitionEvent(EVENT_GO_SELECT, g_pStateSelect);
  g_pStatePlay->addTransitionEvent(EVENT_GO_CONTROL, g_pStateControl);
  
  //sonar transitions
  g_pStateSonar->addTransitionEvent(EVENT_GO_RADAR, g_pStateRadar);
  g_pStateSonar->addTransitionEvent(EVENT_GO_FIRECONTROL, g_pStateFireControl);
  g_pStateSonar->addTransitionEvent(EVENT_GO_STATUS, g_pStateStatus);
  g_pStateSonar->addTransitionEvent(EVENT_GO_CHART, g_pStateChart);  
  g_pStateSonar->addTransitionEvent(EVENT_GO_CONTROL, g_pStateControl);

  //radar transitions
  g_pStateRadar->addTransitionEvent(EVENT_GO_SONAR, g_pStateSonar);
  g_pStateRadar->addTransitionEvent(EVENT_GO_FIRECONTROL, g_pStateFireControl);
  g_pStateRadar->addTransitionEvent(EVENT_GO_STATUS, g_pStateStatus);
  g_pStateRadar->addTransitionEvent(EVENT_GO_CHART, g_pStateChart);  
  g_pStateRadar->addTransitionEvent(EVENT_GO_CONTROL, g_pStateControl);

  //scope transitions
  g_pStateScope->addTransitionEvent(EVENT_GO_CONTROL, g_pStateControl);
  g_pStateScope->addTransitionEvent(EVENT_GO_WIN, g_pStateWin);
  g_pStateScope->addTransitionEvent(EVENT_GO_LOSE, g_pStateLose);
  
  //conn transitions
  g_pStateControl->addTransitionEvent(EVENT_GO_PLAY, g_pStatePlay);
  g_pStateControl->addTransitionEvent(EVENT_GO_SONAR, g_pStateSonar);
  g_pStateControl->addTransitionEvent(EVENT_GO_RADAR, g_pStateRadar);
  g_pStateControl->addTransitionEvent(EVENT_GO_FIRECONTROL, g_pStateFireControl);
  g_pStateControl->addTransitionEvent(EVENT_GO_STATUS, g_pStateStatus);
  g_pStateControl->addTransitionEvent(EVENT_GO_CHART, g_pStateChart);  
  g_pStateControl->addTransitionEvent(EVENT_GO_SCOPE, g_pStateScope);
  g_pStateControl->addTransitionEvent(EVENT_GO_SELECT, g_pStateSelect);
  g_pStateControl->addTransitionEvent(EVENT_GO_WIN, g_pStateWin);
  g_pStateControl->addTransitionEvent(EVENT_GO_LOSE, g_pStateLose);

  //fire control transitions
  g_pStateFireControl->addTransitionEvent(EVENT_GO_SONAR, g_pStateSonar);
  g_pStateFireControl->addTransitionEvent(EVENT_GO_RADAR, g_pStateRadar);
  g_pStateFireControl->addTransitionEvent(EVENT_GO_STATUS, g_pStateStatus);
  g_pStateFireControl->addTransitionEvent(EVENT_GO_CHART, g_pStateChart);  
  g_pStateFireControl->addTransitionEvent(EVENT_GO_CONTROL, g_pStateControl);

  //status transitions
  g_pStateStatus->addTransitionEvent(EVENT_GO_SONAR, g_pStateSonar);
  g_pStateStatus->addTransitionEvent(EVENT_GO_RADAR, g_pStateRadar);
  g_pStateStatus->addTransitionEvent(EVENT_GO_FIRECONTROL, g_pStateFireControl);
  g_pStateStatus->addTransitionEvent(EVENT_GO_CHART, g_pStateChart);  
  g_pStateStatus->addTransitionEvent(EVENT_GO_CONTROL, g_pStateControl);

  //chart transitions
  g_pStateChart->addTransitionEvent(EVENT_GO_SONAR, g_pStateSonar);
  g_pStateChart->addTransitionEvent(EVENT_GO_RADAR, g_pStateRadar);
  g_pStateChart->addTransitionEvent(EVENT_GO_FIRECONTROL, g_pStateFireControl);
  g_pStateChart->addTransitionEvent(EVENT_GO_STATUS, g_pStateStatus);
  g_pStateChart->addTransitionEvent(EVENT_GO_CONTROL, g_pStateControl);
  g_pStateChart->addTransitionEvent(EVENT_GO_WIN, g_pStateWin);
  g_pStateChart->addTransitionEvent(EVENT_GO_LOSE, g_pStateLose);

  g_Timer.initialize();
  g_LoopTimer.initialize();
  g_FPS_Timer.initialize();
  g_con.InitD3D (g_hWnd, g_Global.g_WindowedMode);

  //***********************************************************************
  //load textures from graphics file
  // G R A P H I C F I L E S . D A T
  //***********************************************************************
  pLog->Log("************ Graphicfiles.dat ************");
  CFileReader* cfr = new CFileReader;
  cfr->LoadFile("data\\graphicfiles.dat");
  int fileNumber;
  std::string fileName;
  if(cfr->IsValid()== true){
    pLog->Log("Numbers of lines in file",cfr->GetNumberOfLines());
    for(int j=0; j< cfr->GetNumberOfLines();j++){
      sValue =cfr->GetTerm(cfr->GetLineFromFile(j),1);
      fileNumber = atoi(sValue.c_str());
      sValue = cfr->GetTerm(cfr->GetLineFromFile(j),2);
      fileName = "assets\\artwork\\";
      fileName = fileName + sValue;
      //pLog->Log("Loaded file",fileName);
      pLog->Log(fileName, fileNumber);
      g_con.LoadTexture(fileName, fileNumber);
    }
  } 
  else{
    pLog->Log("ERROR****************** Failure to load textures (graphicfiles.dat)");
    delete cfr;
    g_con.CloseD3D();
    pLog->Log("DirectX closed!");
    Shutdown();
    return 0;
  }

  if(g_Sprite.LoadSprites() == true){
    pLog->Log("Sprites loaded!");
  }
  else{
    pLog->Log("ERROR****************** Failure to sprite data (sprites.dat)");
  }

  //used for framerate display
  std::ostringstream oss;
  std::string sFramerate;
  std::string sText;
  int nDisplayFPSCount = 0;

  //initialize audio manager
  //***************************************************************
  if(g_Global.g_bGameAudio == true){
    pLog->Log("Loading audio clip...");
    if(pAudio->IsValidSound())
      pLog->Log("Audio system is okay!");
    else
      pLog->Log("Audio system failure!");
    
    //load sounds
    pAudio->LoadSample(SOUND_BEEP, "assets\\sounds\\beep-03.wav");
    pAudio->LoadSample(SOUND_REMEMBER, "assets\\sounds\\remember.mp3");
    pAudio->LoadSample(SOUND_HYMN, "assets\\sounds\\navy_hymn.mp3");
    pAudio->LoadSample(SOUND_PERISCOPE, "assets\\sounds\\periscop.wav");
    pAudio->LoadSample(SOUND_BUTTON_CLICK, "assets\\sounds\\button_click.wav");
    pAudio->LoadSample(SOUND_DEPTH_CHARGE1,"assets\\sounds\\dc1.mp3");
    pAudio->LoadSample(SOUND_DEPTH_CHARGE2,"assets\\sounds\\dc2.mp3");
    pAudio->LoadSample(SOUND_TORPEDO1,"assets\\sounds\\torpedo3.mp3");
    pAudio->LoadSample(SOUND_TORPEDO2,"assets\\sounds\\torpedo4.mp3");
    pAudio->LoadSample(SOUND_AMBIENCE1,"assets\\sounds\\ambience1.mp3");
    pAudio->LoadSample(SOUND_CLEAR_BRIDGE,"assets\\sounds\\clear_bridge.wav");
    pAudio->LoadSample(SOUND_DIVING,"assets\\sounds\\diving.mp3");
    pAudio->LoadSample(SOUND_GQ,"assets\\sounds\\general_quarters.wav");
    pAudio->LoadSample(SOUND_ANCHORS,"assets\\sounds\\AnchorsAway.mp3");
    pAudio->LoadSample(SOUND_TAPS,"assets\\sounds\\Taps.mp3");
    pAudio->LoadSample(SOUND_SINKING,"assets\\sounds\\sinking2.mp3");
    pAudio->LoadSample(SOUND_ANTHEM,"assets\\sounds\\USA.mp3");
    pAudio->LoadSample(SOUND_FUNERAL,"assets\\sounds\\fnrlMrch.wav");
    pAudio->LoadSample(SOUND_PING,"assets\\sounds\\sonar1.mp3");
    
    //load stream
    pAudio->LoadStream(SOUND_BIO, "assets\\sounds\\fish.mp3");
    pAudio->AddStreamClip(SOUND_BIO1, SOUND_BIO, 0, 17708);
    pAudio->AddStreamClip(SOUND_BIO2, SOUND_BIO, 17708, 26434);
    pAudio->AddStreamClip(SOUND_BIO3, SOUND_BIO, 26434, 42859);
    pAudio->AddStreamClip(SOUND_BIO4, SOUND_BIO, 42859, 59541);
    pAudio->AddStreamClip(SOUND_BIO5, SOUND_BIO, 59541, 80073);

    for(int i = 0; i < pAudio->Size(); i++){
      pLog->Log(pAudio->GetFilename(i), i); //write filename and file index to log file
    }
  }
  else{
    pLog->Log("Audio disabled");
  }

  pLog->Log("Main game loop entered!");
  ::ShowCursor(false); 
  //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Version Number
  //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Version Number
  //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Version Number
  //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Version Number
  g_strFPS = "Game Challenge 6 (Chuck Bolin) - \"Sinking of the Rising Sun\", v0.047 Final Version";
  ::SetWindowText(g_hWnd, g_strFPS.c_str());
  double timeDelta;

  g_con.InitializePyro();

  //Main application loop
  //*******************************************************
  while (g_bRunning)
  {
    //Handle messages
    if (PeekMessage (&msg,NULL,0,0,PM_REMOVE)){
        TranslateMessage (&msg);
        DispatchMessage (&msg);
    }        
    else{}
      timeDelta = g_LoopTimer.getTimeDifference();
      g_pNext = g_pCurrent->update(timeDelta);
      if(g_pNext == g_pStateEnd)
        g_bRunning = false;
      else if(NULL != g_pNext)
	    {
        g_pCurrent->deactivate();
        g_pCurrent = g_pNext;
        g_pCurrent->activate();
      }
     
	  // Render our current game object
    g_pCurrent->render(g_con);

    //call each second update FPS
    nDisplayFPSCount++;
    if(g_FPS_Timer.getTimer(1)){
      //g_FPS_Counter++;
      oss.str(""); //clear oss
      oss << (int) nDisplayFPSCount;
      //if(g_FPS_Counter > 60){  //call every 60 seconds
      //  pLog->Log("FPS",oss.str());
      //  g_FPS_Counter == 0;
      //}

  	  // update our FPS string.
	    // This thing can be rendered inside any of the game objects.
      g_strFPS = "FPS " + oss.str();
      g_Global.g_strFPS = "FPS " + oss.str();

      nDisplayFPSCount=0;//reset frame count
    }
  }//while(...
  g_con.ClosePyro();
  g_con.CloseD3D();
  pLog->Log("DirectX closed!");
  Shutdown();

  return 0;//(int)msg.wParam;  //returns exit code to operating system
} 
Пример #21
0
/*************************************************************************
MakeWindow - Creates window
*************************************************************************/
int MakeWindow (HINSTANCE hInstance, bool bWindowedMode, Graphics &g_con)
{
    CLog *pLog = CLog::Instance();

    WNDCLASSEX wc;
    
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = WindowProcedure;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE(IDI_ICON1)); 
    wc.hCursor = LoadCursor(hInstance, MAKEINTRESOURCE(IDC_CURSOR3));   //NULL;//(HCURSOR)IDC_CROSS;
    wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = "GC6";
    wc.hIconSm = LoadIcon (hInstance, MAKEINTRESOURCE(IDI_ICON1)); 
    
    if(!RegisterClassEx(&wc))
        return false;    

    //screen data
    int cxScreen, cyScreen;
	  cxScreen = ::GetSystemMetrics(SM_CXMAXIMIZED);
	  cyScreen = ::GetSystemMetrics(SM_CYMAXIMIZED);
    if(g_Global.g_screenWidth < 1 || g_Global.g_screenWidth > cxScreen)
      g_Global.g_screenWidth = cxScreen;   
    if(g_Global.g_screenHeight < 1 || g_Global.g_screenHeight > cyScreen)
      g_Global.g_screenHeight = cyScreen;    

    //Create window
    g_hWnd = CreateWindowEx (NULL, "GC6", " ",
        g_Global.g_WindowedMode ? WS_BORDER | WS_CAPTION | WS_SYSMENU : WS_EX_TOPMOST,
		0,								// x position
		0,								// y position
		g_Global.g_WindowedMode ? g_Global.g_screenWidth : CW_USEDEFAULT,	// width
		g_Global.g_WindowedMode ? g_Global.g_screenHeight : CW_USEDEFAULT,	// height
    NULL, NULL, hInstance, NULL);
    
    
    if (!g_hWnd){//Make sure window was created properly
      pLog->Log("Window failed to create!");
      return false;
    }
    pLog->Log("Window creation successful!");

  	// Show the window!
    ShowWindow( g_hWnd, SW_SHOW );
    UpdateWindow( g_hWnd );

	  // Read the actual screen size
	  RECT rc;
    ::GetClientRect( g_hWnd, &rc );
	  int ViewWidth, ViewHeight;
    ViewWidth  = rc.right - rc.left;
    ViewHeight = rc.bottom - rc.top;
    g_con.SetScreenWidthHeight(ViewWidth, ViewHeight);//ViewWidth, ViewHeight);
    pLog->Log("WIDTH",g_con.GetScreenWidth());
    pLog->Log("HEIGHT", g_con.GetScreenHeight());
    return true;//Success
}
Пример #22
0
/*************************************************************************
Window Procedure - Process Windows events

*************************************************************************/
LRESULT CALLBACK WindowProcedure (HWND g_hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
{
    CLog *pLog = CLog::Instance();

    //Check message
    switch(uMessage)
    {

    case WM_CREATE:
      g_pStateIntro->initialize();
      g_pStateMain->initialize();
      g_pStatePlay->initialize();    
      g_pStateEnd->initialize();
      g_pStateHistory->initialize();
      g_pStateReload->initialize();
      g_pStateCredits->initialize();
      g_pStateSelect->initialize();
      g_pStateAwards->initialize();
      g_pStateWin->initialize();
      g_pStateLose->initialize();
      g_pStateStatus->initialize();
      g_pStateChart->initialize();
      g_pStateControl->initialize();
      g_pStateSonar->initialize();
      g_pStateEnd->initialize();
      g_pStateScope->initialize();
      g_pStateFireControl->initialize();
      g_pStateRadar->initialize();
      g_pCurrent = g_pStateIntro;
      g_pStateIntro->activate();
      pLog->Log("Game states initialized!");
      pLog->Log("Game State = Intro");
      return 0;

	  case WM_CLOSE:
		  g_bRunning = false;
		  break;

    case WM_DESTROY:
      //Shutdown();
  	  PostQuitMessage(0);
      break;

    case WM_LBUTTONDOWN:
      g_Global.g_bLeftMouseDown = true;
      return 0;

    case WM_LBUTTONUP:
      g_Global.g_bLeftMouseDown = false;
      return 0;

    case WM_RBUTTONDOWN:
    case WM_RBUTTONUP:
      
    //case WM_MOUSEMOVE:
      return 0;
    
    }
   // return 0;
    return DefWindowProc(g_hWnd,uMessage,wParam,lParam);
}