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 - BlazeCrate

Pages: [1]
1
General / Collision detection not working?
« on: May 21, 2014, 12:56:09 am »
Hello,

I have been working on a 2d space shooter game for the past 2 weeks. I have gotten to the part where I want my player's bullets to collide with the enemy ships. I have setup this function and it checks the boundaries of both the bullets and the enemy ship.

bool Game::enemyBulletCollision()
{
    if (newEnemy->right <= player->newBullet->left || newEnemy->left >= player->newBullet->right ||
        newEnemy->bottom <= player->newBullet->top || newEnemy->top >= player->newBullet->bottom)
    {
        return false;
    }
    else
    {
        return true;
    }
}

All that I want it to do currently is print out "COLLISION!" in the console. (Will add explosions later). With this code if calls the boolean function above and prints out collision if true.

void Game::handleCollision()
{
    if (enemyBulletCollision())
    {
        printf("Collision!\n");
    }
}

This handleCollison function is called in the main game loop.

I have the bullets in a std::vector in the player class and it allows me to handle the player bullets in that player class. I have the enemies also in a std::vector but in the main game class. What I do is I create the newEnemy and newBullet and then I change their position and then push_back that newBullet or newEnemy into the std::vector of each.

I have tried access the bullets and enemies through a loop instead of accessing the top, left, bottom and right from the newBullet and newEnemy objects but the game seems to crash. (Weird)?

Please help!
Thanks

2
Graphics / Re: OpenGL Texture Invalid Operation Call Failed?
« on: May 19, 2014, 06:47:14 pm »
Well I solved the problem of not getting that output. I used your advice about exiting right after I close the window. I just added return EXIT_SUCCESS; right before window.close(); in my main class.

Thanks for the help!

P.s. I will read the rules of posting for future questions.

3
Graphics / Re: OpenGL Texture Invalid Operation Call Failed?
« on: May 19, 2014, 06:32:40 pm »
Sorry forgot to link my code: https://github.com/Ancell/Tractus

4
Graphics / OpenGL Texture Invalid Operation Call Failed?
« on: May 19, 2014, 06:24:53 pm »
Hello,

I am trying to add bullets into my space ship game. I got them working and shooting the way that I want. The bullets are working fine (with a need for a bit of fine tuning).

But when I close the game the console window gives me the error attached.

5
You can view all of my BEGINNER, learning code here on github: https://github.com/Ancell/Tractus

P.s: This is in no way the best way of doing things I just wanted to try to make a game with what I know.

6
I have modified the code a little bit; playing around with the advice you guys gave.

            if (event.type == sf::Event::MouseButtonPressed)
            {
                if (event.mouseButton.button == sf::Mouse::Left)
                {
                    if (quitButtonRect.contains(event.mouseButton.x, event.mouseButton.y))
                    {
                        currentGameState = Quit;
                    }
                }
            }

I came up with this and it doesn't work the way that I want to. I have it in a update method and then is inside a while(window.pollEvent(event)) loop.

The problem is that it works on very little occasions and it is very inconsistent.

7
      while (window.pollEvent(event))
      {
         if (currentGameState == OptionsScreen)
         {
            sf::IntRect backButtonRect(151, 700, 299, 79);

            if (mouseRect.intersects(backButtonRect) && event.type == sf::Event::MouseButtonPressed)
            {
                currentGameState = MainMenu;
            }
        }
      }
 

This is what I tryed with the events but it doesn't work most of the times that I press on the button. It isn't consistent at all. I don't know if I am doing it wrong or what?

8
General / Mouse Pressed and Released Method for Single Mouse Click?
« on: May 18, 2014, 11:34:27 pm »
Hello,

I have been using SFML for a little while now and I am wondering if there is a way to register a single mouse click and not just call it when the mouse is down.

Something like this:
if (sf::Mouse::isButtonPressed(sf::Mouse::Button))
{

}
 

I know that this exists but it should be if the mouse is down and, pressed should be if the mouse is pressed and released.

I think that I might just need to write my own input class to handle all the input but if anyone knows another way of doing things that would be great.

Pages: [1]