Error

Pages: 12
Getting error while trying to compile CApp.cpp
http://rapidshare.com/share/C4602C45EAAD4117BF3E40DBFD1AC0D5
What kind of errors? Only error I'm getting is linker errors.
It is because you are forgetting to compile CEvent.cpp in with it.


g++ -c CEvent.cpp
g++ -c CApp.cpp
g++ -o CTest CEvent.o CApp.o -lSDL


Compiled fine for me after doing that.
¿why are you posting a picture?
The application is running now
hank you.
Okay you are forgetting to link against SDL.

g++ -o CTest CEvent.o CApp.o -lSDL
check the method
bool CSurface::OnDraw(SDL_Surface* Surf_Dest, SDL_Surface* Surf_Src, int X, int Y)
on CSurface.h and CSurface.cpp

if everything is right there

there is a use of this method
on CEntity.cpp line 91
The function is:
bool CSurface::OnDraw(SDL_Surface* Surf_Dest, SDL_Surface* Surf_Src, int X, int Y)

I'm getting error while trying to compile because these methods
i got this source code on http://www.sdltutorials.com/

[snake@localhost SDL]$ g++ -c CEntity.cpp
CEntity.cpp: In member function ‘virtual void CEntity::OnRender(SDL_Surface*)’:
CEntity.cpp:91:126: error: no matching function for call to ‘CSurface::OnDraw(SDL_Surface*&, SDL_Surface*&, float&, float&, int, int, int&, int&)’
CSurface::OnDraw(Surf_Display, Surf_Entity, X, Y, AnimState * Width, Anim_Control.GetCurrentFrame() * Height, Width, Height);
Last edited on
I fixed it add a second OnDraw function
thank you
Please check the project here
https://github.com/legendarysnake/Open-Multiplayer-Rpg
i'm getting errors while trying to compile
if you join the project will be very helpful.
Error I'm getting so far:
CTile.h:4:20: fatal error: Define.h: No such file or directory
#include "Define.h"


Honestly, we would be more likely to help you if you would tell us what your errors were rather than just saying "I'm getting errors" as most of us don't have time to try and build the source.

Found time to pull the source and attempt to compile on my own. To remove the Define.h error I simply created an empty Define.h file. Then upon compilation, I got several errors about variables being used that weren't defined before hand.
.....
...Define.h...Please tell me Define.h isn't just global variable declarations. The errors I'm getting are things like MAP_WIDTH wasn't declared in this scope and the like with TILE_SIZE, WWIDTH, and MAP_HEIGHT in CArea, CCamera, CEntity, and Cmap.
Last edited on
define.h
#ifndef _DEFINE_H_
#define _DEFINE_H_

#define MAP_WIDTH 40
#define MAP_HEIGHT 40

#define TILE_SIZE 16

#define WWIDTH 640
#define WHEIGHT 480

#endif
Last edited on
I had a hunch that was what the file was. Wasn't expecting defines as I was expecting something like (which I changed on my end) this:

1
2
3
4
5
6
7
8
9
10
11
12
#ifndef _DEFINE_H_
#define _DEFINE_H_

const int MAP_WIDTH = 40;
const int MAP_HEIGHT = 40;

const int TILE_SIZE = 16;

const int WWIDTH = 640;
const int WHEIGHT = 480;

#endif 


Although, again you have to tell what errors you are getting. I may be getting completely different errors than you when trying to build it. I think this is one main reason I'm the only one attempting to help because you are asking for help but not posting anything but your code.

Right now the only errors I get are:

/CArea.cpp|106|undefined reference to `CMap::GetTile(int, int)'|
/CEntity.cpp|228|undefined reference to `CEntity::PosValidEntity(CEntity*, int, int)'|


The rest are warnings that should be simple enough to fix.
Last edited on
CMap.cpp
#include "CMap.h"

CMap::CMap() {
Surf_Tileset = NULL;
}

bool CMap::OnLoad(char* File) {
TileList.clear();

FILE* FileHandle = fopen(File, "r");

if(FileHandle == NULL) {
return false;
}

for(int Y = 0;Y < MAP_HEIGHT;Y++) {
for(int X = 0;X < MAP_WIDTH;X++) {
CTile tempTile;

fscanf(FileHandle, "%d:%d ", &tempTile.TileID, &tempTile.TypeID);

TileList.push_back(tempTile);
}
fscanf(FileHandle, "\n");
}

fclose(FileHandle);

return true;
}


