summaryrefslogtreecommitdiff
path: root/noncore/games/sfcave-sdl/animatedimage.cpp
authorandyq <andyq>2003-01-20 23:11:56 (UTC)
committer andyq <andyq>2003-01-20 23:11:56 (UTC)
commit92419b025aa5d82bb7592281af5505ff931c2e58 (patch) (unidiff)
tree374ee9ca86ef716ce388c8a28e38261f6a04ce7a /noncore/games/sfcave-sdl/animatedimage.cpp
parent02090d2e63ad8398c0a8a9f1fb895a9c6e42514b (diff)
downloadopie-92419b025aa5d82bb7592281af5505ff931c2e58.zip
opie-92419b025aa5d82bb7592281af5505ff931c2e58.tar.gz
opie-92419b025aa5d82bb7592281af5505ff931c2e58.tar.bz2
Initial Revision
Diffstat (limited to 'noncore/games/sfcave-sdl/animatedimage.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/games/sfcave-sdl/animatedimage.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/noncore/games/sfcave-sdl/animatedimage.cpp b/noncore/games/sfcave-sdl/animatedimage.cpp
new file mode 100644
index 0000000..d9d6ff6
--- a/dev/null
+++ b/noncore/games/sfcave-sdl/animatedimage.cpp
@@ -0,0 +1,68 @@
1#include "SDL.h"
2#include "SDL_image.h"
3
4#include "constants.h"
5#include "animatedimage.h"
6
7AnimatedImage :: AnimatedImage( QString file, int nFrames )
8{
9 nrFrames = nFrames;
10 currentFrame = 0;
11
12 // Load image
13 image = IMG_Load( (const char *)file.c_str() );
14 if ( !image )
15 {
16 nrFrames = 0;
17 image = 0;
18 return;
19 }
20
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;
26 frameHeight = image->h;
27}
28
29AnimatedImage :: ~AnimatedImage()
30{
31 if ( image != 0 )
32 SDL_FreeSurface( image );
33}
34
35bool AnimatedImage :: nextFrame()
36{
37 bool rc = true;
38 currentFrame ++;
39 if ( currentFrame >= nrFrames )
40 {
41 currentFrame --;
42 rc = false;
43 }
44
45 return rc;
46}
47
48void AnimatedImage :: draw( SDL_Surface *screen, int x, int y )
49{
50 SDL_Rect dst;
51 dst.x = currentFrame * frameWidth;
52 dst.y = 0;
53 dst.w = frameWidth;
54 dst.h = frameHeight;
55
56 SDL_Rect dst2;
57 dst2.x = x - (frameWidth/2);
58 dst2.y = y - (frameHeight/2);;
59 SDL_BlitSurface( image, &dst, screen, &dst2 );
60}
61
62bool AnimatedImage :: AtEnd()
63{
64 if ( currentFrame +1 >= nrFrames || image == 0 )
65 return true;
66 return false;
67}
68