C:/DevKitPro/!MDuel/source/spriteManager.h

Go to the documentation of this file.
00001 /*
00002  * Marshmallow Duel DS v2
00003  * Copyright © 2007 Sam Pospischil http://pospi.spadgos.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 Free Software
00017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00018  */
00019 
00020 //resource management and allocation for sprites
00021 
00022 #ifndef _SPRITEMANAGER_H
00023 #define _SPRITEMANAGER_H
00024 
00025 #include <PA9.h>
00026 #include <vector>
00027 #include <string>
00028         using std::vector;
00029         using std::string;
00030 #include "macros.h"
00031 #ifndef _ALLGRAPHICS_
00032 #define _ALLGRAPHICS_
00033 #include "../data/all_gfx_ed.c"
00034 #endif
00035 
00036 //forward declaration
00037 class spriteObject;
00038 
00076 class spriteManager {
00077         public:
00084                 spriteManager(u8 newscreen = 0) : bActive(false), screen(newscreen), totalReset(false)
00085                 {
00086                         for (u8 i=0; i<128; ++i)
00087                                 sprites[i] = 0;
00088                         for (u8 i=0; i<16; ++i)
00089                                 palletes[i] = 0;
00090                         #ifdef __WITHSOUND
00091                         for (u8 i=0; i<8; ++i)
00092                                 soundLoopings[i] = false;
00093                         #endif
00094                 }
00099                 virtual ~spriteManager() {deactivate();}
00100                 
00106                 virtual void activate() {bActive = true; clearOutSprites();}
00110                 virtual void deactivate() {bActive = false; clearOutSprites();}
00112                 bool bActive;
00118                 virtual bool isActive() {return bActive;}
00119                 
00120                 virtual void gameTick();
00121                 
00122                 //background and text resetting
00123                 void resetBackground();         //reset only
00124                 void unloadBackground();        //delete properly
00125                 void resetText();                       //clear text
00126                 
00132                 struct spriteSet
00133                 {
00134                         s8 palleteID;
00135                         const unsigned short* palleteData;
00136                         const unsigned char* spriteData;
00137                 };
00138                 
00145                 struct bgSprite
00146                 {
00147                         const unsigned short* bg_Pal;
00148                         const unsigned char* bg_Map;
00149                         const unsigned char* bg_Tiles;          //for backgrounds
00150                 };
00151                 
00152                 bgSprite backGroundSprite;
00153                 
00154                 void loadSpriteSet(spriteSet* target, const unsigned short* p, const unsigned char* s);
00155                 bool spriteSetHasPallete(spriteSet *s);
00156                 void spriteSetLoadPallete(spriteSet *s);
00157                 
00158                 //create a sprite that plays an animation once, then destroys itself
00159                 void createSingleFireSprite(u8 palID, const unsigned char* gfx, vector<u8> frames, u8 ticksPerFrame, s16 nx = OFFX, s16 ny = OFFY, u8 objSize1 = 0, u8 objSize2 = 2, u8 cx = 16, u8 cy = 16, u8 minIndex = 0, u8 colorMode = 1);
00160                 void createSingleFireSprite(u8 palID, u16 gfxID, vector<u8> frames, u8 ticksPerFrame, s16 nx = OFFX, s16 ny = OFFY, u8 objSize1 = 0, u8 objSize2 = 2, u8 cx = 16, u8 cy = 16, u8 minIndex = 0, u8 colorMode = 1);
00161                 
00162                 s8 loadPallete(void* newpallete);
00163                 s8 loadSprite(const unsigned char* newSprite, u8 sizex, u8 sizey, u8 minIndex = 0, u8 palleteID = 0, s16 x = OFFX, s16 y = OFFY, u8 colorMode = 1);
00164                 void replaceSprite(u8 id, void* newSprite);
00165                 
00166                 void updateSpritePallete(u8 spriteID, u16 gfxID, u8 palleteID, u8 sizex, u8 sizey, u8 colorMode, u8 x, u8 y);
00167                 
00168                 void setAlpha(u8 transLevel);   //set alpha blending for this screen's SFX
00169                 
00170                 u16 loadGFX(const unsigned char* newGFX, u8 sizex, u8 sizey, u8 colorMode = 1);
00171                 s8 loadSpriteFromGFX(u16 GFXid, u8 sizex, u8 sizey, u8 palleteID = 0, u8 minIndex = 0, u8 colorMode = 1, s16 x = OFFX, s16 y = OFFY);
00172                 void updateSpriteGFX(s8 spriteID, void* GFXid);
00173                 
00174                 //deletes all gameSprite objects and frees their sprites
00175                 virtual void clearOutSprites(bool keepSound = false);
00176                 
00178                 vector<spriteObject*> gameSprites;
00179                 
00181                 u8 screen;
00182                 
00188                 bool isSprite(s8 index) const {return (index != -1 && sprites[index]);}
00192                 void removeSprite(s8 index) {if (index >= 0) sprites[index] = 0;}
00193                 
00194                 #ifdef __WITHSOUND
00195 
00199                 struct soundData
00200                 {
00201                         const u8* data;
00202                         const u32* size;
00203                 };
00212                 void loadSound(soundData* ref, const u8* data, const u32* size) {ref->data = data; ref->size = size;}
00213                 
00214                 s8 playSound(const u8* data, const u32* size, bool repeat = false, u8 vol = 127);
00215                 void stopSound(s8 channel);
00216                 bool soundLooping(s8 channel);
00217                 void soundTick();
00218                 #endif
00219                 
00225                 bool isResetting() const {return totalReset;}
00226         protected:              
00227                 s8 getNextPalleteID();
00228                 s8 getNextSpriteID(u8 minIndex = 0);
00229                 #ifdef __MDDEBUG
00230                 u8 getNumSpritesTaken() { u8 ret = 0; for (u8 i=0; i<128; ++i) ret+= sprites[i]; return ret; }
00231                 #endif
00232                 
00234                 u8 sprites[128];
00236                 u8 palletes[16];
00237                 
00239                 bool totalReset;
00240                 
00241                 #ifdef __WITHSOUND
00243                 bool soundLoopings[8];
00244                 #endif
00245 };
00246 
00247 #endif

Generated on Tue Mar 13 23:27:53 2007 for MDuel DS by  doxygen 1.5.1-p1