• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
dynamiteandy

C++ Object Type Getting Messed Up?

0 posts in this topic

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.

 

http://www.youtube.com/watch?v=rB2lnPx8QKU&list=PLgHLc_A7MCxWnxBE8QLNEebXwCV86oGDn

 

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

Edited by Dynamite Andy
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0