Hey , i think that i have found the problem when in the main , i delete map1.draw(app) , i mean i stop drawing the map i think it works better , the drawing of map takes a lot of time that's why the player don't fit in his place , so i think now i must modify the Draw function to optimize it , i think that i will use only unsigned value then try to do more ,
What do u think guys ?
(im using a collision with a y = 480 just to test ( i tested it with the old collision and a big diffrence too
)
Hello everybody , i'm new here , but i have searched and didn't found any similar topic where i can find a solution
first of all here is a video of my game, (in progress)
it's a video of yesterday
if you see the collision with the map is really ridicules
( i have done it by my self and i know it's wrong
can anyone help me ? i can post my code (it's a real mess
)
thanks for your support
you Friend from Tunisia
----------------------
i'm working with sfml 1.6 and here player update code
void Player::Update(sf::RenderWindow &Window , int downElement , int rightElement , int leftElement, int topElement , IntRect underBox , int underBoxValue )
{
const Input & input = Window.GetInput();
PlayerVelocity.x = 0 ;
//cout<<"underBoxValue"<< underBoxValue <<endl;
//PlayerVelocity.y += gravity * Window.GetFrameTime();
//gravité
if( (!jump ) )
{
PlayerVelocity.y += gravity * Window.GetFrameTime();
}
else
{
PlayerVelocity.y = 0 ;
}
if(input.IsKeyDown(Key::Right))
{ if(rightElement != 1 && rightElement != 2)
{
PlayerVelocity.x = moveSpeed ;
}
currentFrameY = 1;
}
if(input.IsKeyDown(Key::Left))
{ if(leftElement != 1 && leftElement != 2)
{
PlayerVelocity.x = -moveSpeed ;
}
currentFrameY = 0;
}
if(input.IsKeyDown(Key::Up) && jump )
{
PlayerVelocity.y = -jumpSpeed ;
jump = false ;
// y -= moveSpeed * Window.GetFrameTime();
} //else
// 1ere methode pr fixé le joueur a sol CollisionManager::collsion2Box(this->GetBoundingBox(),underBox )
if( (downElement == 1 || downElement == 2) )
{
PlayerVelocity.y = 0 ;
PlayerPosition.y = underBox.Top - 50 ;
jump = true ;
}
else if ( underBoxValue == -1 && jump )
{
//PlayerVelocity.y = jumpSpeed /2;
jump = false ;
}
if ((topElement == 1 || topElement == 2) && (!jump ) && (leftElement != 1 && leftElement != 2) && rightElement !=1 && rightElement!= 2 ) // ki yodhreb fi 7aja mel fou9
{
PlayerVelocity.y = +jumpSpeed / 3;
}
if(PlayerVelocity.x==0)
{
playerAnimation.setActive(false) ;
}
else playerAnimation.setActive(true) ;
PlayerPosition += PlayerVelocity * Window.GetFrameTime();
playerAnimation.setPosition(1, PlayerPosition.x);
playerAnimation.setPosition(2, PlayerPosition.y );
playerAnimation.setCurrentFrame(2, currentFrameY);
playerAnimation.Update(Window);
}
on the main
int underBoxValue ;
IntRect underBox = map1.getUnderBox(player , app, underBoxValue) ;
player.Update(app , map1.getDownElement(player , app) , map1.getRightElement(player, app) ,map1.getleftElement(player , app) , map1.getTopElement(player, app) , underBox, underBoxValue);
on map.cpp
int Map::getDownElement(Player p , RenderWindow &Window)
{
//if(screenCapture.GetPixel(p.getX(),p.getY()) == );
int i = round (( p.GetBoundingBox().Left +5 ) / BLOCKSIZE ) ;
int j = round ((p.GetBoundingBox().Top ) / BLOCKSIZE ) ;
//int pos = -1 ;
int pos ;
pos = MapVector[j+1][i] ;
if (pos == 0 )
{
cout <<"deboredment"<<endl ;
//p.playerAnimation.setPosition(1,50);
p.killed(Window);
}
return pos ;
}
int Map::getRightElement(Player p , RenderWindow &Window)
{
//if(screenCapture.GetPixel(p.getX(),p.getY()) == );
int i = (( p.GetBoundingBox().Right +14)/ BLOCKSIZE ) ;
int j = ( ( p.GetBoundingBox().Bottom + 10) / BLOCKSIZE ) ;
int pos ;
pos = MapVector[j][i] ;
return pos ;
}
int Map::getleftElement(Player p , RenderWindow &Window)
{
//if(screenCapture.GetPixel(p.getX(),p.getY()) == );
int i = (( p.GetBoundingBox().Left + 2)/ BLOCKSIZE ) ;
int j = ( (p.GetBoundingBox().Bottom + 10) / BLOCKSIZE ) ;
int pos ;
pos = MapVector[j][i] ;
if (pos == 0 )
{cout <<"deboredment"<<endl ; }
return pos ;
}
int Map::getTopElement(Player p , RenderWindow &Window)
{
//if(screenCapture.GetPixel(p.getX(),p.getY()) == );
int i = (( p.GetBoundingBox().Left + 20 )/ BLOCKSIZE ) ;
int j = ( (p.GetBoundingBox().Bottom + 5 )/ BLOCKSIZE ) ;
int pos ;
pos = MapVector[j-1][i] ;
return pos ;
}