Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Canvas

Member Since 05 Mar 2012
Offline Last Active Nov 10 2014 06:06 PM

Posts I've Made

In Topic: SFML Bounding box but how to implment collision with side detection?

05 November 2014 - 02:29 PM

Sorry for the late reply guys, I went on Holiday for quite a few days :D,

 

@GlassKnife this may seem to be the problem let me investigate

 

@Beernutts So basically check the X axis then check the Y axis? But lets say my ball has just fallen inside of a block, wouldn't my ball now bounce up and the opposite X direction for no reason?

 

@Buckeye I have changed my sf::IntRect to sf::FloatRect and it seem much better however I am still getting some odd effects, but they are happening a lot frequently


In Topic: Help with implementing smooth mario movement

25 June 2014 - 02:23 PM

Its ok I have it working now biggrin.png

 

Here is my switch statement

switch (event.type)
		{
			case sf::Event::KeyPressed:
				if (event.key.code == sf::Keyboard::D)
				{
					Characters.at(0).moveRight = true;
				}
				else if (event.key.code == sf::Keyboard::A)
				{
					Characters.at(0).moveLeft = true;
				}
			break;
			case sf::Event::KeyReleased:
				if (event.key.code == sf::Keyboard::D)
				{
					Characters.at(0).moveRight = false;
				}
				else if (event.key.code == sf::Keyboard::A)
				{
					Characters.at(0).moveLeft = false;
				}
			break;
			default:
			break;
		}

Now at the moment i'm trying to swap the sprite around when Mario is moving left or moving right, this is what I have at the moment

if (leftSpeed > 0)
	{
		sprite.setScale(-1.0, 1.0);
	}

	if (rightSpeed > 0)
	{
		sprite.setScale(1.0, 1.0);
	}

it works fine when moving right, but if I am moving left and then turn right the sprite will turn straight around to the right side, I have tried to change the if statement to be if else if and then it works the other way around, where left is more dominant then right. How do I fix this?


In Topic: Help with implementing smooth mario movement

25 June 2014 - 01:34 PM

Thank you for the all the posts guys, I have looked at the my KeyboardEvent method and I have notice I wasn't using the event that is my bad, I have updated my mario to move smoothly now, but the one part I can't get my head around is the new switch statement I'm attempting to implement for my keyboard event

 

Here is my switch statement so far

		switch (event.type)
		{
			case sf::Event::KeyPressed:
			case sf::Keyboard::D:Characters.at(0).moveRight = true; break;
			case sf::Keyboard::A:Characters.at(0).moveLeft = true; break;
			break;
			case sf::Event::KeyReleased:
			case sf::Keyboard::D:Characters.at(0).moveRight = false; break;
			case sf::Keyboard::A:Characters.at(0).moveLeft = false; break;
			break;
			default:
			break;
		}

I'm getting an error at the second sf::Keyboard::D and sf::Keyboard::A, the error states case label value has already appeared in this switch, how do I get around this? I want to change the a variable if a key is released.


In Topic: Help with implementing smooth mario movement

24 June 2014 - 03:33 PM

Well at the moment BeetNutts I have this has my keyboard event handler

 

Same as above

void State::KeyboardEvent(sf::Event event)
{
	if (state == GameStates::GS_Level1)
	{
		if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
		{
			//Set move right to true
			Characters.at(0).moveRight = true;
		}
		else if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
		{
			//Set move left to true
			Characters.at(0).moveLeft = true;
		}

		if (!sf::Keyboard::isKeyPressed(sf::Keyboard::D))
		{
			Characters.at(0).moveRight = false;
		}

		if (!sf::Keyboard::isKeyPressed(sf::Keyboard::A))
		{
			Characters.at(0).moveLeft = false;
		}
	}
}

Feel free to show code on how to make mine better biggrin.png

 

and here is my character update method

void CharacterObject::UpdateMovement()
{

	if (moveRight == true || moveLeft == true)
	{
		if (xSpeed < xSpeedMax)
		{
			xSpeed += xIncrease;
		}
	}

	if (moveRight == true)
	{
		xPos += xSpeed;
	}

	if (moveLeft == true)
	{
		xPos -= xSpeed;
	}

	if (moveLeft == false && moveRight == false)
	{
		if (xSpeed > 0)
		{
			std::cout << "X speed : " << xSpeed << std::endl;
			if ((xSpeed - 0.1) > 0)
			{
				xSpeed -= 0.1;
			}
			else
			{
				xSpeed = 0;
			}
		}
		else
		{
			xSpeed = 0;
		}
	}
}

At the moment the out come is pretty good, but the problem I am facing now is if I move right and hit my maxspeed, when I then press left and stop pressing right, I need to slow Mario down and then turn him around, but at the moment Mario just turns around and get's full maxspeed, trying to work out how I can deal with this. But also if i dont have right or left down my character stops moving, but the xSpeed isn't 0 yet


In Topic: C++ and SFML game structure help

10 May 2014 - 08:12 AM

Dezachu that all sounds good to me, but one question I do need to ask. You have stated that if the game was to get large ( or larger). clearing the vector and re-populating it would be quite heavy on process. This makes sense to me, but where you have said create a vector of GameObject and then iterate over that vector just render them. Could you try and explain this for my Level.cpp class. My level has a Hero object which will have a sprite, the Monster object will have a sprite and the Map will have a numerous amount of sprites. if each one of these have a GameObject which just holds the sprite. If I pass them back as the object, the vector will just take a copy, and when I call the Hero.Update method that update which changes the position will not even the GameObject copy in the vector. Would I have to change my vector to take pointers of GameObject? I would prefer to stay away from pointers as this will most probably cause a problem with memory management


PARTNERS