Hi, I have this class called panel and a class that manages this class called panel manager.
A panel can have a color, a type, and a size this is set by using the randomize function which calls protected functions in the panel class.
The functions used to determine the type of block is shown below.
The numbers in the returnColour class are used for returning the image of the block that should be used.
void panelManager::setActive(int i, bool active)
{
gamePanel.Randomize();
gamePanel.setActive(active);
}
void panelManager::Randomize(TextureManager *textureM)
{
for (int i = 0; i < MAX_PANELS; i++)
{
gamePanel.Randomize();
gamePanel.setTextureManager(&textureM[gamePanel.ReturnColour()]);
}
}
//=============================================================================
// Non-protected function for outside user for randomizing the block when the
// game is finished. Function will call set size, set type then set colour to
// provide the block with a random image.
//=============================================================================
void Panel::Randomize()
{
countdown = rand() % 60 + 1;
setSize();
setType();
setColour();
switch(rand() % 2 + 1)
{
case 1: active = true;
break;
case 2: active = false;
break;
};
}
//=============================================================================
// Protected function for setting the size of the rectangle, a block can either
// be small or large.
//=============================================================================
void Panel::setSize()
{
switch(rand() % 2 + 1)
{
case 1: size = panelNS::SMALL; // Block is small
height = 57;
spriteData.height = height; // Size of the panel
spriteData.rect.bottom = height; // Size of the panel
break;
case 2: size = panelNS::LARGE; // Block is large
height = 74;
spriteData.height = height; // Size of the panel
spriteData.rect.bottom = height; // Size of the panel
break;
}
}
//=============================================================================
// Protected function for setting the type of block
//=============================================================================
void Panel::setType()
{
switch(rand() % 6 + 1)
{
case 1: type = panelNS::NORMAL; // Standard Point Block
break;
case 2: type = panelNS::DEATH; // -100 Points Block
break;
case 3: type = panelNS::DOUBLE; // *2 Points
break;
case 4: type = panelNS::SLOW; // Slow the opponent down
break;
case 5: type = panelNS::SPEED; // Speed the player up
break;
case 6: type = panelNS::SUPER; // Add the friend player
break;
}
}
//=============================================================================
// Protected function for setting the colour of the block
//=============================================================================
void Panel::setColour()
{
if (type == panelNS::NORMAL) // If the panel is a normal type
{ // Give it a normal colour
switch(rand() % 6 + 1)
{
case 1: colour = panelNS::PINK;
break;
case 2: colour = panelNS::YELLOW;
break;
case 3: colour = panelNS::GREEN;
break;
case 4: colour = panelNS::BLUE;
break;
case 5: colour = panelNS::RED;
break;
case 6: colour = panelNS::PURPLE;
break;
}
}
else // Otherwise its a powerup block so give it
{ // a powerup colour
colour = panelNS::POWERUP;
}
}
//=============================================================================
// Panel Return Colour, Usies the size colour and type to return the number
// ID of the correct block
//=============================================================================
int Panel::ReturnColour()
{
switch(size)
{
case panelNS::SMALL: switch(colour)
{
case panelNS::POWERUP: switch(type)
{
case panelNS::DEATH: return 0;
break;
case panelNS::DOUBLE: return 2;
break;
case panelNS::SLOW: return 4;
break;
case panelNS::SPEED: return 6;
break;
case panelNS::SUPER: return 8;
break;
}
break;
case panelNS::PINK: return 10;
break;
case panelNS::YELLOW: return 12;
break;
case panelNS::GREEN: return 14;
break;
case panelNS::BLUE: return 16;
break;
case panelNS::RED: return 18;
break;
case panelNS::PURPLE: return 20;
break;
}
break;
case panelNS::LARGE: switch(colour)
{
case panelNS::POWERUP: switch(type)
{
case panelNS::DEATH: return 1;
break;
case panelNS::DOUBLE: return 3;
break;
case panelNS::SLOW: return 5;
break;
case panelNS::SPEED: return 7;
break;
case panelNS::SUPER: return 9;
break;
}
break;
case panelNS::PINK: return 11;
break;
case panelNS::YELLOW: return 13;
break;
case panelNS::GREEN: return 15;
break;
case panelNS::BLUE: return 17;
break;
case panelNS::RED: return 19;
break;
case panelNS::PURPLE: return 21;
break;
}
break;
}
}

0 & Evens = Small block, Odds = Large Blocks
So, during the game when I'm checking for collisions If a collision has occurred I return the block type and perform the correct action, for example a death block = score - 100 and so on. But somewhere, something is going wrong and the block types are getting messed up, for example the large blue block should have the normal type but will somehow become a super block and im very uynsure how.
This is shown on a video I uploaded of my progress at the time 34/35 where the opponent hits a normal colour block.
The code that I'm using for checking for collisions is this.
//=============================================================================
// Handle collisions
//=============================================================================
void CreateThis::collisions()
{
VECTOR2 collisionVector;
if(gameBall.collidesWith(player, collisionVector))
{
gameBall.bounce(collisionVector,player);
activehit = 1;
}
if(gameBall.collidesWith(opponent, collisionVector))
{
gameBall.bounce(collisionVector,opponent);
activehit = 2;
}
if(gameBall.collidesWith(friendpower, collisionVector))
{
gameBall.bounce(collisionVector,opponent);
activehit = 0;
}
for (int i = 0; i < MAX_PANELS; i++)
{
if(gameBall.collidesWith(gamePanels.ReturnPanel(i), collisionVector))
{
gameBall.bounce(collisionVector,gamePanels.ReturnPanel(i));
gamePanels.setActive(i,false);
if (gamePanels.ReturnType(i) == "Death")
{
switch(activehit)
{
case 1: player.UpdateScore(-100);
break;
case 2: opponent.UpdateScore(-100);
break;
}
}
else if (gamePanels.ReturnType(i) == "Super")
{
switch(activehit)
{
case 1: if (!friendpower.getActive())
{
friendpower.setCenteredPosition(156,GAME_HEIGHT/2);
friendpower.setActive(true);
friendpower.setTextureManager(&paddleTexture[8]);
}
break;
case 2: if (!friendpower.getActive())
{
friendpower.setCenteredPosition(GAME_WIDTH-156,GAME_HEIGHT/2);
friendpower.setActive(true);
friendpower.setTextureManager(&paddleTexture[7]);
}
break;
}
}
}
}
}
Entity panelManager::ReturnPanel(int i)
{
return gamePanel;
}
std::string panelManager::ReturnType(int i)
{
switch(gamePanel.GetType())
{
case 0: return "Normal";
break;
case 1: return "Death";
break;
case 2: return "Double";
break;
case 3: return "Slow";
break;
case 4: return "Speed";
break;
case 5: return "Super";
break;
}
}
I'm very unsure as to where I am going wrong and would really appreciate some help in finding out where.. I'm hosting this on my dropbox for accessing it in different places if you wanna have a look to possibly help me fix this feel free to. If you go to compile the game it requires the june 2010 directX sdk.