1 /************************************************************************
2  *                                                                      *
3  *  FreeSynd - a remake of the classic Bullfrog game "Syndicate".       *
4  *                                                                      *
5  *   Copyright (C) 2005  Stuart Binge  <skbinge@gmail.com>              *
6  *   Copyright (C) 2005  Joost Peters  <joostp@users.sourceforge.net>   *
7  *   Copyright (C) 2006  Trent Waddington <qg@biodome.org>              *
8  *                                                                      *
9  *    This program is free software;  you can redistribute it and / or  *
10  *  modify it  under the  terms of the  GNU General  Public License as  *
11  *  published by the Free Software Foundation; either version 2 of the  *
12  *  License, or (at your option) any later version.                     *
13  *                                                                      *
14  *    This program is  distributed in the hope that it will be useful,  *
15  *  but WITHOUT  ANY WARRANTY;  without even  the implied  warranty of  *
16  *  MERCHANTABILITY  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  *
17  *  General Public License for more details.                            *
18  *                                                                      *
19  *    You can view the GNU  General Public License, online, at the GNU  *
20  *  project's  web  site;  see <http://www.gnu.org/licenses/gpl.html>.  *
21  *  The full text of the license is also included in the file COPYING.  *
22  *                                                                      *
23  ************************************************************************/
24 
25 #ifndef SPRITEMANAGER_H
26 #define SPRITEMANAGER_H
27 
28 #include "sprite.h"
29 #include <vector>
30 
31 /*!
32  * Sprite manager class.
33  */
34 class SpriteManager {
35 public:
36     SpriteManager();
37     virtual ~SpriteManager();
38 
39     void clear();
40 
loaded()41     bool loaded() { return sprite_count_ != 0; }
spriteCount()42     int spriteCount() { return sprite_count_; }
43 
44     bool loadSprites(uint8 * tabData, int tabSize, uint8 *spriteData,
45             bool rle = false);
46     Sprite *sprite(int spriteNum);
47     bool drawSpriteXYZ(int spriteNum, int x, int y, int z, bool flipped = false,
48             bool x2 = false);
49 
50 protected:
51     Sprite *sprites_;
52     int sprite_count_;
53 };
54 
55 /*!
56  * Game sprite frame class.
57  */
58 class GameSpriteFrame {
59 public:
GameSpriteFrame()60     GameSpriteFrame() : first_element_(0), width_(0), height_(0), flags_(0),
61             next_frame_(0) {}
62     int first_element_;
63     int width_, height_;
64     int flags_;
65     int next_frame_;
66 };
67 
68 /*!
69  * Game sprite frame element class.
70  */
71 class GameSpriteFrameElement {
72 public:
GameSpriteFrameElement()73     GameSpriteFrameElement() : sprite_(0), off_x_(0), off_y_(0),
74             flipped_(false), next_element_(0) {}
75     int sprite_;
76     int off_x_, off_y_;
77     bool flipped_;
78     int next_element_;
79 };
80 
81 /*!
82  * Game sprite class.
83  */
84 class GameSpriteManager : public SpriteManager {
85 public:
86     GameSpriteManager();
87     virtual ~GameSpriteManager();
88 
89     void load();
90 
numAnims()91     int numAnims() { return (int) index_.size(); }
92 
93     bool drawFrame(int animNum, int frameNum, int x, int y);
94     bool lastFrame(int animNum, int frameNum);
95     int lastFrame(int animNum);
96     int getFrameFromFrameIndx(int frameIndx);
97     int getFrameNum(int animNum);
98 
99 protected:
100     std::vector<int> index_;
101     std::vector<GameSpriteFrame> frames_;
102     std::vector<GameSpriteFrameElement> elements_;
103 };
104 
105 #endif
106