00001 #ifndef _BREAKOUTPADDLE_H_
00002 #define _BREAKOUTPADDLE_H_
00003
00004 #include "Vector2.h"
00005 #include "AABB.h"
00006
00007 #include "BreakoutBox.h"
00008 #include "BreakoutWorldBoundaries.h"
00009 #include "Visualisation.h"
00010
00011 class BreakoutPaddle : public BreakoutBox
00012 {
00013 public:
00014 BreakoutPaddle(const Vector2i &pos, const Vector2i &boxSize, const ColourRGB &innerColour, const ColourRGB &outerColour)
00015 : BreakoutBox(), m_bBallAttached(false), m_pBallAttached(0)
00016 {
00017 m_position = pos; m_size = boxSize; updateBBox();
00018 m_sprID = Visualisation::getSingleton()->CreateSpriteBox(boxSize.x, boxSize.y, outerColour, innerColour);
00019 }
00020
00021 virtual void Draw()
00022 {
00023 if(m_bIsEnabled)
00024 {
00025 Visualisation::getSingleton()->DrawSprite(m_sprID, m_position.x, m_position.y);
00026 }
00027 }
00028 virtual void Update()
00029 {
00030 this->SetPosition(m_position + m_velocity);
00031 if(m_bBallAttached)
00032 {
00033 m_pBallAttached->SetPosition(m_position + m_ballOffset);
00034 }
00035 }
00036
00037 bool HandleCollisionWithWorldBoundaries(BreakoutWorldBoundaries* pBounds)
00038 {
00039 Vector2i minBounds = pBounds->GetMinBounds();
00040 Vector2i maxBounds = pBounds->GetMaxBounds();
00041
00042 if(m_boundingBox.Right > maxBounds.x)
00043 {
00044 int xDiff = m_boundingBox.Right - maxBounds.x;
00045 m_position.x -= xDiff;
00046 updateBBox();
00047 return true;
00048 }
00049
00050 if(m_boundingBox.Left < minBounds.x)
00051 {
00052 int xDiff = minBounds.x - m_boundingBox.Left;
00053 m_position.x += xDiff;
00054 updateBBox();
00055 return true;
00056 }
00057
00058 return false;
00059 }
00060
00061 void AttachBallToPaddle(BreakoutBall* pBall)
00062 {
00063 m_pBallAttached = pBall;
00064 m_bBallAttached = true;
00065
00066 m_pBallAttached->SetVelocity(Vector2i(0,0));
00067 m_ballOffset.x = (m_size.x / 2) - (pBall->GetRadius() / 2);
00068 m_ballOffset.y = -pBall->GetRadius() - 2;
00069
00070 m_pBallAttached->SetPosition(m_position + m_ballOffset);
00071 }
00072
00073 void DetachBallFromPaddle()
00074 {
00075 m_pBallAttached = 0;
00076 m_bBallAttached = false;
00077 }
00078
00079 bool IsBallAttached() { return m_bBallAttached; }
00080
00081 Vector2i GetVelocity() { return m_velocity; }
00082 void SetVelocity(const Vector2i &vel) { m_velocity = vel; }
00083 void AddToVelocity(const Vector2i &vec) { m_velocity += vec; }
00084
00085 protected:
00086 SpriteID m_sprID;
00087 Vector2i m_velocity, m_ballOffset;
00088 bool m_bBallAttached;
00089 BreakoutBall* m_pBallAttached;
00090 };
00091
00092
00093 #endif