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

Show Posts

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.


Messages - Eulavvalue

Pages: [1]
1
General / Re: Simple Collision Help
« on: November 10, 2013, 08:10:54 pm »
I think you may want to take a look at the thread I posted yesterday. I solved it already (to my knowledge), but it'll get you going. Note that this is only good for boxes, though. If you want to tackle circles vs boxes then you would have to find a different method.
http://en.sfml-dev.org/forums/index.php?topic=13510.0

2
General / Re: AABB Collision Detection - Checking which side
« on: November 09, 2013, 08:48:54 pm »
I managed to figure this out while thinking about it at work. If anyone has a solution to this similar problem I would be interested to see how you checked for collision.

// Move sprite
        playerSprite.move(movement * deltaTime.asSeconds());

        // Set bounding box to current position
        boundingBox.setPosition(playerSprite.getPosition());

        // Check for collision
        bool collide = false;
        float left = 1000;
        float right = 1000;
        float top = 1000;
        float bottom = 1000;
        for (auto layer = myLoader.GetLayers().begin(); layer != myLoader.GetLayers().end(); ++layer)
        {
                if (layer->name == "Collision")
                {
                        for (auto object = layer->objects.begin(); object != layer->objects.end(); ++object)
                        {
                                // collision = object->GetAABB().intersects(boundingBox.getGlobalBounds());    
                                if ((boundingBox.getPosition().x + boundingBox.getGlobalBounds().width > object->GetPosition().x &&
                                        boundingBox.getPosition().x < object->GetPosition().x + object->GetAABB().width) &&
                                        (boundingBox.getPosition().y + boundingBox.getGlobalBounds().height > object->GetPosition().y &&
                                        boundingBox.getPosition().y < object->GetPosition().y + object->GetAABB().height))
                                {
                                        left = 1000;
                                        right = 1000;
                                        top = 1000;
                                        bottom = 1000;
                                        if ((boundingBox.getPosition().x > object->GetPosition().x) &&
                                                (boundingBox.getPosition().x + boundingBox.getGlobalBounds().width > object->GetPosition().x + object->GetAABB().width))
                                        {
                                                // boundingBox.setPosition(object->GetPosition().x + object->GetAABB().width, boundingBox.getPosition().y);
                                                left = object->GetPosition().x + object->GetAABB().width - boundingBox.getPosition().x;
                                                std::cout << "Left: " << left << std::endl;
                                                std::cout << "Collide on left" << std::endl;
                                                collide = true;
                                        }
                                        if ((boundingBox.getPosition().x < object->GetPosition().x) &&
                                                (boundingBox.getPosition().x + boundingBox.getGlobalBounds().width < object->GetPosition().x + object->GetAABB().width))
                                        {
                                                // boundingBox.setPosition(object->GetPosition().x - boundingBox.getGlobalBounds().width, boundingBox.getPosition().y);
                                                right = boundingBox.getPosition().x + boundingBox.getGlobalBounds().width - object->GetPosition().x;
                                                std::cout << "Right: " << right << std::endl;
                                                std::cout << "Collide on right" << std::endl;
                                                collide = true;
                                        }
                                        if ((boundingBox.getPosition().y > object->GetPosition().y) &&
                                                (boundingBox.getPosition().y + boundingBox.getGlobalBounds().height > object->GetPosition().y + object->GetAABB().height))
                                        {
                                                // boundingBox.setPosition(boundingBox.getPosition().x, object->GetPosition().y + object->GetAABB().height);
                                                top = (object->GetPosition().y + object->GetAABB().height) - boundingBox.getPosition().y;
                                                std::cout << "Top: " << top << std::endl;
                                                std::cout << "Collide on top" << std::endl;
                                                collide = true;
                                        }
                                        if ((boundingBox.getPosition().y < object->GetPosition().y) &&
                                                (boundingBox.getPosition().y + boundingBox.getGlobalBounds().height < object->GetPosition().y + object->GetAABB().height))
                                        {
                                                // boundingBox.setPosition(boundingBox.getPosition().x, object->GetPosition().y - boundingBox.getGlobalBounds().height);
                                                bottom = (boundingBox.getPosition().y + boundingBox.getGlobalBounds().height) - object->GetPosition().y;
                                                std::cout << "Bottom: " << bottom << std::endl;
                                                std::cout << "Collide on bottom" << std::endl;
                                                collide = true;
                                        }

                                        if (collide)
                                        {
                                                if (left < bottom && left < top && left < right)
                                                {
                                                        boundingBox.setPosition(object->GetPosition().x + object->GetAABB().width, boundingBox.getPosition().y);
                                                }
                                                else if (right < bottom && right < top && right < left)
                                                {
                                                        boundingBox.setPosition(object->GetPosition().x - boundingBox.getGlobalBounds().width, boundingBox.getPosition().y);
                                                }
                                                else if (top < right && top < left && top < bottom)
                                                {
                                                        boundingBox.setPosition(boundingBox.getPosition().x, object->GetPosition().y + object->GetAABB().height);
                                                }
                                                else if (bottom < right && bottom < left && bottom < top)
                                                {
                                                        boundingBox.setPosition(boundingBox.getPosition().x, object->GetPosition().y - boundingBox.getGlobalBounds().height);
                                                }
                                        }
                                }
                        }
                }
        }

        playerSprite.setPosition(boundingBox.getPosition());
 

