00001 #include "BackgroundSprite.h"
00002
00003 #include "SDL.h"
00004 #include "Visualisation.h"
00005
00006 #include "GameException.h"
00007
00008 BackgroundSprite::BackgroundSprite(const SpriteID &id, const unsigned int &w, const unsigned int &h, const unsigned int &numStars)
00009 : Sprite(id)
00010 {
00011 m_numFrames = 1;
00012 SDL_Surface* pScreen = Visualisation::getSingleton()->GetScreen();
00013 m_pFrames = SDL_CreateRGBSurface(SDL_HWSURFACE, w, h, pScreen->format->BitsPerPixel, pScreen->format->Rmask, pScreen->format->Gmask, pScreen->format->Bmask, pScreen->format->Amask);
00014
00015 if(!m_pFrames)
00016 {
00017 throw GameException(eMajorError, "BackgroundSprite: Constructor failed due to failed SDL_CreateRGBSurface() call.");
00018 return;
00019 }
00020
00021 if(SDL_MUSTLOCK(m_pFrames))
00022 SDL_LockSurface(m_pFrames);
00023
00024 for(size_t x = 0; x < w; x++)
00025 {
00026 for(size_t y = 0; y < h; y++)
00027 {
00028 WritePixel(m_pFrames, x, y, ColourRGB(1,1,1));
00029 }
00030 }
00031
00032 for(size_t i = 0; i < numStars; i++)
00033 {
00034 int x = rand() % w;
00035 int y = rand() % h;
00036 WritePixel(m_pFrames, x, y, ColourRGB(255,255,255));
00037 }
00038
00039 if(SDL_MUSTLOCK(m_pFrames))
00040 SDL_UnlockSurface(m_pFrames);
00041 }