@Valentin_Honore wrote:
Hello,
I have some problem with "Jump" I don't have the result I would like. Actually, wth the Jump part of the code, my player go a little into the platform and I don't know why. More over, If I continue to press space button my player become crazy by shaking very fast and I don't want that. I would like that the player has to release the space button before do another jump.
There it is the code to make my "player" jump :
public void playerUpdate(GameTime gameTime)
{
KeyboardState kState = Keyboard.GetState();
float dt = (float)gameTime.ElapsedGameTime.TotalSeconds;
hitBoxPlayer = new Vector2(position.X + 45, position.Y + 35);
// Fall because of gravity part code
Vector2 tempPos = position;
tempPos.Y += speed * increment * dt;
tempPos.X += speed * increment * dt;
if (Platform.DidCollideVertical(tempPos) && Platform.DidCollideHorizontal(position))
{
jumping = false;
}
else
{
position.Y += speed * increment * dt;
if (increment < 10)
increment += 0.1f;
jumping = true;}
// "Jump" part of the code
if (kState.IsKeyDown(Keys.Space) && spaceRelease == true) { position.Y -= 5 * speed * dt; } if (kState.IsKeyUp(Keys.Space) && Platform.DidCollideVertical(tempPos)) { spaceRelease = true; increment = 0f; } else if (kState.IsKeyUp(Keys.Space) ) { spaceRelease = false; }
Here the DidCollide 's functions (that are in class Platform) :
> public static bool DidCollideVertical(Vector2 otherPos) > { > foreach (Platform p in Platform.platforms) > { > float sumY = 128 + 26; > if (Math.Abs(p.HitBox.Y - otherPos.Y) < sumY) > { > return true; > } > } > return false; > } > public static bool DidCollideHorizontal(Vector2 otherPos) > { > foreach (Platform p in Platform.platforms) > { > > if (otherPos.X >= (p.position.X-20) && otherPos.X < p.hitBox.X) > { > return true; > } > } > return false; > }
(The boolean "jump" will be used in the draw method later)
you can download the all project here : https://www.dropbox.com/s/im74pk9zbm2wllj/Bumble2.rar?dl=0
Thanks in advance for your help,
Valentin
Posts: 1
Participants: 1