CTile* CMap::GetTile(int X, int Y) {
int ID = 0;

ID = X / TILE_SIZE;
ID = ID + (MAP_WIDTH * (Y / TILE_SIZE));

if(ID < 0 || ID >= TileList.size()) {
return NULL;
}

return &TileList[ID];
}
void CMap::OnRender(SDL_Surface* Surf_Display, int MapX, int MapY) {
if(Surf_Tileset == NULL) return;

int TilesetWidth = Surf_Tileset->w / TILE_SIZE;
int TilesetHeight = Surf_Tileset->h / TILE_SIZE;

int ID = 0;

for(int Y = 0;Y < MAP_HEIGHT;Y++) {
for(int X = 0;X < MAP_WIDTH;X++) {
if(TileList[ID].TypeID == TILE_TYPE_NONE) {
ID++;
continue;
}

int tX = MapX + (X * TILE_SIZE);
int tY = MapY + (Y * TILE_SIZE);

int TilesetX = (TileList[ID].TileID % TilesetWidth) * TILE_SIZE;
int TilesetY = (TileList[ID].TileID / TilesetWidth) * TILE_SIZE;

CSurface::OnDraw(Surf_Display, Surf_Tileset, tX, tY, TilesetX, TilesetY, TILE_SIZE, TILE_SIZE);

ID++;
}
}
}
CEntity.cpp
#include "CEntity.h"

std::vector<CEntity*> CEntity::EntityList;

CEntity::CEntity() {
Surf_Entity = NULL;

X = 0;
Y = 0;

Width = 0;
Height = 0;

MoveLeft = false;
MoveRight = false;

Type = ENTITY_TYPE_GENERIC;

Dead = false;
Flags = ENTITY_FLAG_GRAVITY;

SpeedX = 0;
SpeedY = 0;

AccelX = 0;
AccelY = 0;

MaxSpeedX = 5;
MaxSpeedY = 5;

CurrentFrameCol = 0;
CurrentFrameRow = 0;

Col_X = 0;
Col_Y = 0;

Col_Width = 0;
Col_Height = 0;
}

CEntity::~CEntity() {
}

bool CEntity::OnLoad(char* File, int Width, int Height, int MaxFrames) {
if((Surf_Entity = CSurface::OnLoad(File)) == NULL) {
return false;
}

// CSurface::Transparent(Surf_Entity, 255, 0, 255);

this->Width = Width;
this->Height = Height;

Anim_Control.MaxFrames = MaxFrames;

return true;
}

void CEntity::OnLoop() {
//We're not Moving
if(MoveLeft == false && MoveRight == false) {
StopMove();
}

if(MoveLeft) {
AccelX = -0.5;
}else

if(MoveRight) {
AccelX = 0.5;
}

if(Flags & ENTITY_FLAG_GRAVITY) {
AccelY = 0.75f;
}

SpeedX += AccelX * CFPS::FPSControl.GetSpeedFactor();
SpeedY += AccelY * CFPS::FPSControl.GetSpeedFactor();

if(SpeedX > MaxSpeedX) SpeedX = MaxSpeedX;
if(SpeedX < -MaxSpeedX) SpeedX = -MaxSpeedX;
if(SpeedY > MaxSpeedY) SpeedY = MaxSpeedY;
if(SpeedY < -MaxSpeedY) SpeedY = -MaxSpeedY;

OnAnimate();
OnMove(SpeedX, SpeedY);
}

