Ok here is my function. I am trying to do the collsion detection from one of the articles. I am trying to learn to so I can modify it.
#ifndef _CCOLLISON_H_ #define _CCOLLISON_H_
/*Includes*/ #include "global.h"
class cCollison { public: cCollison(void); ~cCollison(void);
//Functions int DetectCollisionVer1(cSprite &p_sprite1,cSprite &p_sprite2);
private: int m_left1; int m_left2; int m_right1; int m_right2; int m_top1; int m_top2; int m_bottom1; int m_bottom2;
}; #endif //end of file
here is the defination int cCollison::DetectCollisionVer1(cSprite &p_sprite1, cSprite &p_sprite2) { //Set the attributes //meaning were are going to record the object stats //sprite1 first then sprite2 m_left1 = p_sprite1.GetXpos(); m_left2 = p_sprite2.GetXpos(); m_right1 = p_sprite1.GetXpos() + p_sprite1.GetWidth(); m_right2 = p_sprite2.GetXpos() + p_sprite2.GetWidth(); m_top1 = p_sprite1.GetYpos(); m_top2 = p_sprite2.GetYpos(); m_bottom1 = p_sprite1.GetYpos() + p_sprite1.GetHeight(); m_right2 = p_sprite2.GetYpos() + p_sprite2.GetHeight();
//The following is not a collision so disregard if (m_bottom1 < m_top2) return(0); if (m_top1 > m_bottom2) return(0);
if (m_right1 < m_left2) return(0); if (m_left1 > m_right2) return(0);
return (1); }//end of function
the Error appears here: error C2061: syntax error : identifier 'cSprite' appears at the declaration of the DetectCollisionVer1() method
Just trying this learn this very challenging subject of game programming.
Quote:Original post by stylin In the code you posted above, csprite.h includes global.h. You'll need to include csprite.h in ccollision.h in order to reference your cSprite class.
That is what I said, which is why he responded that in global.h he has #include "csprite.h".
I'm stumped why it doesn't work. I debug better if I have the files [grin]. It is easier to check possible solutions or various typos.
Quote:Original post by stylin In the code you posted above, csprite.h includes global.h. You'll need to include csprite.h in ccollision.h in order to reference your cSprite class.
That is what I said, which is why he responded that in global.h he has #include "csprite.h".
Except that he's wrong. csprite.h includes global.h, and collision.h includes global.h. collision.h is completely ignorant of csprite.h.