Hello!I have a real bad time with this for a long time.The only last piece of that "map" is collideble and this is making me a lot of problems.If I solve this a lot of things will run out nicely.
The minimal Code:
int mapArray[45][5] =
{
{1,0,0,0,0},
{1,0,0,0,0},
{1,0,0,0,0},
{1,0,0,0,0},
{1,0,0,0,0},
...//and so
{1,0,0,0,0},
};
//In the game loop
if(Keyboard::isKeyPressed(Keyboard::Up))
{
upkey = true;
upkeytimer.restart().asSeconds();
}
else if(!Keyboard::isKeyPressed(Keyboard::Up))
{
upkey = false;
}
if(upkey == true)
{
for(float up = upkeytimer.getElapsedTime().asSeconds();up < 2;up++) //Longer it's pressed longer it jumps
{
pos.y -=up;
}
}
if(upkey == false && !SAdventurer.getGlobalBounds().intersects(STileGrass.getGlobalBounds())) //It collides only with the last piece,why?
{
pos.y += 2;
}
//After window.clear()
for(int i = 0;i<43;i++)
{
for(int j = 0; j<5;j++)
{
if(mapArray[i][j] == 1)
{
STileGrass.setPosition(i * 70, (j * 70) + offsety); //The "map" builder
window.draw(STileGrass);
}
}
}
window.display();