Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

C++ collision detection

Options
  • 09-10-2011 10:07am
    #1
    Registered Users Posts: 180 ✭✭


    hello I have been writing a side scrolling shooter in visual studio with opengl. I draw the level with GL_QUADSTRIP that reads its points in from a .dat file.

    the dat file looks like this
    # level length
    20
    # level speed (used for development/testing)
    1.2
    # ground data
    10
    0.0 0.0
    1.0 0.25
    2.0 0.0
    #ceiling data
    10
    0.0 1.0
    1.0 0.75
    2.0 1.0
    #end
    I am trying to use this to try and implement collision detection between the ship(which is just a basic triangle drawn with opengl) and the floor and ceiling data
    for(int i= 0;i<=level.groundLength; i++){
    if (ship.position.x < level.ground.x){
    gameState = GAME_QUIT;
    }
    }

    This isnt working obviously so my question is can anyone help me work out how to read the data form the .dat to check if the ship is collidiing with the level and ending the game.

    Any help is appreciated
    Thanking You


Comments

  • Closed Accounts Posts: 5,482 ✭✭✭Kidchameleon


    Not quite sure what way your going about this, any chance of some source? Is the level a tile map?


  • Registered Users Posts: 1,922 ✭✭✭fergalr


    I suspect we would need way more information, to be able to give a helpful reply.

    Context on how you represent the ground, the world, and how the data gets from that .dat file into your game representation would be helpful.


    Two comments on the code snippet you've provided:

    -Why is the groundlevel being checked against the ship level in a 'for loop'?
    Surely you only want to check level of the ground underneath where the ship is currently, rather than to see if the ship is underneath any of the ground anywhere?

    -Secondly, as a shot in the dark at your problem, are you sure you mean to check the 'x' co-ordinate? Generally in a side scroller you would use Y to represent the vertical co-ordinate, and hence use the Y value in the check?


  • Registered Users Posts: 7,157 ✭✭✭srsly78


    Why not just use XNA to do this? Would make your life a lot more productive.

    Using c++ and opengl is doing it the hard way, you are gonna have to build everything yourself, even a DAT loader. This is great if you want to learn, but can be demoralising and difficult.

    Sounds like you have only written some vague pseudo-code here, I don't think you quite realise how much work is involved :)


Advertisement