3
General / Re: AABB Collision Detection - Checking which side
« on: November 09, 2013, 11:12:44 am »
That's something I plan to do after I figure out collision. There's a query tree I can use that comes with the Tiled map loader to reduce the tiles I'm checking collision against to those within what I specify. Also it only checks tiles that I specify as solid, so the white rectangles in the pictures are the only checked rectangles.

Edit: After reading your post again it seems you may have misunderstood my problem possibly? I'm not trying to find coordinates of the player sprite since I already have that.

4
General / [Solved] AABB Collision Detection - Checking which side
« on: November 09, 2013, 10:27:30 am »
I'm working on some code to check which side of the box had collided, and then I align the first object to the second one like in 2D games. I know *what* is happening, but I'm pretty confused as to how I would fix it.

The following code will iterate through every tile and check the player against it. Best way I know how to explain the issue is by an example, so here goes.
http://imgur.com/l4ND9Xc
If the above picture continues on its course upwards it will register as a top and right collision. It will register as a right collision and be aligned as such, but then register as a top collision and align as such in one iteration. I'm trying to figure out a way so the following scenario would register as top collision only, and ignore side scenarios (typical 2D collision game play). However, if the user was colliding to the bottom and right like so:
http://imgur.com/wAbBYUp
It should keep the character in position.

BoundingBox and playerSprite has to do with the Player class.
object is a tile or rectangle.

Simply not sure how to go on about this issue since the way I'm thinking of now is checking (colLeft && (!colTop&&!colBottom) then performing proper movement for left collision, but that would be a lot of if-statements. I figured there was someone more experienced that could offer some insight.

