Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [Solved]Loading from this tileset  (Read 11513 times)

0 Members and 1 Guest are viewing this topic.

The Illusionist Mirage

  • Full Member
  • ***
  • Posts: 115
  • My Life = Linux, C++ & Computers
    • View Profile
    • fleptic
    • Email
Re: Loading from this tileset
« Reply #15 on: October 15, 2013, 05:30:23 am »
I am still unable to figure out what's wrong. :(

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Loading from this tileset
« Reply #16 on: October 15, 2013, 07:07:49 am »
Please read this thread and change your post accordingly...
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

The Illusionist Mirage

  • Full Member
  • ***
  • Posts: 115
  • My Life = Linux, C++ & Computers
    • View Profile
    • fleptic
    • Email
Re: Loading from this tileset
« Reply #17 on: October 15, 2013, 02:02:22 pm »
Ok. Here's how I load my tiles:
for(int i = 0; i < H; i++)
                {
                        for(int j = 0; j < W; j++)
                        {
                                if(tileMap[i][j] == '0')// || tileMap[i][j] == ' ')
                                        tile_ground.setTextureRect(sf::IntRect(256, 64, 32, 32));

                                if(tileMap[i][j] == 'P')
                                        tile_ground.setTextureRect(sf::IntRect(512, 0, 32, 32));

                                tile_ground.setPosition(j * 32, i * 32);
                                window.draw(tile_ground);
                        }
                }
 

And here's how I do the collision checking:
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
                {
                        source.y = Up;
                        isKeyPressed = true;
                        if(!heroSprite.getLocalBounds().intersects(tile_ground.getLocalBounds()))               // I check if the player sprite and the obstacle intersect     
                                heroSprite.move(0, - heroSpeed.y * deltaTime);
                }
               
                else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
                {
                        source.y = Down;
                        isKeyPressed = true;
                        if(!heroSprite.getLocalBounds().intersects(tile_ground.getLocalBounds()))               // I check if the player sprite and the obstacle intersect
                                heroSprite.move(0, heroSpeed.y * deltaTime);
                }

                else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
                {
                        source.y = Left;
                        isKeyPressed = true;
                        if(!heroSprite.getLocalBounds().intersects(tile_ground.getLocalBounds()))               // I check if the player sprite and the obstacle intersect
                                heroSprite.move(- heroSpeed.x * deltaTime, 0);
                }

                else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
                {
                        source.y = Right;
                        isKeyPressed = true;
                        if(!heroSprite.getLocalBounds().intersects(tile_ground.getLocalBounds()))               // I check if the player sprite and the obstacle intersect
                                heroSprite.move(heroSpeed.x * deltaTime, 0);
                }
 

But my sprite is stuck in only one tile and can't move in any direction. How do I prevent this?

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Loading from this tileset
« Reply #18 on: October 15, 2013, 02:20:50 pm »
It looks fairly clear that your code will simply refuse to let the player move ever again as soon as he starts intersecting the ground.  You have to plan out your collision algorithm better than that.

Try separating input handling from collision handling.  That tends to make this easier.

The Illusionist Mirage

  • Full Member
  • ***
  • Posts: 115
  • My Life = Linux, C++ & Computers
    • View Profile
    • fleptic
    • Email
Re: Loading from this tileset
« Reply #19 on: October 15, 2013, 04:25:57 pm »
OK, I've figured out my problems from one of my friends(Geheim). Thanks to all for helping!

 

anything