Pass a class object as a parameter? (C++/SDL)
Posted: Sat Jun 25, 2011 2:49 pm
Someone tried to explain this to me earlier and it didn't work out to well so if someone can show me how using my code I would like too,
Have a class object created in main, and have a function before main use its member functions.
Cake for the person that can!
Have a class object created in main, and have a function before main use its member functions.
Cake for the person that can!
Code: Select all
void option(const Card &card)
{
if (keystates[SDLK_LEFT])
{
apply_surface(0,0,Table,screen);
Card1.applyCard(100,280);
Card2.applyCard(140,280);
Card3.applyCard(420,50);
apply_surface(370,513,Border,screen);
spot = false;
}
else
if (keystates[SDLK_RIGHT])
{
apply_surface(0,0,Table,screen);
Card1.applyCard(100,280);
Card2.applyCard(140,280);
Card3.applyCard(420,50);
apply_surface(500,513,Border,screen);
spot = true;
}
else
if (keystates[SDLK_RETURN])
{
if (spot == false)
{
pos = false;
}
else
if (spot = true)
{
pos = true;
}
}
}
int main ( int argc, char *args[] )
{
srand(time(0));
bool quit = false;
if( init() == false ) { return 1;}
if( load_files() == false ) { return 2;}
apply_surface( 0,0,Table,screen);
apply_surface(370,513,Border,screen);
Card Card1;
Card Card2;
Card Card3;
Card1.applyCard(100,280);
Card2.applyCard(140,280);
Card3.applyCard(420,50);
while (quit == false)
{
while ( SDL_PollEvent( &event ) )
{
if( event.type == SDL_QUIT )
{
quit = true;
}
}
SDL_Flip( screen );
}
cleanup();
return 0;
}