Jump to content
  • Advertisement
Sign in to follow this  
TroyM88

level output problem....

This topic is 3319 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok so i've spent all day yesterday going over this and i just cant see anything wrong so im hoping someone on here can help... ok so im making breakout (the old brick smashing game) and the level i output doesnt draw correctly for some reason. i've messed with the x,y start position of the draw function yet that doesnt change the outcome... and i've completely run out of ideas as to what exactly it can be thats causing it. here is the output im getting image the red block is the ball the blue block is a brick and the orange is the paddle...
// This is the constructor, destructor, initialise & draw functions from my level cpp.

CLevel::CLevel()
:m_iBricksRemaining(0)
,m_pPaddle(0)
,m_pBall(0)
,m_iWidth(0)
,m_iHeight(0)
{

}

CLevel::~CLevel()
{
	while (m_vecBricks.size() > 0)
	{
		CBrick* pBrick = m_vecBricks[m_vecBricks.size() - 1];

		m_vecBricks.pop_back();

		delete pBrick;
	}

	delete m_pPaddle;
	m_pPaddle = 0;

	delete m_pBall;
	m_pBall = 0;
}

bool
CLevel::Initialise(int _iWidth, int _iHeight)
{
	m_iWidth = _iWidth;
	m_iHeight = _iHeight;

	const float fBallVelX = 200.0f;
	const float fBallVelY = 75.0f;

	m_pBall = new CBall();
	VALIDATE(m_pBall->Initialise(m_iWidth / 2.0f, m_iHeight / 2.0f,
fBallVelX, fBallVelY));

	m_pPaddle = new CPaddle();
	VALIDATE(m_pPaddle->Initialise());

	//Set the paddle's position to be centered on the x.
	// and a little bit up from the bottom of the window.
	m_pPaddle->SetX(_iWidth / 2.0f);
	m_pPaddle->SetY(_iHeight - (4 * m_pPaddle->GetHeight()));

	const int kiNumBricks = 36;
	const int kiStartX = 200;
	const int kiGap = 5;

	int iCurrentX = kiStartX;
	int iCurrentY = 800;

	for(int i = 0; i < kiNumBricks; ++i)
	{
		CBrick* pBrick = new CBrick();
		VALIDATE(pBrick->Initialise());

		pBrick->SetX(static_cast<float>(iCurrentX));
		pBrick->SetY(static_cast<float>(iCurrentY));

		iCurrentX += static_cast<int>(pBrick->GetWidth()) + kiGap;

		if (iCurrentX > _iWidth)
		{
			iCurrentX = kiStartX;
			iCurrentY += 200;
		}
		m_vecBricks.push_back(pBrick);
	}
	SetBricksRemaining(kiNumBricks);

	return(true);
}

void  
CLevel::Draw()
{
	for(unsigned int i = 0; i < m_vecBricks.size(); ++i)
	{
		m_vecBricks->Draw();
	}

	m_pPaddle->Draw();
	m_pBall->Draw();

	DrawScore();
}
i also have a few collision algorithms if they could be effecting how the level gets intialised but i dont think that could be it. so i've been pouring over the level.cpp and cant find anything, so im lost to exactly how to fix this problem... and help would be much appreciated!!..

Share this post


Link to post
Share on other sites
Advertisement
It's a shot in the dark but it could be that you are assuming your Y axis is one direction when in fact it's another direction completely.

For instance that you are assuming larger values of Y are higher on the screen and lower values of Y are lower on the screen when in fact it's the reverse.

Share this post


Link to post
Share on other sites
i see what you mean, which luckily i hadn't even noticed that the y starting position is meant to be 20, i think i might have changed it earlier and forgot about it....

but no that doesnt bring it off the top of the screen even adjusting the x axis isnt changing anything

Share this post


Link to post
Share on other sites
then the x and y variables must be set set to this position somewhere else in the code, can you show us the other code where you're setting/adjusting the x and y position?

Share this post


Link to post
Share on other sites

// These are my collision detection declarations.
// I have a few getX() & getY() function calls in here.


void
CLevel::Process(float _fDeltaTick)
{
void ProcessBallWallCollision();
void ProcessBallPaddleCollision();
void ProcessBallBrickCollision();

void ProcessCheckForWin();

void ProcessBallBounds();

for(unsigned int i = 0; i < m_vecBricks.size(); ++i)
{
m_vecBricks->Process(_fDeltaTick);
}
m_pPaddle->Process(_fDeltaTick);
m_pBall->Process(_fDeltaTick);

}

