- Main Page
- Classes
- Files

- File List
- File Members

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

Go to the documentation of this file.

    00001 #include "BreakoutScoreCounter.h"
    00002
    00003 #include "GameConfig.h"
    00004 #include <deque>
    00005 #include <cstdlib>
    00006 #include <cstdio>
    00007
    00008 BreakoutScoreCounter::BreakoutScoreCounter(const Vector2i &pos,  const ColourRGB &colour, int val /* = 0 */)
    00009 : m_position(pos), m_value(val)
    00010 {
    00011         for(int i = 0; i < 10; i++)
    00012         {
    00013                 char buffer[2]; //Single digit and null terminator \0
    00014                 //itoa(i, buffer, 10);
    00015 #ifdef _WIN32
    00016                 sprintf_s(buffer, 2, "%d", i);
    00017 #else
    00018                 sprintf(buffer, "%d", i);  // GP2X compatible
    00019 #endif
    00020
    00021                 m_digits[i] = Visualisation::getSingleton()->CreateSpriteText(buffer, colour);
    00022         }
    00023 }
    00024
    00025 BreakoutScoreCounter::~BreakoutScoreCounter()
    00026 {
    00027         for(int i = 0; i < 10; i++)
    00028                 Visualisation::getSingleton()->RemoveSprite(m_digits[i]);
    00029 }
    00030
    00031 void BreakoutScoreCounter::Update(const int &val)
    00032 {
    00033         m_value = val;
    00034 }
    00035
    00036 void BreakoutScoreCounter::Draw()
    00037 {
    00038         std::deque<int> vIndividualDigits;
    00039         vIndividualDigits.push_front(m_value % 10);
    00040         int divider = 10;
    00041         int result = m_value / divider;
    00042         while(result >= 10)
    00043         {
    00044                 vIndividualDigits.push_front(result % 10);
    00045
    00046                 divider *= 10;
    00047                 result = m_value / divider;
    00048         }
    00049
    00050         vIndividualDigits.push_front(result);
    00051
    00052         Visualisation* pVis = Visualisation::getSingleton();
    00053         Vector2i currPos = m_position;
    00054         for(size_t i = 0; i < vIndividualDigits.size(); i++)
    00055         {
    00056                 pVis->DrawSprite(m_digits[vIndividualDigits[i]], currPos.x, currPos.y);
    00057                 currPos.x += CHARACTER_WIDTH;
    00058         }
    00059 }