- Main Page
- Classes
- Files

- File List
- File Members

# C:/Users/Public/AGS Final Folder/BFLETCHER D4010283/Source/Game/Source/BoxSprite.cpp

Go to the documentation of this file.

    00001 #include "BoxSprite.h"
    00002
    00003 #include "SDL.h"
    00004 #include "Visualisation.h"
    00005 #include "GameException.h"
    00006
    00007 BoxSprite::BoxSprite(const SpriteID &id, const unsigned int &w, const unsigned int &h, const ColourRGB &borderColour, const ColourRGB &fillColour, unsigned int borderSize /* = 1 */)
    00008 : Sprite(id)
    00009 {
    00010         m_numFrames = 1; //Only one frame for procedural boxes so far, animation could be added later.
    00011         SDL_Surface* pScreen = Visualisation::getSingleton()->GetScreen();
    00012         m_pFrames = SDL_CreateRGBSurface(SDL_HWSURFACE, w, h, pScreen->format->BitsPerPixel, pScreen->format->Rmask, pScreen->format->Gmask, pScreen->format->Bmask, pScreen->format->Amask);
    00013
    00014         if(!m_pFrames)
    00015         {
    00016                 throw GameException(eMajorError, "BoxSprite: Constructor failed due to failed SDL_CreateRGBSurface() call.");
    00017                 return;
    00018         }
    00019
    00020         for(size_t x = 0; x < w; x++)
    00021         {
    00022                 for(size_t y = 0; y < h; y++)
    00023                 {
    00024                         if(x < borderSize || x > w - borderSize || y < borderSize || y > h - borderSize)
    00025                                 WritePixel(m_pFrames, x, y, borderColour);
    00026                         else
    00027                                 WritePixel(m_pFrames, x, y, fillColour);
    00028                 }
    00029         }
    00030 }