// SDL libs
#ifdef WIN32
#pragma comment(lib, "SDL.lib")
#pragma comment(lib, "SDLmain.lib")
#endif
//------------------------------------------------------------
//Includes
//------------------------------------------------------------
#include <iostream>
#include <string>
#include <vector>
#include <SDL.h>
#include <SDL_syswm.h>
using namespace std;
#include "Sprite.h" // <- see its there
//-----------------------------------------------------------------
// Constant Variables
//-----------------------------------------------------------------
//For the mouse functions
const int LEFT = 1;
const int RIGHT = 2;
const int MIDDLE = 3;
//-----------------------------------------------------------
// Defines
//-----------------------------------------------------------
#define MouseButtonPressed(evt, btn) (evt.button.state == SDL_PRESSED && evt.button.button == btn)
#define MouseButtonReleased(evt, btn) (evt.button.state == SDL_RELEASED && evt.button.button == btn)
//------------------------------------------------------------
// SDL Function Declarations
//------------------------------------------------------------
int main(int argc, char *argv[]);
//------------------------------------------------------------
// Game Engine Function Declarations
//------------------------------------------------------------
// These are implemented by you for your game.
BOOL GameInitialize();
void GameStart();
void GameEnd();
void GameActivate(HWND hWindow);
void GameDeactivate(HWND hWindow);
void GamePaint(SDL_Surface *screen);
void GameCycle();
int HandleKeys(SDL_Event event);
void MouseButtonDown(int x, int y, int iButton);
void MouseButtonUp(int x, int y, int iButton);
void MouseMove(int x, int y);
BOOL SpriteCollision(Sprite *pSpriteHitter, Sprite *pSpriteHittee); //<- But this causes an undeclared identifier
Not sure whats causing this undeclared identifier.
Ive been working on my simple game engine for a while now but ive been recently working on the Collision detection between sprites. For some reason when I compile what I have it gives me undeclated identifier for the Sprite arguments I have in my BOOL SpriteCollision() function.
I have included my sprite class.h file so I really don't see why. Ive looked and looked and I still can't tell what might be causing it. Its probibly something im over looking. Could someone maybe see if theres something wrong with this section of code?
Try removing the #include "Sprite.h"
Forward declare Sprite
You should minimise the #includes in a .h wherever possible.
Unrelated but, remove the using namespace::std from your .h, and qualify each stl class. eg. std::vector
Forward declare Sprite
class Sprite;
You should minimise the #includes in a .h wherever possible.
Unrelated but, remove the using namespace::std from your .h, and qualify each stl class. eg. std::vector
Forward declare? I can't remove #include "Sprite.h" because it has my sprite class in it.
Ill change the using later on. Right now im just worried about getting things to work. Not a 100% good coding style. Though I am tyring to keep things in a good coding style. Qualifing each stl:: is a waste to me when I don't know every single one ill be using.
Ill change the using later on. Right now im just worried about getting things to work. Not a 100% good coding style. Though I am tyring to keep things in a good coding style. Qualifing each stl:: is a waste to me when I don't know every single one ill be using.
sure. Don't know if it will help much because its very basic.
e:\my documents\c++ programs\jpong\gameengine.h(69) : error C2065: 'Sprite' : undeclared identifier
e:\my documents\c++ programs\jpong\gameengine.h(69) : error C2065: 'Sprite' : undeclared identifier
//-----------------------------------------------------------------// Game Application// C++ Header - Sprite.h//-----------------------------------------------------------------#pragma once//-----------------------------------------------------------------// Include Files//-----------------------------------------------------------------#include <windows.h>#include <SDL.h>#include <string>#include "Bitmap.h"#include "GameEngine.h"//-----------------------------------------------------------------// Custom Data Type(s)//-----------------------------------------------------------------enum SPRITEACTION{ SA_NONE = 0x0000L, SA_KILL = 0x0001L,}; enum BOUNDSACTION { BA_STOP, BA_WRAP, BA_BOUNCE, BA_DIE};//-----------------------------------------------------------------// Function Declarations//-----------------------------------------------------------------// These are to be able to mess with SDL_Rect much easier.void SetSDLRect(SDL_Rect &rcRect, int x, int y, int w, int h);// rcRect1 = Rectangle to copy to.// rcRect2 = Rectangle to copy from.void CopySDLRect(SDL_Rect &rcRect1, SDL_Rect &rcRect2);void InflateSDLRect(SDL_Rect &rcRect, int x, int y);//-----------------------------------------------------------------// Sprite Class//-----------------------------------------------------------------class Sprite{protected: // Member variables Bitmap *m_pBitmap; SDL_Rect m_rcPosition, m_rcCollision; POINT m_ptVelocity; int m_iZOrder; SDL_Rect m_rcBounds; BOUNDSACTION m_baBoundsAction; BOOL m_bHidden; // Helper Methods virtual void CalcCollisionRect();public: // Constructor(s)/Destructor Sprite(Bitmap* pBitmap); Sprite(Bitmap* pBitmap, SDL_Rect &rcBounds, BOUNDSACTION baBoundsAction = BA_STOP); Sprite(Bitmap* pBitmap, POINT ptPosition, POINT ptVelocity, int iZOrder, SDL_Rect &rcBounds, BOUNDSACTION baBoundsAction = BA_STOP); virtual ~Sprite(); // General Methods virtual SPRITEACTION Update(); void Draw(SDL_Surface *screen); BOOL IsPointInside(int x, int y); BOOL TestCollision(Sprite *pTestSprite); // Accessor Methods SDL_Rect GetPosition() {return m_rcPosition;}; void SetPosition(int x,int y); void SetPosition(POINT ptPosition); void SetPosition(SDL_Rect &rcPosition) {CopySDLRect(m_rcPosition, rcPosition);}; void OffsetPosition(int x, int y); SDL_Rect GetCollision() {return m_rcCollision;}; POINT GetVelocity() {return m_ptVelocity;}; void SetVelocity(int x, int y); void SetVelocity(POINT ptVelocity); BOOL GetZOrder() {return m_iZOrder;}; void SetZOrder(int iZOrder) {m_iZOrder = iZOrder;}; void SetBounds(SDL_Rect &rcBounds) {CopySDLRect(m_rcBounds, rcBounds);}; void SetBoundsAction(BOUNDSACTION ba) {m_baBoundsAction = ba;}; BOUNDSACTION GetBoundsAction() {return m_baBoundsAction;}; SDL_Rect GetBounds() {return m_rcBounds;}; BOOL IsHidden() {return m_bHidden;}; void SetHidden(BOOL bHidden) {m_bHidden = bHidden;}; int GetWidth() {return m_pBitmap->GetWidth();}; int GetHeight() {return m_pBitmap->GetHeight();};};//-----------------------------------------------------------------// Sprite Inline Helper Methods//-----------------------------------------------------------------inline void Sprite::CalcCollisionRect(){ int iXShrink = m_rcPosition.w / 12; int iYShrink = m_rcPosition.h / 12; CopySDLRect(m_rcCollision, m_rcPosition); InflateSDLRect(m_rcCollision, iXShrink, iYShrink);}//-----------------------------------------------------------------// Sprite Inline General Methods//-----------------------------------------------------------------inline BOOL Sprite::TestCollision(Sprite *pTestSprite){ SDL_Rect rcTest = pTestSprite->GetCollision(); return m_rcCollision.x <= (rcTest.x + rcTest.w) && rcTest.x <= (m_rcCollision.x + m_rcCollision.y) && m_rcCollision.y <= (rcTest.y + rcTest.h) && rcTest.x <= (m_rcCollision.y + m_rcCollision.h);}
Note this is probibly got a lot of errors in it that I havn't had the compiler catch yet.
Sprite.h includes GameEngine.h and GameEngine.h includes Sprite.h. Either use a forward declare like was already suggested, or rethink how you organize files.
jfl.
jfl.
Gehh im going to just stop for now and let my mind rest. If I forward declare Sprite then I error C2027 now. *sighs* I wish the book I was working from was newer so I knew I was organizing everything right. Ive looked at that link you gave metimmee. I think ive even read it beffore. But having my code in so many seperate files is getting confusing. Especialy in how do Include what where. X-x What to put in each file.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement