Jump to content

  • Log In with Google      Sign In   
  • Create Account


Dynamite Andy

Member Since 15 Mar 2013
Offline Last Active May 09 2013 03:06 PM
-----

Topics I've Started

C++ Object Type Getting Messed Up?

06 May 2013 - 05:03 AM

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[i].Randomize();
    gamePanel[i].setActive(active);
}

void panelManager::Randomize(TextureManager *textureM)
{
    for (int i = 0; i < MAX_PANELS; i++)
    {
        gamePanel[i].Randomize();
        gamePanel[i].setTextureManager(&textureM[gamePanel[i].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;
	}

}

33m4l5i.png

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[i];
}

std::string panelManager::ReturnType(int i)
{
	switch(gamePanel[i].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.

 

https://www.dropbox.com/sh/6bsif5da5iaeoc9/UsFCs-zYdI


C++ - Passing array of textures through function

03 May 2013 - 03:04 AM

Hi, So in my game I've been working on all morning I've decided to create a class that will manage the multiple panels in my game.

 

Before this I was originally just making the panels in the game loop.

So anyways in my game.cpp file I have texture array which has all the textures for the panels.

 

TextureManager panelTexture[22];

Is what it is. This was initalised calling the function initalize with the following parameters, the panel had a variety of sizes and colours. hence the two functions inside of it.

if(!gamePanel.initialize(this,paddleNS::WIDTH,gamePanel.ReturnSize(),0,&panelTexture[gamePanel.ReturnColour()]))
		throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing player paddle"));

because i've now decided to use this manager class the function will now need to pass the panelTexture array to the panel manager class. Like so?

// Panelmanager.h
virtual bool initialize(Game *gamePtr, int width, int height, int ncols,
                            TextureManager *textureM[]);
// Panelmanager.cpp
bool panelManager::initialize(Game *gamePtr, int width, int height, int ncols,
                            TextureManager *textureM[])
{
    for (int i = 0; i < MAX_PANELS; i++)
    {
        gamePanel[i].initialize(gamePtr,panelNS::WIDTH,gamePanel[i].getHeight(),ncols,textureM[gamePanel[i].ReturnColour()]);
    }
}

So i am now able to call the panelmanager initalize function to initalize the game panels., however im having problems with this.

 

if(!gamePanels.initialize(this,0,0,0,&panelTexture))
		throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing player paddle"));

 

I cant seem the pass the array, when i try &panelTexture i get the following error

	1	IntelliSense: argument of type "TextureManager (*)[22]" is incompatible with parameter of type "TextureManager **"	

when i try &panelTexture[] i get this error

	1	IntelliSense: expected an expression

Basically I am stumped with errors at this bit, Could anyone advise on how to get past this?


Keeping functions in a game engine. Switching engines

17 April 2013 - 03:30 AM

Being developer's when a game engine doesn't have a function that we require, we build our own - such as returning certain things we may require,

However game engines tend to be updated regularly and when we move to a new version of that engine we lose the functions that we have built and incorporated into that engine.

I was just wondering how people managed to move from the old engine to a newer versions keeping their functions without having to constantly remake them?

C++ Function to center image?

05 April 2013 - 08:27 AM

Hey,
So i'm working with a game engine that was wrote by charles kelly for his book programming 2D games.

His engine is rather good, however positioning images is rather bad as it does it as x = left corner and y = top of image
I don't want to do the maths to center an image in the position x,y i'd much rather write a function for it..

there's already functions for getting the center x and center y.

 

however how would i go about writing a function so that it takes int x, int y and moves the image so that its center is x,y?

// Return center X.
    virtual float getCenterX()      {return spriteData.x + spriteData.width/2*getScale();}

    // Return center Y.
    virtual float getCenterY()      {return spriteData.y + spriteData.height/2*getScale();}

// getScale() incase needed
// Return scale factor.
    virtual float getScale()    {return spriteData.scale;}

14o6l9e.png

The image to above shows what im after..

red = current setting.

blue = what im after


Helping fix a few things.

15 March 2013 - 07:50 AM

Hey,

So I'm developing a game called PongBreakout in c++ using a game engine i got from uni (when i was there..)
I've got a few problems with my game that i'm struggling to fix and need some help to figure out how to do so.

the first bug is that the countdown is far to fast and i dont know how to slow it down - ive been told to use a scalar (not a clue what that is..) <- ball.cpp (Update())
the second bug is that the ball sometimes gets stuck at the side of the screen if the paddle is there (play it and you'll eventually notice it.) <- ball.ccp (ProcessCollisons())
the third bug is that the rand() function doesnt seem to be working for getting a value between 8 and 5. <- ball.cpp
And lastly the cpu paddle is very buggy movement wise, is there anyway to make it move a bit better instead of always juttering.. <- enemyboard.cpp

To run this game you need direct x aug 2009.

https://www.dropbox.com/sh/yykud3daabght8y/aejKK5bXFZ

http://www.microsoft.com/en-us/download/details.aspx?id=23549


Everything required is on on my dropbox.

PARTNERS