Basically the move() function which handles collision checking and movement requires the objects screen and the objects it's checking for collision with. One is of type Base and called base2, but now G++ is telling me that Base is undeclared. But you see the object that is intended to be passed as the operand of move() is also of type Base and named base and that works fine which means that clearly Base exists else lower down the line in Main.h, the declaration of 'Base *base;' wouldn't have been successful. Anyway here's the source code for a few of the files.
Globals.h
Code: Select all
//setting bullshit
//setting bullshit
#ifndef GLOBALS_H
#define GLOBALS_H
#include <iostream>
#include <sstream>
#include <fstream>
#include <cmath>
#include <ctime>
#include "SDL\SDL.h"
#include "Windows.h"
using namespace std;
bool quit;
const int SCREEN_BPP=32;
const int SCREEN_WIDTH=800;
const int SCREEN_HEIGHT=480;
const int SPRITE_MAX=375;
const int SPRITE_WIDTH=32;
const int SPRITE_HEIGHT=32;
const int BASE_HEIGHT=50;
const string SPRITE_FOLDER="Sprites\\";
const string FOREGROUND_FOLDER="Foreground\\";
const string BACKGROUND_FOLDER="Background\\";
const string PLAYER_FOLDER=FOREGROUND_FOLDER+"Player\\";
const string AI_FOLDER=FOREGROUND_FOLDER+"AIs\\";
const string OBJECT_FOLDER=FOREGROUND_FOLDER+"Objects\\";
const string BASE_FOLDER=FOREGROUND_FOLDER+"Bases\\";
const string SKY_FOLDER=BACKGROUND_FOLDER+"Skys\\";
const string PROP_FOLDER=BACKGROUND_FOLDER+"Props\\";
const string BREAK="----------------------------------------------------------------------";
//bullshiz
bool checkCollision(SDL_Rect a,SDL_Rect b);
#include "Debugger.h"
#include "Sprite.cpp"
#include "Player.cpp"
#include "AI.cpp"
#include "Object.cpp"
#include "Base.cpp"
#include "Sky.cpp"
#include "Prop.cpp"
#include "Lib.cpp"
#include "Trigger.cpp"
#endif
Code: Select all
#ifndef PLAYER_H
#define PLAYER_H
#include "Globals.h"
using namespace std;
class Player{
private:
Sprite *sprite;
string file;
int x;
int y;
int xDelta;
int yDelta;
public:
Player();
Player(string file,int x,int y,int w,int h);
~Player();
void draw(SDL_Surface *screen);
void checkInput(SDL_Surface *screen,SDL_Event event2,const int SPRITE_WIDTH,const int SPRITE_HEIGHT);
void move(SDL_Surface *screen,Base *base2);
string getFile();
void setFile(string file2);
SDL_Rect getBox();
int getX();
void setX(int x);
int getY();
void setY(int y);
int getW();
void setW(int w);
int getH();
void setH(int h);
int getXDelta();
void setXDelta(int xDelta2);
int getYDelta();
void setYDelta(int yDelta2);
};
#endif
Code: Select all
#ifndef PLAYER_CPP
#define PLAYER_CPP
#include "Player.h"
Player::Player(string file,int x,int y,int w,int h){
setXDelta(0);
setYDelta(0);
sprite=new Sprite(PLAYER_FOLDER+file,x,y,w,h);
}
Player::~Player(){
delete sprite;
delete this;
}
void Player::draw(SDL_Surface *screen){
sprite->draw(screen);
}
void Player::checkInput(SDL_Surface *screen,SDL_Event event2,const int SPRITE_WIDTH,const int SPRITE_HEIGHT){
//check event
if(SDL_PollEvent(&event2)){
if(event2.type==SDL_KEYDOWN){
switch(event2.key.keysym.sym){
case SDLK_ESCAPE:
quit=true;
break;
case SDLK_UP:
setYDelta(getYDelta()-1);
break;
case SDLK_DOWN:
setYDelta(getYDelta()+1);
break;
case SDLK_LEFT:
setXDelta(getXDelta()-1);
break;
case SDLK_RIGHT:
setXDelta(getXDelta()+1);
break;
default:
//do nowt
break;
}
}else if(event2.type==SDL_KEYUP){
switch(event2.key.keysym.sym){
case SDLK_UP:
setYDelta(getYDelta()+1);
break;
case SDLK_DOWN:
setYDelta(getYDelta()-1);
break;
case SDLK_LEFT:
setXDelta(getXDelta()+1);
break;
case SDLK_RIGHT:
setXDelta(getXDelta()-1);
break;
default:
//do nowt
break;
}
}else if(event2.type==SDL_QUIT){
quit=true;
}
}
}
void Player::move(SDL_Surface *screen,Base *base2){
setX(getX()+getXDelta());
if((getX()<0)||(getX()+SPRITE_WIDTH>SCREEN_WIDTH)||(checkCollision(getBox(),base2->getBox()))){
setX(getX()-getXDelta());
}
setY(getY()+getYDelta());
if((getY()<0)||(getY()+SPRITE_HEIGHT>SCREEN_HEIGHT-BASE_HEIGHT)){
setY(getY()-getYDelta());
}
draw(screen);
}
string Player::getFile(){
return sprite->getFile();
}
void Player::setFile(string file2){
sprite->setFile(file2);
}
SDL_Rect Player::getBox(){
return sprite->getBox();
}
int Player::getX(){
return sprite->getX();
}
void Player::setX(int x){
sprite->setX(x);
}
int Player::getY(){
return sprite->getY();
}
void Player::setY(int y){
sprite->setY(y);
}
int Player::getW(){
return sprite->getW();
}
void Player::setW(int w){
sprite->setW(w);
}
int Player::getH(){
return sprite->getH();
}
void Player::setH(int h){
sprite->setH(h);
}
int Player::getXDelta(){
return xDelta;
}
void Player::setXDelta(int xDelta2){
xDelta=xDelta2;
}
int Player::getYDelta(){
return yDelta;
}
void Player::setYDelta(int yDelta2){
yDelta=yDelta2;
}
#endif
Help appreciated as always.In file included from src\Player.cpp:3,
from src\Globals.h:38,
from src\Globals.cpp:3,
from src\Main.h:1,
from src\Main.cpp:1:
src\Player.h:21: error: `Base' has not been declared
src\Player.h:21: error: ISO C++ forbids declaration of `base2' with no type
In file included from src\Globals.h:38,
from src\Globals.cpp:3,
from src\Main.h:1,
from src\Main.cpp:1:
src\Player.cpp:64: error: `Base' has not been declared
src\Player.cpp:64: error: ISO C++ forbids declaration of `base2' with no type
src\Player.cpp: In member function `void Player::move(SDL_Surface*, int*)':
src\Player.cpp:66: error: request for member `getBox' in `*base2', which is of n
on-class type `int'
src\Main.cpp: In function `void foregroundLayer()':
src\Main.cpp:37: error: no matching function for call to `Player::move(SDL_Surfa
ce*&, Base*&)'
src\Player.cpp:64: note: candidates are: void Player::move(SDL_Surface*, int*)