gras5hopper
asked on
Collision detection c++ and boundry detection
I am making a game where the player uses the arrow keys to control a submarine to avoid obstacles. However I am unsure of to detect collisions between the 2 objects...
Using c++ and SFML I have declared the Submarine sprite like this
public:
void Submarine::Init(const std::string& ImageFile)
{
cout<<"Sub loaded";
submarine.LoadFromFile(Ima geFile);
cout<<"Sub stored"<<endl;
subSprite.SetImage(submari ne);
subSprite.SetPosition(150, 300);
subSprite.Scale(2.0,2.0);
}
and the obstacle sprites are declared like this
class ObstacleSprite : public Sprite
{
public:
ObstacleSprite();
ObstacleSprite(const Image &Img, const Vector2f &Position=Vector2f(0, 0), const Vector2f &Scale=Vector2f(1, 1), float Rotation=0.f, const Color &Col=Color(255, 255, 255, 255),float scrollPos=0.0);
void setScrollPos(float scrollPos);
void setVertPos(float vertPos);
float getVertPos(void);
float getScrollPos(void);
}
My best guess is a bounding box, but as i've never written one before I am unsure how to go about it. In the SFML documentation there may be somthing like 'get sub rect' but again I am unsure how to implement these...
This is a link to sf::sprite documentation
http://www.sfml-dev.org/documentation/1.6/classsf_1_1Sprite.htm
Using c++ and SFML I have declared the Submarine sprite like this
public:
void Submarine::Init(const std::string& ImageFile)
{
cout<<"Sub loaded";
submarine.LoadFromFile(Ima
cout<<"Sub stored"<<endl;
subSprite.SetImage(submari
subSprite.SetPosition(150,
subSprite.Scale(2.0,2.0);
}
and the obstacle sprites are declared like this
class ObstacleSprite : public Sprite
{
public:
ObstacleSprite();
ObstacleSprite(const Image &Img, const Vector2f &Position=Vector2f(0, 0), const Vector2f &Scale=Vector2f(1, 1), float Rotation=0.f, const Color &Col=Color(255, 255, 255, 255),float scrollPos=0.0);
void setScrollPos(float scrollPos);
void setVertPos(float vertPos);
float getVertPos(void);
float getScrollPos(void);
}
My best guess is a bounding box, but as i've never written one before I am unsure how to go about it. In the SFML documentation there may be somthing like 'get sub rect' but again I am unsure how to implement these...
This is a link to sf::sprite documentation
http://www.sfml-dev.org/documentation/1.6/classsf_1_1Sprite.htm
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.