show function:
void Player::show()
{
//sprites loaded
int rcurrentFrame = -1;
int lcurrentFrame = -1;
int currentClip = 0;
int currentMultiplication = 0;
switch(currentShape)
{
case 1:
cout<<"case 1";
rightFrameAmount = 28;
leftFrameAmount = 28;
CHARACTER_WIDTH = 128;
CHARACTER_HEIGHT = 128;
player_image = load_image("nwalkspritesheet.png");
break;
case 2:
cout<<"case 2";
rightFrameAmount = 32;
leftFrameAmount = 32;
CHARACTER_WIDTH = 128;
CHARACTER_HEIGHT = 132;
player_image = load_image("mwalkspritesheet.png");
break;
case 3:
break;
}
if(player_image == NULL)
{
cout<<"it's nothing";
}
for(int i = 0; i < rightFrameAmount; i++)
{
rcurrentFrame ++;
clipsRight[rcurrentFrame].x = CHARACTER_WIDTH * i;
clipsRight[rcurrentFrame].y = 0;
clipsRight[rcurrentFrame].w = CHARACTER_WIDTH;
clipsRight[rcurrentFrame].h = CHARACTER_HEIGHT;
}
for(int j = 0; j < leftFrameAmount; j++)
{
lcurrentFrame ++;
clipsLeft[lcurrentFrame].x = CHARACTER_WIDTH * j;
clipsLeft[lcurrentFrame].y = CHARACTER_HEIGHT;
clipsLeft[lcurrentFrame].w = CHARACTER_WIDTH;
clipsLeft[lcurrentFrame].h = CHARACTER_HEIGHT;
}
//If left
if( xvelocity < 0 )
{
//left
status = CHARACTER_LEFT;
//Move to the next frame in the animation
frame++;
}
//If right
else if( xvelocity > 0 )
{
//right
status = CHARACTER_RIGHT;
//Move to the next frame in the animation
frame++;
}
//If standing
else
{
//Restart animation
frame = 0;
}
//Loop animation
if( frame >= rightFrameAmount )
{
frame = 0;
}
//Direction
if( status == CHARACTER_RIGHT )
{
apply_surface( character.x, character.y, player_image, screen, &clipsRight[ frame ] );
}
else if( status == CHARACTER_LEFT )
{
apply_surface( character.x, character.y, player_image, screen, &clipsLeft[ frame ] );
}
}
gameloop:
while( quit == false )
{
fps.start();
while( SDL_PollEvent( &event ) )
{
walk.handle_events();
if( event.type == SDL_QUIT )
{
quit = true;
}
}
walk.move();
SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0xFF, 0xFF, 0xFF ) );
SDL_FillRect( screen, &wall, SDL_MapRGB( screen->format, 0x77, 0x77, 0x77 ) );
walk.show();
if( SDL_Flip( screen ) == -1 )
{
return 1;
}
if( fps.get_ticks() < 1000 / FRAMES_PER_SECOND )
{
SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() );
}
}