// Move sprite
        playerSprite.move(movement * deltaTime.asSeconds());

        // Set bounding box to current position
        boundingBox.setPosition(playerSprite.getPosition());

        // Check for collision
        for (auto layer = myLoader.GetLayers().begin(); layer != myLoader.GetLayers().end(); ++layer)
        {
                if (layer->name == "Collision")
                {
                        for (auto object = layer->objects.begin(); object != layer->objects.end(); ++object)
                        {
                                // collision = object->GetAABB().intersects(boundingBox.getGlobalBounds());    
                                if ((boundingBox.getPosition().x + boundingBox.getGlobalBounds().width > object->GetPosition().x &&
                                        boundingBox.getPosition().x < object->GetPosition().x + object->GetAABB().width) &&
                                        (boundingBox.getPosition().y + boundingBox.getGlobalBounds().height > object->GetPosition().y &&
                                        boundingBox.getPosition().y < object->GetPosition().y + object->GetAABB().height))
                                {
                                        if ((boundingBox.getPosition().x > object->GetPosition().x) &&
                                                (boundingBox.getPosition().x + boundingBox.getGlobalBounds().width > object->GetPosition().x + object->GetAABB().width))
                                        {
                                                boundingBox.setPosition(object->GetPosition().x + object->GetAABB().width, boundingBox.getPosition().y);
                                                std::cout << "Collide on left" << std::endl;
                                        }
                                        else if ((boundingBox.getPosition().x < object->GetPosition().x) &&
                                                (boundingBox.getPosition().x + boundingBox.getGlobalBounds().width < object->GetPosition().x + object->GetAABB().width))
                                        {
                                                boundingBox.setPosition(object->GetPosition().x - boundingBox.getGlobalBounds().width, boundingBox.getPosition().y);
                                                std::cout << "Collide on right" << std::endl;
                                        }
                                        else if ((boundingBox.getPosition().y > object->GetPosition().y) &&
                                                (boundingBox.getPosition().y + boundingBox.getGlobalBounds().height > object->GetPosition().y + object->GetAABB().height))
                                        {
                                                boundingBox.setPosition(boundingBox.getPosition().x, object->GetPosition().y + object->GetAABB().height);
                                                std::cout << "Collide on top" << std::endl;
                                        }
                                        else if ((boundingBox.getPosition().y < object->GetPosition().y) &&
                                                (boundingBox.getPosition().y + boundingBox.getGlobalBounds().height < object->GetPosition().y + object->GetAABB().height))
                                        {
                                                boundingBox.setPosition(boundingBox.getPosition().x, object->GetPosition().y - boundingBox.getGlobalBounds().height);
                                                std::cout << "Collide on bottom" << std::endl;
                                        }
                                }
                        }
                }
        }

        playerSprite.setPosition(boundingBox.getPosition());
 

5
Graphics / Re: Getting 8 points from sprite
« on: November 08, 2013, 01:57:40 am »
Thanks, pointed me in the right direction. Ended up creating a sf::RectangleShape boundingBox in my player class and updating it every tick to check for collision. If collision happens then I revert any movements. Will probably have to update it once I apply gravity to the game and such. 

Edit: Turns out there is also a GetAABB() method included so I can just check for intersections rather than check for points :P.

6
Graphics / [Solved] Getting 8 points from sprite
« on: November 07, 2013, 10:45:17 am »
I'm using Tiled Tile Map Loader (http://trederia.blogspot.co.uk/2013/05/tiled-map-loader-for-sfml.html) and am attempting to use the MapLoader's Collision(point) function to check for any collisions against tiles with my player sprite. I've got it to work using a test sf::RectangleShape where I can simply getPoint(0), getPoint(1), etc. So I'm thinking I should be able to get the bounding box of my sprite and make a RectangleShape with it, and use that to check for collision. I'm drawing a blank on how to get the bounding box from my sprite and creating a sf::Vector2f with it, though, if anyone can help or point me in the right direction. I've read  the creator's collision article on his website and for whatever reason it's not clicking (possibly because I'm tired), so figured I would throw up a post before I sleep.

7
General / Re: Redistributing game
« on: June 21, 2013, 05:36:33 am »
Thanks for the responses. It seems like when I had him download the VC redistributable he ran the 64 bit .exe when it was a 32 bit application. He ran the 32 bit one and it worked perfectly. I'll remove some of the extra .dll's since they aren't needed, and could cause legal issues (although they wouldn't get much money wise from me :P).

8
General / Redistributing game
« on: June 19, 2013, 04:48:33 am »
Hello and thanks for stopping in the thread. At the moment I have an issue trying to get friends to play a game I made to run correctly. The error they are getting is "The application was unable to start correctly (0xc000007b). Click OK to close the application."

This is the zip file I sent to them: http://i.imgur.com/JY4G5KG.png