void CEntity::OnRender(SDL_Surface* Surf_Display) {
if(Surf_Entity == NULL || Surf_Display == NULL) return;
CSurface::OnDraw(Surf_Display, Surf_Entity, X, Y, AnimState * Width, Anim_Control.GetCurrentFrame() * Height, Width, Height);

}
void CEntity::OnAnimate() {
if(MoveLeft) {
CurrentFrameCol = 0;
}else

if(MoveRight) {
CurrentFrameCol = 1;
}

Anim_Control.OnAnimate();
}
void CEntity::OnCollision(CEntity* Entity) {
}
void CEntity::OnMove(float MoveX, float MoveY) {
if(MoveX == 0 && MoveY == 0) return;

double NewX = 0;
double NewY = 0;

MoveX *= CFPS::FPSControl.GetSpeedFactor();
MoveY *= CFPS::FPSControl.GetSpeedFactor();

if(MoveX != 0) {
if(MoveX >= 0) NewX = CFPS::FPSControl.GetSpeedFactor();
else NewX = -CFPS::FPSControl.GetSpeedFactor();
}

if(MoveY != 0) {
if(MoveY >= 0) NewY = CFPS::FPSControl.GetSpeedFactor();
else NewY = -CFPS::FPSControl.GetSpeedFactor();
}

while(true) {
if(Flags & ENTITY_FLAG_GHOST) {
PosValid((int)(X + NewX), (int)(Y + NewY)); //We don't care about collisions, but we need to send events to other entities

X += NewX;
Y += NewY;
}else{
if(PosValid((int)(X + NewX), (int)(Y))) {
X += NewX;
}else{
SpeedX = 0;
}

if(PosValid((int)(X), (int)(Y + NewY))) {
Y += NewY;
}else{
SpeedY = 0;
}
}

MoveX += -NewX;
MoveY += -NewY;

if(NewX > 0 && MoveX <= 0) NewX = 0;
if(NewX < 0 && MoveX >= 0) NewX = 0;

if(NewY > 0 && MoveY <= 0) NewY = 0;
if(NewY < 0 && MoveY >= 0) NewY = 0;

if(MoveX == 0) NewX = 0;
if(MoveY == 0) NewY = 0;

if(MoveX == 0 && MoveY == 0) break;
if(NewX == 0 && NewY == 0) break;
}
}
void CEntity::StopMove() {
if(SpeedX > 0) {
AccelX = -1;
}

if(SpeedX < 0) {
AccelX = 1;
}

if(SpeedX < 2.0f && SpeedX > -2.0f) {
AccelX = 0;
SpeedX = 0;
}
}
bool CEntity::Collides(int oX, int oY, int oW, int oH) {
int left1, left2;
int right1, right2;
int top1, top2;
int bottom1, bottom2;

int tX = (int)X + Col_X;
int tY = (int)Y + Col_Y;

left1 = tX;
left2 = oX;

right1 = left1 + Width - 1 - Col_Width;
right2 = oX + oW - 1;

top1 = tY;
top2 = oY;

bottom1 = top1 + Height - 1 - Col_Height;
bottom2 = oY + oH - 1;


if (bottom1 < top2) return false;
if (top1 > bottom2) return false;

if (right1 < left2) return false;
if (left1 > right2) return false;

return true;
}
bool CEntity::PosValid(int NewX, int NewY) {
bool Return = true;

int StartX = (NewX + Col_X) / TILE_SIZE;
int StartY = (NewY + Col_Y) / TILE_SIZE;

int EndX = ((NewX + Col_X) + Width - Col_Width - 1) / TILE_SIZE;
int EndY = ((NewY + Col_Y) + Height - Col_Height - 1) / TILE_SIZE;

for(int iY = StartY;iY <= EndY;iY++) {
for(int iX = StartX;iX <= EndX;iX++) {
CTile* Tile = CArea::AreaControl.GetTile(iX * TILE_SIZE, iY * TILE_SIZE);

if(PosValidTile(Tile) == false) {
Return = false;
}
}
}

if(Flags & ENTITY_FLAG_MAPONLY) {
}else{
for(int i = 0;i < EntityList.size();i++) {
if(PosValidEntity(EntityList[i], NewX, NewY) == false) {
Return = false;
}
}
}

return Return;
}
bool CEntity::PosValidTile(CTile* Tile) {
if(Tile == NULL) {
return true;
}

if(Tile->TypeID == TILE_TYPE_BLOCK) {
return false;
}

return true;
}
void CEntity::OnCleanup() {
if(Surf_Entity) {
SDL_FreeSurface(Surf_Entity);
}

Surf_Entity = NULL;
}
bool CEntity::PosValidEntity(CEntity* Entity, int NewX, int NewY) {
if(this != Entity && Entity != NULL && Entity->Dead == false &&
Entity->Flags ^ ENTITY_FLAG_MAPONLY &&
Entity->Collides(NewX + Col_X, NewY + Col_Y, Width - Col_Width - 1, Height - Col_Height - 1) == true) {

CEntityCol EntityCol;

EntityCol.EntityA = this;
EntityCol.EntityB = Entity;

CEntityCol::EntityColList.push_back(EntityCol);

return false;
}

return true;
}
I have the code. I said to post the errors you were getting so I know if you are at the same point. Me fixing the errors I get makes no difference if you are getting a completely different set of errors.

First error is that you appear to not have GetTile(int, int); actually defined in CMap (or CTile for that matter), but do in CArea but it is returning a pointer to CMap's function.

So basically you are calling a function that semi exists. You declare it in CMap, but you don't define it in CMap.cpp and just now looking at the second error.

Okay, I give up. You need to think this out a little more. You have CArea's class calling CMap functions that return pointers to CTile methods, but you are using CArea members inside of the GetMap declaration from CMap .. at least from what I see at first glance.

You will have to get help from someone with more time on their hands to help you with the code.
Last edited on
Thank you so much for your help, i fixed it here
I wasn't very helpful. Glad you got it fixed though.
I fixed the 2 errors you told me, but i got news, i am trying to compile this application:
https://github.com/Samurai336/sdl2-collision-events
which actually is the same application with some changes.
using this makefile :
all:
g++ CAnimation.cpp CApp_OnCleanup.cpp CApp_OnEvent.cpp CApp.cpp CApp_OnLoop.cpp CApp_OnRender.cpp CArea.cpp CCamera.cpp CEntity.cpp CEntityCol.cpp CEvent.cpp CFPS.cpp CMap.cpp CPlayer.cpp CSurface.cpp CTile.cpp -o application


the application return me:
http://tinypic.com/r/15raww5/8
Pages: 12