1
General / Connecting scrolling map and collisions
« on: July 26, 2010, 10:11:38 am »
Why have you copied reply that was written before by someone else? I did it what was said.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Char.SetPosition(512, 384);
Obstacle.SetCenter(Obstacle.GetSize()*.5f);
Char.SetCenter(20, 32); //fits to image size
Background.Resize(2000,2000);
Background.Move(-500,-500);
Obstacle.Move(100,100);
Obstacle.Scale(2.f, 2.f);
sf::Vector2f Center(500,500);
sf::Vector2f HalfSize(App.GetWidth()*.5f,App.GetHeight()*.5f);
sf::View View(Center,HalfSize);
sf::Event evt;
while(App.IsOpened())
{
while(App.GetEvent(evt))
{
if(evt.Type==sf::Event::Closed){App.Close();}
if(evt.Type==sf::Event::KeyPressed&&evt.Key.Code==sf::Key::Escape){App.Close();}
if(evt.Type==sf::Event::KeyPressed&&evt.Key.Code==sf::Key::F1)
{
sf::Image Screen;
Screen = App.Capture();
Screen.SaveToFile("sc2.jpg");
}
}
UpdateBoy(Char, App.GetInput(), Dir, App.GetFrameTime(), go);
View.SetCenter(Char.GetPosition());
App.Clear();
App.SetView(View);
App.Draw(Background);
App.Draw(Obstacle);
App.Draw(Char);
App.Display();
}
if(App.GetInput().IsKeyDown(sf::Key::Down))
{
if((Collision::BoundingBoxTest(Player,Obstacle)==false) && (Collision::BoundingBoxTest(Player, Obst2) == false))
{
Player.Move(0,100*timer);
lastKey="D";
CFPS.Move(0, 100*timer);
}
else if(lastKey=="D")
{
Player.Move(0,-100*timer);
CFPS.Move(0,-100*timer);
}
else
{
Player.Move(0,100*timer);
CFPS.Move(0,100*timer);
}
}
Player.SetCenter(Player.GetSize() / 2.f);
Camera.SetCenter(Player.GetPosition());
App.SetView(App.GetDefaultView());
if(!Collision::BoundingBoxTest(Ludzik, Przesz))
{
if(App.GetInput().IsKeyDown(Key::Up))
Ludzik.Move(0, -100 * time);
if(App.GetInput().IsKeyDown(Key::Down))
Ludzik.Move(0, 100 * time);
if(App.GetInput().IsKeyDown(Key::Left))
Ludzik.Move(-100 * time, 0);
if(App.GetInput().IsKeyDown(Key::Right))
Ludzik.Move(100 * time, 0);
}
if(Collision::BoundingBoxTest(Ludzik, Przesz))
{
//here
}
Your code seeme to test just only one time the collision. What are the size of the two images ? Because maybe "Przesz" is not 100px width nor 50px height...
Your code seeme to test just only one time the collision.
Can you show us the BoundingBoxTest function too please ?