This is a picture of Advanced Installer 10.2 where I packaged the game (Ignore the red question marks I was testing something): http://i.imgur.com/45RcfPT.png

A little bit about the files - I included the Release version of the Asteroids.exe. I included the debug and non-debug versions of the SFML 2.0 files, and the rest are required MSVS 2012 .dll's from what I understand.

Am I missing any files? I've tried it on three different friends. Two who do not have MSVS 2012, and one that does. The one that does have it installed had no issues running the program.

9
Graphics / [SOLVED] Rotating bullet around ship
« on: May 23, 2013, 04:19:03 am »
Solved: I was scaling my ship and bullet to 0.3 / 0.3 which was messing with calculations. Resized all of them to 30% in an image editor and use no scales and worked fine.

Hello, I'm creating a game similar to asteroids and I'm having trouble trying to set my bullets position to the front of the ship. I've read multiple threads and tried different solutions, but whenever I tried to rotate the bullet it wouldn't rotate around the ship.

From what I understand I want to set my bullets origin to the ships current position, and then somehow calculate the angle and then use setRotation(calculatedAngle) to rotate it to the front of the ship. I've tried, but failed and now I'm here seeing if anyone has some tips. Any help is appreciated!

Below is the relevant code:
// Update space ship
void SpaceShip::update(float elapsedTime)
{
        firingElapsedTime += firingClock.getElapsedTime().asSeconds();
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
        {
                if (firingElapsedTime >= firingSpeed)
                {
                        firingElapsedTime = 0.0f;
                        fire();
                }
        }

    if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
    {
        getSprite().rotate(-250 *elapsedTime);
    }
    if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
    {
        getSprite().rotate(250 * elapsedTime);
    }

    if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
    {
                sf::Vector2f direction(-sin(getSprite().getRotation() * 3.14159265f / 180.0f), -cos(getSprite().getRotation() * 3.14159265f / -180.0f));
                velocity.x -= acceleration * direction.x * elapsedTime;
                velocity.y += acceleration * direction.y * elapsedTime;
    }

    if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
    {
                sf::Vector2f direction(-sin(getSprite().getRotation() * 3.14159265f / 180.0f), -cos(getSprite().getRotation() * 3.14159265f / -180.0f));
                velocity.x += acceleration * direction.x * elapsedTime;
                velocity.y -= acceleration * direction.y * elapsedTime;
    }

    pos = this->getPosition();

        if(pos.x < getSprite().getLocalBounds().width/2 || pos.x > (Game::SCREEN_WIDTH - getSprite().getLocalBounds().width/2) || pos.y < getSprite     ().getLocalBounds().width/2 || pos.y > (Game::SCREEN_HEIGHT - getSprite().getLocalBounds().width/2))
        {
                velocity = -velocity;
        }
   
    getSprite().move(velocity);
        firingClock.restart();
}

// Fire bullets
void SpaceShip::fire()
{
        for (unsigned int i = 0; i < 20; i++)
        {
                if (bullet[i]->active == false)
                {
                        sf::Vector2f direction(-sin(getSprite().getRotation() * 3.14159265f / 180.0f), -cos(getSprite().getRotation() * 3.14159265f / -180.0f));
                        pos = this->getPosition();
                        bullet[i]->setPosition(pos.x, pos.y - 30);
                        bullet[i]->direction.x = direction.x;
                        bullet[i]->direction.y = direction.y;
                        bullet[i]->velocity.x = -bulletAcceleration * direction.x;
                        bullet[i]->velocity.y = bulletAcceleration * direction.y;
                        bullet[i]->active = true;
                        bullet[i]->elapsedTime = 0.0f;
                        std::stringstream objectName;
                        objectName << "Bullet" << i;
                        bullet[i]->objectName = objectName.str();
                        Game::getGameObjectManager().add(objectName.str(), bullet[i]);
                        break;
                }
        }
}
 

Pages: [1]
anything