#include "cBall.hpp" using Equipment::cBall; cBall::cBall( const signed long int xpos /*= 0*/, const signed long int ypos /*= 0*/, const signed long int xarea /*= 0*/, const signed long int yarea /*= 0*/, const unsigned long int warea /*= 0*/, const unsigned long int harea /*= 0*/, VideoEngine::cImage** image /*= nullptr*/, VideoEngine::cCamera** camera /*= nullptr*/ ) : cSprite(xpos, ypos, xarea, yarea, warea, harea, image, camera), m_pause(false), m_ballState(Serve), m_speed(-10.0, -10.0), m_maxSpeed(10), m_minSpeed(5), m_boucedAllReady(false) {} cBall::~cBall() {} ///Functions void cBall::Move() { if (m_pause == false) { float frameTime = TimingEngine::cTiming::Inst().getFrameTime(); AddPosX(long int(m_speed.x * frameTime)); AddPosY(long int(m_speed.y * frameTime)); m_boucedAllReady = false; } } const bool cBall::isPaused() { return m_pause; } void cBall::Pause() { m_pause = !m_pause; } void cBall::BounceX() { float rand = MathEngine::cRandom::Inst().Rand(m_maxSpeed, m_minSpeed); m_speed.x = -m_speed.x; m_speed.y = rand; AddPosX((long)m_speed.x); } void cBall::BounceY() { float rand = MathEngine::cRandom::Inst().Rand(m_maxSpeed, m_minSpeed); m_speed.x = rand; m_speed.y = -m_speed.y; AddPosY((long)m_speed.y); } void cBall::Reset( const int delay ) { delay; m_ballState = Serve; } ///Sets void cBall::setSpeed( const float x /*= -10*/, const float y /*= -10*/ ) { m_speed.x = x; m_speed.y = y; } void cBall::setMaxSpeed( const float max /*= 10*/ ) { m_maxSpeed = max; } void cBall::setMinSpeed( const float min /*= 5*/ ) { m_minSpeed = min; } ///Gets const MathEngine::Vector2 cBall::getSpeed() const { return m_speed; } const float cBall::getMaxSpeed() const { return m_maxSpeed; } const float cBall::getMinSpeed() const { return m_minSpeed; }