5 #include <SDL/SDL_opengl.h>
6 #include <SDL/SDL_ttf.h>
19 m_instance =
new Game;
27 ShowCollisions(false),
35 CurrentParticleSystem(NULL),
36 CurrentParticle(NULL),
45 mLevels(map<string,
Level*>()),
48 int screenwidth = 640;
49 int screenheight = 480;
52 if (SDL_Init(SDL_INIT_VIDEO) < 0) {
53 cout<<
"Couldn't initialize SDL: "<<SDL_GetError()<<endl;
57 if(SDL_InitSubSystem(SDL_INIT_EVENTTHREAD)<0)
58 cout<<
"Couldn't initialize SDL: "<<SDL_GetError()<<endl;
66 cout <<
"TTF_Init() Failed: " << TTF_GetError() << endl;
74 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
75 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
78 SDL_WM_SetCaption(
"Ivan's Game", NULL);
82 resize(screenwidth, screenheight);
85 srand(time(0)+SDL_GetTicks());
137 cout<<
"Level "<<name<<
" does not exist."<<endl;
141 auto level =
mLevels.find(name);
144 level->second->
load();
146 return level->second;
148 cout<<
"Level "<<name<<
" does not exist."<<endl;
178 while(SDL_PollEvent(&event))
184 if (0 == SDL_WaitEvent(&event)) {
185 std::cout<<
"waiting"<<std::endl;
217 pair<FontType,int> key = pair<FontType,int>(t,s);
218 map<pair<FontType, int>,
Font*>::iterator it =
mFonts.find(key);
226 Font* f = it->second;
233 pair<FontType,int> key = pair<FontType,int>(t,s);
234 map<pair<FontType, int>,
Font*>::iterator it =
mFonts.find(key);
237 Font* f = it->second;
257 glGenTextures(1, &tex->
image);
265 glGenTextures(1, &t->
image);
279 glDeleteTextures(1, &val->
image);
295 for(
int i=0, count=
mAnims.size(); i < count; i++) {
296 if(
mAnims[i]->Name==name) {
307 cout<<
"Could not load "<<name<<
" because:"<<e.what()<<endl;
323 mActors.insert(make_pair(name, actor));
368 auto level =
mLevels.find(name);
373 cout<<
"Level "<<name<<
" already exists!"<<endl;
379 switch (event.type) {
390 case SDL_ACTIVEEVENT:
391 switch(event.active.state)
393 case SDL_APPMOUSEFOCUS:
398 case SDL_APPINPUTFOCUS:
399 if(event.active.gain==1)
401 cout<<
"Appinputfocus gained"<<endl;
411 cout<<
"inputfocus lost"<<endl;
419 if(event.active.gain==1)
421 cout<<
"active gained"<<endl;
431 cout<<
"active lost"<<endl;
437 case SDL_APPINPUTFOCUS | SDL_APPACTIVE:
438 if(event.active.gain==1)
442 cout<<
"Focus and input gained"<<endl;
450 cout<<
"got something unexpected:"<<(int)event.active.state<<endl;
455 case SDL_VIDEORESIZE :
456 resize( event.resize.w, event.resize.h ) ;
473 std::cout<<
"pressed:"<<
event.key.keysym.sym<<std::endl;
474 switch(event.key.keysym.sym)
529 SDL_GL_SwapBuffers();
534 if(SDL_InitSubSystem(SDL_INIT_TIMER)<0)
535 cout<<
"Couldn't initialize SDL: "<<SDL_GetError()<<endl;
538 std::cout <<
"Timer creation failed" << std::endl;
545 SDL_RemoveTimer(
timer);
546 SDL_QuitSubSystem(SDL_INIT_TIMER);
550 mScreen = SDL_SetVideoMode(w, h, 32, SDL_OPENGL | SDL_RESIZABLE);
552 cout<<
"Couldn't set video mode: "<<SDL_GetError()<<endl;
557 glClearColor (0.0, 0.0, 0.0, 0.0);
560 glEnable( GL_TEXTURE_2D );
562 glViewport( 0, 0, w, h );
564 glMatrixMode( GL_PROJECTION );
567 glOrtho( 0, w, h, 0, -1, 1 );
569 glMatrixMode( GL_MODELVIEW );
571 glDepthFunc(GL_LEQUAL);
578 SDL_UserEvent uevent = {
585 SDL_PushEvent(&event);
591 Uint32 startclock = SDL_GetTicks();
607 Uint32 frameTotal = 0;