Jump to content

  • Log In with Google      Sign In   
  • Create Account


bd36

Member Since 22 Feb 2012
Offline Last Active May 30 2012 05:42 PM
-----

Topics I've Started

Checkers Game Movement

22 April 2012 - 01:36 PM

I just finished creating a simple tower defense in SFML for a class and now I want to make a checkers game in SFML to learn some more c++ with the possibility of exploring some AI concepts or networking once I get a 2 player local game working first. I started to develop the game and so far the board is created and you can move a piece to an empty spot on the board. I just now started to try and add in the rules for valid moves. I have required forward diagonal moves but I am looking at it and seems like there has to be a better way than my current approach. Once jumps and stuff are involved it looks like it will get way out of hand.

Here is the code for a move
bool Board::move()
{
	if(movePiece1.getPiece() != getCurrentTurnPieceType())
	{
		printf("The Selected piece to move isnt yours.\n");
		pieceBeingMoved = false;
		return false;
	}
	if(movePiece2.getPiece() != GamePiece::NONE)
	{
		printf("The Selected new space isnt empty.\n");
		pieceBeingMoved = false;
		return false;
	}
	if(getCurrentTurnPieceType() == GamePiece::BLACK)
	{
		if(movePiece1.isKing() == false && movePiece2.getRow() <= movePiece1.getRow())
		{
			printf("must move forward\n");
			pieceBeingMoved = false;
			return false;
		}
	}
	else {
		if(movePiece1.isKing() == false && movePiece2.getRow() >= movePiece1.getRow())
		{
			printf("must move forward]\n");
			pieceBeingMoved = false;
			return false;
		}
	}
	if(movePiece1.getCol() == movePiece2.getCol())
	{
		printf("go diagonal not up\n");
		pieceBeingMoved = false;
		return false;
	}
	gamePieces[movePiece1.getRow()][movePiece1.getCol()].changePieceKind(GamePiece::NONE);
	gamePieces[movePiece2.getRow()][movePiece2.getCol()].changePieceKind(getCurrentTurnPieceType());
	blackTurn = !blackTurn;
	return true;
};

Does anyone have an suggestions for a better way to go about doing this. I also feel like the way I am getting the move isn't the best. Now the player clicks to get the space to move from and then clicks again to for the destination then the move is evaluated and the cells that are selected are stored as variables in the board object.

Thanks

Compiling SFML for Windows

14 April 2012 - 11:36 AM

I finished making my first attempt at a game. I did it using SFML2 in Xcode on my mac. I have been able to figure out how to create the application bundle for distribution. What I would like to know is it it possible to compile the program to run on windows as well? In my code I didn't use anything other than c++ classes, SFML classes and my own classes (No OSX APIs). I can't think of anything that would need to change between the platforms other than the SFML stuff. I know that on windows you need dlls and stuff rather than frameworks.

Is it possible for me to compile my application so that my friend can run it on his windows pc? I have access to bootcamp running windows 7 if needed. Thanks.

<vector> iterator access error

12 April 2012 - 11:36 AM

I am making a tower defense game and when I certain type of enemy is killed I am attempted to spawn two new enemies of a weaker type. However when I implemented this in my code I threw an access error. The code is below.

In the game loop:
//Loop through all the enemies currently active
	for (EnemyArray::iterator enemy = enemies.begin(); enemy != enemies.end();)
	{
		enemy->update(); //update the enemy
	  
		//check if the enemy has died and can be removed
		if (enemy->isDead())
			enemy = enemies.erase(enemy); //remove the enemy from the array. (dont increment the iterator b/c erase returns the next position automatically
		else
			++enemy; //move the iterator to the next enemy
	}

Then in the isDead function for the enemy i tried to do this
if(health <= 0) //was killed by the player's towers
	{
		playerMoney += valueWhenKilled; //get the money for killing the enemy
	  
		if(type == Black)//spawns 2 purples on death
		{
			enemies.push_back(Enemy(x,y,Purple));
			enemies.push_back(Enemy(x,y,Purple));
		}
	  
		return true; //enemy died
	}

I think that this has to do with the fact that I am adding to the vector than trying to use an iterator that was created before the addition to delete something afterwards. Although that is just my guess after playing with it for a little bit, I am still fairly new to c++. As soon as I remove the push_back() lines the codes works fine, just like it did before. I am not sure what I need to do in order to get this to work.

Any suggestions?

Targeting for shooting

24 March 2012 - 12:07 PM

Hello for my game I have a sprite that rotates to face a target. Currently the sprite rotates and follows the target as it should. However now I am trying to get the sprite to fire a bullet in the direction it is facing. Im fairly certain I have the right idea but am just missing something in the trigonometry.
int targetX, targetY;
		targetX = front.getX();
		targetY = front.getY();
		rotation = atan2((targetY-y),(targetX-x));
		rotation = rotation * (180/3.14159265);
		sprite.setRotation(1*rotation);
		fireRate.update();
		if(fireRate.check2())
		{
			bullets->push_back(Bullet(x,y,bulletSpeed*cos(rotation),bulletSpeed*sin(rotation),100));
		}
I find the angle to rotate by taking the arctan of the differences in x and y between the sprite and the target. I am thinking that once I have this angle I should be able to take the cosine of that same angle and multiple it by the speed to get the x velocity of the bullet and sine for the y. The bullets shoot off at angles sometimes but in all sorts of directions. I think it has to do with the differences in domain between arctan and sine and cosine. So things end up being 180 degree off what they should or something. Any ideas?

Sprite Rotation

19 March 2012 - 08:32 PM

I currently have a small sprite that I am trying to rotate dynamically. I have look around on google and it doesn't seem like there are very many good solutions without switching to opengl or something. I am now using SDL to render my 2d game. Up to this point I have been able to get away with just making a sprite sheet with different directions. However, I want to be able to rotate to track a moving target to shoot at it so pre-drawing all to possible angles no longer seems like the right solution. Looking on Google it seems like one option is http://www.ferzkopp.net/joomla/content/view/19/14/ but it also look like a lot of people aren't recommending this because its slow or something. Im not really sure what I should do to fix this problem. It seems like a relatively common task in a game that i surprisingly haven't found a good answer to yet. Any suggestions would be greatly appreciated.

PARTNERS