Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "SDLEntity.h"
- #include "SDLApplication.h"
- #include "SDLSound.h"
- #include "SDLTimer.h"
- #include "SDLTyper.h"
- #include "GameScore.h"
- int main(int argc, char* argv[])
- {
- try{
- SDL_Application *g_Application = new SDL_Application();
- SDLSound *g_Sound = new SDLSound();
- SDLEntity *g_Entity = new SDLEntity();
- SDL_Timer *g_Timer = new SDL_Timer();
- SDLTyper *g_Typer = new SDLTyper();
- GScore *g_Score = new GScore();
- if(g_Application->Init() || g_Sound->Init() || g_Typer->Init())
- {
- throw g_Application->InvalidPath;
- }
- g_Typer->Init();
- g_Typer->OpenFont(FONT);
- g_Application->SetCaption(WINNAME);
- g_Application->InitBackground(BACKGROUND);
- g_Application->DrawBackground();
- g_Sound->InitBGSound(BGSOUND);
- g_Sound->EmitBGSound();
- g_Sound->InitActionSound(g_Sound->GoodShoot, SHOOT);
- g_Entity->InitSurface(ENTITY);
- g_Entity->Move(g_Application->GetScreenSurface(), 0, 0);
- g_Timer->Set(1000);
- while(g_Application->m_isGameRunning)
- {
- g_Application->CheckForGameExit();
- if(g_Application->HandleMouseInput(g_Entity->GetRect()) || !g_Timer->IsTimerRun())
- {
- g_Application->DrawBackground();
- g_Entity->Move(g_Application->GetScreenSurface(), rand() % (g_Application->Width - g_Entity->GetRect()->w), rand() % (g_Application->Heigth - g_Entity->GetRect()->h));
- if(g_Timer->IsTimerRun())
- {
- g_Sound->EmitActionSound(g_Sound->GoodShoot);
- g_Typer->DisplayText(g_Application->GetScreenSurface(), 0, "Nice Shoot!");
- g_Score->Add();
- }
- else
- {
- g_Score->Sub();
- g_Typer->DisplayText(g_Application->GetScreenSurface(), 0, "Fail!");
- }
- g_Timer->Set(rand() % (1000 - 500) + 500);
- }
- g_Typer->DisplayText(g_Application->GetScreenSurface(), 620, g_Score->ToString().c_str());
- g_Timer->Update();
- g_Application->UpdateWindow();
- }
- delete g_Score;
- delete g_Typer;
- delete g_Sound;
- delete g_Application;
- delete g_Entity;
- delete g_Timer;
- }
- catch(unsigned exeption)
- {
- char* ErrorMessage = nullptr;
- switch(exeption)
- {
- case SDL_Application::InvalidPath:
- {
- ErrorMessage = "Invalid path.";
- break;
- }
- case SDL_Application::InvalidEntityId:
- {
- ErrorMessage = "Invalid entity id.";
- break;
- }
- case SDL_Application::InvalidSound:
- {
- ErrorMessage = "Invalid sound.";
- break;
- }
- }
- MessageBoxA(nullptr, (std::string("Game was aborted with error: ") + ErrorMessage).c_str() , nullptr, MB_OK);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment