- Main Page
- Classes
- Files

- File List
- File Members

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

Go to the documentation of this file.

    00001
    00006 #include "BreakoutBox.h"
    00007
    00008 #include "BreakoutApp.h"
    00009 #include "Visualisation.h"
    00010
    00011 #include "Vector2.h"
    00012 #include "AABB.h"
    00013
    00014 #include "GameConfig.h"
    00015 #include "SDL.h"
    00016
    00017 BreakoutBox::BreakoutBox()
    00018 : m_bIsEnabled(true), m_health(0), m_bIsAlive(true), m_lastHitTime(0)
    00019 {
    00020
    00021 }
    00022
    00023 BreakoutBox::BreakoutBox(const Vector2i &pos, const Vector2i &size, const unsigned int &health)
    00024 : m_bIsEnabled(true), m_health(health), m_position(pos), m_size(size), m_bIsAlive(true), m_lastHitTime(0)
    00025 {
    00026         updateBBox();
    00027 }
    00028
    00029 BreakoutBox::~BreakoutBox()
    00030 {
    00031 }
    00032
    00033 void BreakoutBox::Draw()
    00034 {
    00035         if(m_bIsEnabled)
    00036         {
    00037                 SpriteID sprID = BreakoutApp::getSingleton()->GetBoxSpriteFromHealth(m_health);
    00038                 Visualisation::getSingleton()->DrawSprite(sprID, m_position.x, m_position.y);
    00039         }
    00040 }
    00041
    00042 void BreakoutBox::updateBBox()
    00043 {
    00044 //      m_boundingBox.Left = m_position.x - (m_size.x / 2);
    00045 //      m_boundingBox.Right = m_boundingBox.Left + m_size.x;
    00046 //      m_boundingBox.Bottom = m_position.y - (m_size.y / 2);
    00047 //      m_boundingBox.Top = m_boundingBox.Bottom + m_size.y;
    00048
    00049         m_boundingBox.Left = m_position.x;
    00050         m_boundingBox.Right = m_boundingBox.Left + m_size.x;
    00051         m_boundingBox.Bottom = m_position.y;
    00052         m_boundingBox.Top = m_boundingBox.Bottom + m_size.y;
    00053 }
    00054
    00055 void BreakoutBox::TakeHit()
    00056 {
    00057         //Protection against issue where block was hit twice by the same collision.
    00058         if(m_lastHitTime + BOX_MIN_TIME_BETWEEN_HITS > SDL_GetTicks())
    00059                 return;
    00060
    00061         m_health--;
    00062         m_lastHitTime = SDL_GetTicks();
    00063         if(m_health <= 0)
    00064                 m_bIsAlive = false;
    00065 }