| 1 | /*************************************************************************** |
| 2 | sprite.cpp - description |
| 3 | ------------------- |
| 4 | begin : Thu Jan 17 2002 |
| 5 | copyright : (C) 2002 by Waldemar Baraldi |
| 6 | email : [email protected] |
| 7 | ***************************************************************************/ |
| 8 | |
| 9 | /*************************************************************************** |
| 10 | * * |
| 11 | * This program is free software; you can redistribute it and/or modify * |
| 12 | * it under the terms of the GNU General Public License as published by * |
| 13 | * the Free Software Foundation; either version 2 of the License, or * |
| 14 | * (at your option) any later version. * |
| 15 | * * |
| 16 | ***************************************************************************/ |
| 17 | |
| 18 | #include "sprite.h" |
| 19 | #include "list.h" |
| 20 | #include "surface.h" |
| 21 | #include "imagemanager.h" |
| 22 | |
| 23 | Sprite::Sprite(Str * filenamebase, Str * filenameext, int nFrames, ImageManager * im){ |
| 24 | frames = (Image**) malloc(nFrames*(sizeof(Image*))); |
| 25 | |
| 26 | this->n_frames=nFrames; |
| 27 | this->filenamebase=filenamebase; |
| 28 | this->filenameext=filenameext; |
| 29 | char aux[256]; |
| 30 | |
| 31 | for (int i=0;i<nFrames;i++){ |
| 32 | sprintf(aux, "%s%04i%s", filenamebase->get(), i, filenameext->get()); |
| 33 | frames[i]=im->getImage(new Str(aux)); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | Sprite::~Sprite(){ |
| 38 | delete frames; |
| 39 | if (filenamebase) delete filenamebase; |
| 40 | if (filenameext) delete filenameext; |
| 41 | } |
| 42 | |
| 43 | int Sprite::nFrames(){ |
| 44 | return n_frames; |
| 45 | } |
| 46 | |
| 47 | int Sprite::frameWidth(ImageManager * im){ |
| 48 | return frames[0]->width(); |
| 49 | } |
| 50 | |
| 51 | int Sprite::frameHeight(ImageManager * im){ |
| 52 | return frames[0]->height(); |
| 53 | } |
| 54 | |
| 55 | Surface * Sprite::frame(ImageManager * im, int n){ |
| 56 | return frames[n]; |
| 57 | } |