CPaddle*
CLevel::GetPaddle() const
{
return (m_pPaddle);
}

void CLevel::ProcessBallWallCollision()
{
float fBallX = m_pBall->GetX();
float fBallY = m_pBall->GetY();
float fBallW = m_pBall->GetWidth();
float fBallH = m_pBall->GetHeight();

float fHalfBallW = fBallW / 2;

if (fBallX < fHalfBallW)
{
m_pBall->SetVelocityX(m_pBall->GetVelocityX() * -1);
}

else if (fBallX > m_iWidth - fHalfBallW)
{
m_pBall->SetVelocityX(m_pBall->GetVelocityX() * -1);

}

if (fBallY < 0 )
{
m_pBall->SetVelocityY(m_pBall->GetVelocityY() * -1);

}

#ifdef CHEAT_BOUNCE_ON_BACK_WALL
if (fBallY > m_iHeight - fBallH)
{

m_pBall->SetVelocityX(m_pBall->GetVelocityX() * -1);
}
#endif //CHEAT_BOUNCE_ON_BACK_WALL
}

void
CLevel::ProcessBallPaddleCollision()
{
float fBallR = m_pBall->GetRadius();

float fBallX = m_pBall->GetX();
float fBallY = m_pBall->GetY();

float fPaddleX = m_pPaddle->GetX();
float fPaddleY = m_pPaddle->GetY();

float fPaddleW = m_pPaddle->GetWidth();
float fPaddleH = m_pPaddle->GetHeight();

if ((fBallX + fBallR > fPaddleX - fPaddleW / 2) &&
(fBallX - fBallR < fPaddleX + fPaddleW / 2) &&
(fBallX + fBallR > fPaddleY - fPaddleH / 2) &&
(fBallX - fBallR < fPaddleY + fPaddleH / 2))
{
m_pBall->SetY((fPaddleY - fPaddleH / 2) - fBallR);
m_pBall->SetVelocityY(m_pBall->GetVelocityY() * -1);

}

}

void
CLevel::ProcessBallBrickCollision()
{

for(unsigned int i = 0; i < m_vecBricks.size(); ++i)
{
if (!m_vecBricks->IsHit())
{
float fBallR = m_pBall->GetRadius();

float fBallX = m_pBall->GetX();
float fBallY = m_pBall->GetY();

float fBrickX = m_vecBricks->GetX();
float fBrickY = m_vecBricks->GetY();

float fBrickW = m_vecBricks->GetWidth();
float fBrickH = m_vecBricks->GetHeight();

if ((fBallX + fBallR > fBrickX - fBrickW / 2) &&
(fBallX - fBallR < fBrickX + fBrickW / 2) &&
(fBallX + fBallR > fBrickY - fBrickH / 2) &&
(fBallX - fBallR < fBrickY + fBrickH / 2))
{
//Hit the front side of the brick....
m_pBall->SetY((fBrickY + fBrickH / 2.0f) + fBallR);

m_pBall->SetVelocityY(m_pBall->GetVelocityY() * -1);

m_vecBricks->SetHit(true);

SetBricksRemaining(GetBricksRemaining() - 1);
}
}
}
}

void CLevel::ProcessCheckForWin()
{
for (unsigned int i = 0; i < m_vecBricks.size(); ++i)
{
if (!m_vecBricks->IsHit())
{
return;
}
}

CGame::GetInstance().GameOverWon();
}

void
CLevel::ProcessBallBounds()
{
if (m_pBall->GetX() < 0)
{
m_pBall->SetX(0);
}
else if (m_pBall->GetX() > m_iWidth)
{
m_pBall->SetX(static_cast<float>(m_iWidth));
}

if (m_pBall->GetY() < 0)
{
m_pBall->SetY(0.0f);
}

else if (m_pBall->GetY() > m_iHeight)
{
CGame::GetInstance().GameOverLost();
//m_pBall->SetY(m_iHeight);
}
}

//these definitions are in my entity.cpp
//entity.cpp

void
CEntity::SetX(float _f)
{
m_fX = _f;
}


void
CEntity::SetY(float _f)
{
m_fY = _f;
}




which i have the CLevel::intialise calling to set the starting positions of the bricks.. but as shown above i static_cast the iCurrentX & Y to SetX and Y.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!