1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| #include "MainClass.h"
CMain::CMain(void)
{
this->m_quit = false;
this->m_window = NULL;
//Initialize SDL
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "SDL could not initialize! SDL Error: %s\n", SDL_GetError() );
this->m_quit = true;
}
else
{
//Set texture filtering to linear
if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) )
{
printf( "Warning: Linear texture filtering not enabled!" );
}
//Create window
this->m_window = SDL_CreateWindow( "Colliding Balls", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
if( this->m_window == NULL )
{
printf( "Window could not be created! SDL Error: %s\n", SDL_GetError() );
this->m_quit = true;
}
else
{
//Create renderer for window
this->m_renderer = SDL_CreateRenderer( this->m_window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC );
if( m_renderer == NULL )
{
printf( "Renderer could not be created! SDL Error: %s\n", SDL_GetError() );
this->m_quit = true;
}
else
{
//Initialize renderer color
SDL_SetRenderDrawColor( this->m_renderer, 0xFF, 0xFF, 0xFF, 0xFF );
//Initialize PNG loading
int imgFlags = IMG_INIT_PNG;
if( !( IMG_Init( imgFlags ) & imgFlags ) )
{
printf( "SDL_image could not initialize! SDL_mage Error: %s\n", IMG_GetError() );
this->m_quit = true;
}
//Initialize SDL_ttf
if( TTF_Init() == -1 )
{
printf( "SDL_ttf could not initialize! SDL_ttf Error: %s\n", TTF_GetError() );
this->m_quit = true;
}
}
}
}
this->m_mainEvent = new SDL_Event();
this->m_max_num_balls_per_row = (SCREEN_WIDTH/BALL_INIT_WIDTH)/2;
this->m_ball_image_init_width = BALL_INIT_IMAGE_WIDTH/2; //la largeur de balle propre à l'image initiale, avant changement de diamètre initial
this->m_compteur_collisions = 0;
this->m_ball_manager1 = new BallManager(this->m_array_balls, this->m_array_spriteBallsClips, BALL_INIT_NUM, BALL_INIT_MIN_VELOCITY, BALL_INIT_MAX_VELOCITY);
} |
Partager