Thanks Elias
.I made my own "formula" for the jump,but now the BIG problem is that the only last tile is collideble with the player.
THE MINIMAL CODE :
#include <SFML/Graphics.hpp>
using namespace sf;
int main()
{
//Variables
bool upkey = false;
int offsety = 530;
int velocity = 20;
int acceleration = 1;
double gravity = 0.5;
int DisplayFrame = 0; //Frames for animations
float CurrentFrame = 0;
Clock upkeytimer; //Clock
upkeytimer.restart().asSeconds();
int mapArray[45][5] = //The tile map.Now I have a little question,how to put it horizontally,because it consumes a lot of lines
{
{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},
{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},
{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},
{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},
{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},
{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},
{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},
{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},
{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},
};
//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())) //The Problem
{
pos.y += 2;
}
if(Keyboard::isKeyPressed(Keyboard::Right))
{
SAdventurer.setTextureRect(IntRect(80 * DisplayFrame,111,80,110));
pos.x += 2.5;
view.move(2.5,0);
}
CurrentFrame += 0.12;
if(CurrentFrame >= 2) CurrentFrame = 0; //The animation
DisplayFrame = (int)CurrentFrame;
window.clear(Color::White); //Clearing the window
SAdventurer.setPosition(pos.x,pos.y);
window.setView(view); //Setting the view
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 tilemap builder
window.draw(STileGrass);
}
}
}
window.draw(SAdventurer); //Drawing the Player
window.display(); //Displaying
}
PS:That's the #50th post,so I'm not anymore a Newbie,I'm a Jr.!