sprite.h

00001 /***************************************************************************
00002  *   Copyright (C) 2007 by Mike Polan                                      *
00003  *   kanadakid@gmail.com                                                   *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 // sprite.h: the Sprite class
00021 
00022 #ifndef SPRITE_H
00023 #define SPRITE_H
00024 
00025 #include <iostream>
00026 #include <map>
00027 #include <vector>
00028 #include "SDL.h"
00029 
00034 struct _Frame {
00036         int time;
00037         
00039         ustring sfx;
00040         
00042         SDL_Surface *image;
00043 };
00044 typedef struct _Frame Frame;
00045 
00050 struct _Animation {
00052         ustring id;
00053         
00055         bool loop;
00056         
00058         std::vector<Frame> frames;
00059 };
00060 typedef struct _Animation Animation;
00061 
00062 typedef std::map<ustring, Animation> AnimationMap;
00063 typedef std::map<ustring, Animation>::iterator AnimationMapIter;
00064 
00072 class Sprite {
00073         public:
00075                 Sprite();
00076                 
00080                 void toggleLoop(bool b);
00081                 
00085                 bool loop();
00086                 
00090                 bool done();
00091                 
00095                 void setAnimation(const ustring &anim);
00096                 
00102                 void animate(int x, int y, SDL_Surface *dest=SDL_GetVideoSurface());
00103                 
00108                 void renderFrame(const Point &p, int frame=0);
00109                 
00113                 void addAnimation(const Animation &anim) { m_Animations[anim.id]=anim; }
00114                 
00118                 ustring getCurrentAnimationId() const { return m_CurAnim; }
00119                 
00124                 Animation* getAnimation(const ustring &id);
00125                 
00129                 AnimationMap getAnimations() const { return m_Animations; }
00130                 
00134                 Frame* getCurrentFrame();
00135                 
00139                 int numAnimations() const { return m_Animations.size(); }
00140                 
00146                 void addFrame(const ustring &id, int time, SDL_Surface *frame);
00147                 
00149                 void reset();
00150                 
00151         private:
00152                 // the current frame and animation
00153                 ustring m_CurAnim;
00154                 int m_CurFrame;
00155                 int m_LastFrame;
00156                 
00158                 AnimationMap m_Animations;
00159 };
00160 
00161 #endif
00162 

Generated on Fri Feb 22 22:29:23 2008 for Phoenix Wright Case Player API by  doxygen 1.5.3