summaryrefslogtreecommitdiff
path: root/noncore/games/sfcave-sdl/animatedimage.cpp
Unidiff
Diffstat (limited to 'noncore/games/sfcave-sdl/animatedimage.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/games/sfcave-sdl/animatedimage.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/noncore/games/sfcave-sdl/animatedimage.cpp b/noncore/games/sfcave-sdl/animatedimage.cpp
index d9d6ff6..441c647 100644
--- a/noncore/games/sfcave-sdl/animatedimage.cpp
+++ b/noncore/games/sfcave-sdl/animatedimage.cpp
@@ -1,36 +1,33 @@
1#include "SDL.h" 1#include "SDL.h"
2#include "SDL_image.h" 2#include "SDL_image.h"
3 3
4#include "constants.h" 4#include "constants.h"
5#include "animatedimage.h" 5#include "animatedimage.h"
6 6
7AnimatedImage :: AnimatedImage( QString file, int nFrames ) 7AnimatedImage :: AnimatedImage( string file, int nFrames )
8{ 8{
9 nrFrames = nFrames; 9 nrFrames = nFrames;
10 currentFrame = 0; 10 currentFrame = 0;
11 11
12 // Load image 12 // Load image
13 image = IMG_Load( (const char *)file.c_str() ); 13 image = IMG_Load( (const char *)file.c_str() );
14 if ( !image ) 14 if ( !image )
15 { 15 {
16 nrFrames = 0; 16 nrFrames = 0;
17 image = 0; 17 image = 0;
18 return; 18 return;
19 } 19 }
20 20
21 SDL_SetColorKey(image, SDL_SRCCOLORKEY | SDL_RLEACCEL, SDL_MapRGB( image->format, 0, 0, 0 ) ); 21 SDL_SetColorKey(image, SDL_SRCCOLORKEY | SDL_RLEACCEL, SDL_MapRGB( image->format, 0, 0, 0 ) );
22 //image = SDL_DisplayFormat( tmp );
23
24 //SDL_FreeSurface( tmp );
25 frameWidth = image->w/nrFrames; 22 frameWidth = image->w/nrFrames;
26 frameHeight = image->h; 23 frameHeight = image->h;
27} 24}
28 25
29AnimatedImage :: ~AnimatedImage() 26AnimatedImage :: ~AnimatedImage()
30{ 27{
31 if ( image != 0 ) 28 if ( image != 0 )
32 SDL_FreeSurface( image ); 29 SDL_FreeSurface( image );
33} 30}
34 31
35bool AnimatedImage :: nextFrame() 32bool AnimatedImage :: nextFrame()
36{ 33{
@@ -38,24 +35,27 @@ bool AnimatedImage :: nextFrame()
38 currentFrame ++; 35 currentFrame ++;
39 if ( currentFrame >= nrFrames ) 36 if ( currentFrame >= nrFrames )
40 { 37 {
41 currentFrame --; 38 currentFrame --;
42 rc = false; 39 rc = false;
43 } 40 }
44 41
45 return rc; 42 return rc;
46} 43}
47 44
48void AnimatedImage :: draw( SDL_Surface *screen, int x, int y ) 45void AnimatedImage :: draw( SDL_Surface *screen, int x, int y )
49{ 46{
47 if ( !image )
48 return;
49
50 SDL_Rect dst; 50 SDL_Rect dst;
51 dst.x = currentFrame * frameWidth; 51 dst.x = currentFrame * frameWidth;
52 dst.y = 0; 52 dst.y = 0;
53 dst.w = frameWidth; 53 dst.w = frameWidth;
54 dst.h = frameHeight; 54 dst.h = frameHeight;
55 55
56 SDL_Rect dst2; 56 SDL_Rect dst2;
57 dst2.x = x - (frameWidth/2); 57 dst2.x = x - (frameWidth/2);
58 dst2.y = y - (frameHeight/2);; 58 dst2.y = y - (frameHeight/2);;
59 SDL_BlitSurface( image, &dst, screen, &dst2 ); 59 SDL_BlitSurface( image, &dst, screen, &dst2 );
60} 60}
61 61