Is this a good start?

Started by
18 comments, last by SSJCORY 18 years, 9 months ago
I am starting on a game is this like a good start am i going about things correctly? Heres my code.

#include<windows.h>
#include<vector>
#include<string>
#include<sstream>
using namespace std;
class cMap;
class cPlayer;
class cAnimate{
private:
	vector <HBITMAP>animation;
	bool active;
	int currentframe;
	int frametime;
	int lastupdate;
	int x;
	int y;
	vector <int>width;
	vector <int>height;
public:
	cAnimate(){
		active = false;
		currentframe = 0;
		frametime = 300;
		lastupdate = GetTickCount();
	}
	int getLastUpdate(){
		return lastupdate;
	}
	int getFrameTime(){
		return frametime;
	}
	void addFrame(HBITMAP newframe,int newwidth,int newheight){
		animation.push_back(newframe);
		width.push_back(newwidth);
		height.push_back(newheight);
	}
	void removeFrame(int index){
		animation.erase(animation.begin() + index);
	}
	void activate(){
		active = true;
	}
	bool isActive(){
		return active;
	}
	int getCurrentFrame(){
		return currentframe;
	}
	void setX(int newx){
		x = newx;
	}
	void setY(int newy){
		y = newy;
	}
	int getX(){
		return x;
	}
	int getY(){
		return y;
	}
	int getWidth(int index){
		return width[index];
	}
	int getHeight(int index){
		return height[index];
	}
	void display(HWND hwnd){
		HDC hdc = GetDC(hwnd);
		HDC idc = CreateCompatibleDC(hdc);
		SelectObject(idc,(HBITMAP)animation[currentframe]);
		BitBlt(hdc,x,y,width[currentframe],height[currentframe],idc,0,0,SRCCOPY);
		DeleteDC(idc);
		lastupdate = GetTickCount();
		if(currentframe < animation.size()){
			currentframe++;
		}
		else{
			currentframe = 0;
			active = false;
		}
	}
};
cAnimate boom;
class cMap{
private:
	int width;
	int height;
	int mousex;
	int mousey;
	vector<cPlayer> players;
	int currentplayer;
public:
	int getwidth(){
		return width;
	}
	int getheight(){
		return height;
	}
	cMap(){
		width = 500;
		height = 500;
		currentplayer = 1; 
	}
	cMap(int newwidth,int newheight){
		width = newwidth;
		height = newheight;
		currentplayer = 1;
	}
	void setMouse(int x, int y){
		mousex = x;
		mousey = y;
	}
	int getMouseX(){
		return mousex;
	}
	int getMouseY(){
		return mousey;
	}
	void moveplayer(int direction);
	void addplayer(cPlayer newplayer);
	void removeplayer(int index);
	void display(HWND hwnd);
	int didcollide(cPlayer player1,cPlayer player2);
	void isClicked(cPlayer player);
	cPlayer getPlayer(int playerid);
};
class cPlayer{
private:
	int x;
	int y;
	int life;
	string name;
	HBITMAP visual;
public:
	int getX(){
		return x;
	}
	int getY(){
		return y;
	}
	HBITMAP getVisual(){
		return visual;
	}
	string getName(){
		return name;
	}
	void setX(int newx){
		x = newx;
	}
	void setY(int newy){
		y = newy;
	}
	void setVisual(HBITMAP newbitmap){
		visual = newbitmap;
	}
	cPlayer(){
		visual = (HBITMAP)LoadImage(0,"defaultplayer.bmp",IMAGE_BITMAP,50,50,LR_LOADFROMFILE);
		x = 0;
		y = 0;
		name = "default";
		life = 100;
	}
	cPlayer(int startx,int starty,string newname){
		visual = (HBITMAP)LoadImage(0,"defaultplayer.bmp",IMAGE_BITMAP,50,50,LR_LOADFROMFILE);
		x = startx;
		y = starty;
		name = newname;
		life = 100;
	}
	cPlayer(HBITMAP hbitmap){
		visual = hbitmap;
		x = 0;
		y = 0;
		name = "default";
		life = 100;
	}
	cPlayer(HBITMAP hbitmap,int startx,int starty){
		visual = hbitmap;
		x = startx;
		y = starty;
		name = "default";
		life = 100;
	}
	void display(HWND hwnd){
		HDC hdc = GetDC(hwnd);
		HDC idc = CreateCompatibleDC(hdc);
		SelectObject(idc,visual);
		BitBlt(hdc,x,y,50,50,idc,0,0,SRCCOPY);
		ostringstream text;
		text<<life;
		TextOut(hdc,x-15,y-70,"--------------",14);
		TextOut(hdc,x-17,y-70,"+",1);
		TextOut(hdc,x-17,y-40,"+",1);
		TextOut(hdc,x-17,y-60,"+",1);
		TextOut(hdc,x,y-40,text.str().c_str(),text.str().size());
		TextOut(hdc,x,y-60,name.c_str(),name.size());
		DeleteDC(idc);
		SetPixel(hdc,500,500,RGB(255,0,0));
	}
};
cMap cmap;
bool done = false;
cPlayer player4(400,400,"DAVID");
LRESULT CALLBACK WndProc(HWND hwnd,UINT iMsg,WPARAM wParam,LPARAM lParam){
	switch(iMsg){
	case WM_DESTROY:
		PostQuitMessage(0);
		done = true;
		return 0;
		break;
	case WM_LBUTTONDOWN:
		cmap.setMouse(LOWORD(lParam),HIWORD(lParam));
		cmap.isClicked(cmap.getPlayer(2));
		break;
	case WM_KEYDOWN:
		RECT rect;
		HDC hdc = GetDC(hwnd);
		GetWindowRect(hwnd,&rect);
		FillRect(hdc,&rect,(HBRUSH)GetStockObject(WHITE_BRUSH));
		switch(wParam){
		case VK_LEFT:
			cmap.moveplayer(1);
			break;
		case VK_RIGHT:
			cmap.moveplayer(2);
			break;
		case VK_UP:
			cmap.moveplayer(3);
			break;
		case VK_DOWN:
			cmap.moveplayer(4);
			break;
		}
		cmap.display(hwnd);
		break;
	}
	return DefWindowProc(hwnd,iMsg,wParam,lParam);
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hpInstance,PSTR cmdLine,int iCmd){
	HWND hwnd;
	MSG msg;
	WNDCLASS wc;
	wc.cbClsExtra = NULL;
	wc.cbWndExtra = NULL;
	wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
	wc.hCursor = LoadCursor(NULL,IDC_ARROW);
	wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
	wc.hInstance = hInstance;
	wc.lpfnWndProc = WndProc;
	wc.lpszClassName = "cory";
	wc.lpszMenuName = NULL;
	wc.style = CS_VREDRAW|CS_HREDRAW;
	RegisterClass(&wc);
	hwnd = CreateWindow("cory","window",WS_OVERLAPPEDWINDOW,0,0,800,600,NULL,NULL,hInstance,NULL);
	ShowWindow(hwnd,iCmd);
	UpdateWindow(hwnd);
	cPlayer player(200,200,"Kara");
	cPlayer player2(300,300,"Cory");
	cPlayer player3(400,400,"Alex");
	
	cmap.addplayer(player);
	cmap.addplayer(player2);
	cmap.addplayer(player3);
	boom.addFrame((HBITMAP)LoadImage(0,"boom1.bmp",IMAGE_BITMAP,50,50,LR_LOADFROMFILE),50,50);
	boom.addFrame((HBITMAP)LoadImage(0,"boom2.bmp",IMAGE_BITMAP,100,100,LR_LOADFROMFILE),100,100);
	boom.addFrame((HBITMAP)LoadImage(0,"boom3.bmp",IMAGE_BITMAP,150,150,LR_LOADFROMFILE),150,150);

	while(!done){
		if(boom.isActive()){
			int ticker = GetTickCount();
			if(boom.getLastUpdate() + boom.getFrameTime() < ticker){
				boom.display(hwnd);
			}
		}
		if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)){
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else{
		}
	}
	UnregisterClass("cory",hInstance);
	return 0;
}
void cMap::display(HWND hwnd){
	HDC hdc = GetDC(hwnd);
	for(int i = 0; i <= players.size()-1;i++){
		for(int j = 0; j <= players.size()-1;j++){
			if(cmap.didcollide(players,players[j]) == 1 && i != j){
				int diffx;
				int diffy;
				int boomx;
				int boomy;
				if(players.getX() >= players[j].getX()){
					diffx = players.getX() - players[j].getX();
					boomx = players[j].getX() + (diffx/2);
					boom.setX(boomx);
				}
				else{
					diffx = players[j].getX() - players.getX();
					boomx = players.getX() + (diffx/2);
					boom.setX(boomx);
				}
				if(players.getY() >= players[j].getY()){
					diffy = players.getY() - players[j].getY();
					boomy = players[j].getY() + (diffy/2);
					boom.setY(boomy);
				}
				else{
					diffy = players[j].getY() - players.getY();
					boomy = players.getY() + (diffy/2);
					boom.setY(boomy);
				}
				cmap.removeplayer(i);
				cmap.removeplayer(j-1);
				boom.activate();
				
			}
		}
	}
	ostringstream os;
	os<<currentplayer+1;
	TextOut(hdc,10,10,"Player ",7);
	TextOut(hdc,60,10,os.str().c_str(),os.str().size());
	int countdown = players.size()-1;
	while(countdown >= 0){
		players[countdown].display(hwnd);
		countdown--;
	}
}
void cMap::addplayer(cPlayer newplayer){
	players.push_back(newplayer);
}
void cMap::moveplayer(int direction){
	if(direction == 1){
		players[currentplayer].setX(players[currentplayer].getX()-10);
	}
	if(direction == 2){
		players[currentplayer].setX(players[currentplayer].getX()+10);
	}
	if(direction == 3){
		players[currentplayer].setY(players[currentplayer].getY()-10);
	}
	if(direction == 4){
		players[currentplayer].setY(players[currentplayer].getY()+10);
	}
	if(currentplayer >= players.size() -1){
		currentplayer = 0;
	}
	else{
		currentplayer++;
	}
}
int cMap::didcollide(cPlayer player1,cPlayer player2){
		int left1,left2;
		int right1,right2;
		int top1,top2;
		int bottom1,bottom2;
		left1 = player1.getX();
		left2 = player2.getX();
		right1 = player1.getX() + 50;
		right2 = player2.getX() + 50;
		top1 = player1.getY();
		top2 = player2.getY();
		bottom1 = player1.getY() + 50;
		bottom2 = player2.getY() + 50;
		if (bottom1 < top2) return(0);
		if (top1 > bottom2) return(0);
		if (right1 < left2) return(0);
		if (left1 > right2) return(0);
		return 1;
}
void cMap::isClicked(cPlayer player){
	if(player.getX() <= mousex && player.getX() + 50 >= mousex){
		if(player.getY() <= mousey && player.getY() + 50 >= mousey){//400,400
			MessageBox(NULL,"OMG CLICKED!","CLICK!",MB_OK);
		}
	}
}
cPlayer cMap::getPlayer(int playerid){
	return players[playerid];
}
void cMap::removeplayer(int index){
	players.erase(players.begin()+index);
}

Thanks for your input, -CORY
Favorite Quotes:Gandalf: You cannot pass!|Smeagol: We don't need you!|Sloth: Hey you guys!|
Advertisement
Looks ok to me. What kinda game is this going to be?
It is going to be possibly a zelda type game :-)
-CORY
Favorite Quotes:Gandalf: You cannot pass!|Smeagol: We don't need you!|Sloth: Hey you guys!|
You're really going to want to stick all those classes and functions and whatnot into separate files. This is a good article on such things.
Ok yikes i tried to do what you told me and i got errors >.< At first i had 200+ errors i got it down to 11. Do you think you can help me? Heres the sources:
player.h:
#include<string>#include<windows.h>#include<sstream>using namespace std;class cPlayer{private:	int x;	int y;	int life;	string name;	HBITMAP visual;public:	int getX();	int getY();	HBITMAP getVisual();	string getName();	void setX(int newx);	void setY(int newy);	void setVisual(HBITMAP newbitmap);	cPlayer();	cPlayer(int startx,int starty,string newname);	cPlayer(HBITMAP hbitmap);	cPlayer(HBITMAP hbitmap,int startx,int starty);	void display(HWND hwnd);};

player.cpp:
#include"Player.h"void cPlayer::display(HWND hwnd){	HDC hdc = GetDC(hwnd);	HDC idc = CreateCompatibleDC(hdc);	SelectObject(idc,visual);	BitBlt(hdc,x,y,50,50,idc,0,0,SRCCOPY);	ostringstream text;	text<<life;	TextOut(hdc,x-15,y-70,"--------------",14);	TextOut(hdc,x-17,y-70,"+",1);	TextOut(hdc,x-17,y-40,"+",1);	TextOut(hdc,x-17,y-60,"+",1);	TextOut(hdc,x,y-40,text.str().c_str(),text.str().size());	TextOut(hdc,x,y-60,name.c_str(),name.size());	DeleteDC(idc);	SetPixel(hdc,500,500,RGB(255,0,0));}cPlayer::cPlayer(HBITMAP hbitmap,int startx,int starty){	visual = hbitmap;	x = startx;	y = starty;	name = "default";	life = 100;}cPlayer::cPlayer(HBITMAP hbitmap){	visual = hbitmap;	x = 0;	y = 0;	name = "default";	life = 100;}cPlayer::cPlayer(int startx,int starty,string newname){	visual = (HBITMAP)LoadImage(0,"defaultplayer.bmp",IMAGE_BITMAP,50,50,LR_LOADFROMFILE);	x = startx;	y = starty;	name = newname;	life = 100;}cPlayer::cPlayer(){	visual = (HBITMAP)LoadImage(0,"defaultplayer.bmp",IMAGE_BITMAP,50,50,LR_LOADFROMFILE);	x = 0;	y = 0;	name = "default";	life = 100;}void cPlayer::setVisual(HBITMAP newbitmap){	visual = newbitmap;}int cPlayer::getX(){	return x;}int cPlayer::getY(){	return y;}HBITMAP cPlayer::getVisual(){	return visual;}string cPlayer::getName(){	return name;}void cPlayer::setX(int newx){	x = newx;}void cPlayer::setY(int newy){	y = newy;}

map.h:
#include<vector>#include"player.h"using namespace std;class cMap{private:	int width;	int height;	int mousex;	int mousey;	vector<cPlayer> players;	int currentplayer;public:	int getwidth();	int getheight();	cMap();	cMap(int newwidth,int newheight);	void setMouse(int x, int y);	int getMouseX();	int getMouseY();	void moveplayer(int direction);	void addplayer(cPlayer newplayer);	void removeplayer(int index);	void display(HWND hwnd);	int didcollide(cPlayer player1,cPlayer player2);	void isClicked(cPlayer player);	cPlayer getPlayer(int playerid);};

map.cpp:
#include"map.h"int cMap::getwidth(){	return width;}int cMap::getheight(){	return height;}cMap::cMap(){	width = 500;	height = 500;	currentplayer = 1; }cMap::cMap(int newwidth,int newheight){	width = newwidth;	height = newheight;	currentplayer = 1;}void cMap::setMouse(int x, int y){	mousex = x;	mousey = y;}int cMap::getMouseX(){	return mousex;}int cMap::getMouseY(){	return mousey;}void cMap::display(HWND hwnd){	HDC hdc = GetDC(hwnd);	for(int i = 0; i <= players.size()-1;i++){		for(int j = 0; j <= players.size()-1;j++){			if(cmap.didcollide(players,players[j]) == 1 && i != j){				int diffx;				int diffy;				int boomx;				int boomy;				if(players.getX() >= players[j].getX()){					diffx = players.getX() - players[j].getX();					boomx = players[j].getX() + (diffx/2);					boom.setX(boomx);				}				else{					diffx = players[j].getX() - players.getX();					boomx = players.getX() + (diffx/2);					boom.setX(boomx);				}				if(players.getY() >= players[j].getY()){					diffy = players.getY() - players[j].getY();					boomy = players[j].getY() + (diffy/2);					boom.setY(boomy);				}				else{					diffy = players[j].getY() - players.getY();					boomy = players.getY() + (diffy/2);					boom.setY(boomy);				}				cmap.removeplayer(i);				cmap.removeplayer(j-1);				boom.activate();							}		}	}	ostringstream os;	os<<currentplayer+1;	TextOut(hdc,10,10,"Player ",7);	TextOut(hdc,60,10,os.str().c_str(),os.str().size());	int countdown = players.size()-1;	while(countdown >= 0){		players[countdown].display(hwnd);		countdown--;	}}void cMap::addplayer(cPlayer newplayer){	players.push_back(newplayer);}void cMap::moveplayer(int direction){	if(direction == 1){		players[currentplayer].setX(players[currentplayer].getX()-10);	}	if(direction == 2){		players[currentplayer].setX(players[currentplayer].getX()+10);	}	if(direction == 3){		players[currentplayer].setY(players[currentplayer].getY()-10);	}	if(direction == 4){		players[currentplayer].setY(players[currentplayer].getY()+10);	}	if(currentplayer >= players.size() -1){		currentplayer = 0;	}	else{		currentplayer++;	}}int cMap::didcollide(cPlayer player1,cPlayer player2){	int left1,left2;	int right1,right2;	int top1,top2;	int bottom1,bottom2;	left1 = player1.getX();	left2 = player2.getX();	right1 = player1.getX() + 50;	right2 = player2.getX() + 50;	top1 = player1.getY();	top2 = player2.getY();	bottom1 = player1.getY() + 50;	bottom2 = player2.getY() + 50;	if (bottom1 < top2) return(0);	if (top1 > bottom2) return(0);	if (right1 < left2) return(0);	if (left1 > right2) return(0);	return 1;}void cMap::isClicked(cPlayer player){	if(player.getX() <= mousex && player.getX() + 50 >= mousex){		if(player.getY() <= mousey && player.getY() + 50 >= mousey){//400,400			MessageBox(NULL,"OMG CLICKED!","CLICK!",MB_OK);		}	}}cPlayer cMap::getPlayer(int playerid){	return players[playerid];}void cMap::removeplayer(int index){	players.erase(players.begin()+index);}

animate.h:
#include<vector>#include<windows.h>using namespace std;class cAnimate{private:	vector <HBITMAP>animation;	bool active;	int currentframe;	int frametime;	int lastupdate;	int x;	int y;	vector <int>width;	vector <int>height;public:	cAnimate();	int getLastUpdate();	int getFrameTime();	void addFrame(HBITMAP newframe,int newwidth,int newheight);	void removeFrame(int index);	void activate();	bool isActive();	int getCurrentFrame();	void setX(int newx);	void setY(int newy);	int getX();	int getY();	int getWidth(int index);	int getHeight(int index);	void display(HWND hwnd);};

animate.cpp:
#include"animate.h"cAnimate::cAnimate(){	active = false;	currentframe = 0;	frametime = 300;	lastupdate = GetTickCount();}int cAnimate::getLastUpdate(){	return lastupdate;}int cAnimate::getFrameTime(){	return frametime;}void cAnimate::addFrame(HBITMAP newframe,int newwidth,int newheight){	animation.push_back(newframe);	width.push_back(newwidth);	height.push_back(newheight);}void cAnimate::removeFrame(int index){	animation.erase(animation.begin() + index);}void cAnimate::activate(){	active = true;}bool cAnimate::isActive(){	return active;}int cAnimate::getCurrentFrame(){	return currentframe;}void cAnimate::setX(int newx){	x = newx;}void cAnimate::setY(int newy){	y = newy;}int cAnimate::getX(){	return x;}int cAnimate::getY(){	return y;}int cAnimate::getWidth(int index){	return width[index];}int cAnimate::getHeight(int index){	return height[index];}void cAnimate::display(HWND hwnd){	HDC hdc = GetDC(hwnd);	HDC idc = CreateCompatibleDC(hdc);	SelectObject(idc,(HBITMAP)animation[currentframe]);	BitBlt(hdc,x,y,width[currentframe],height[currentframe],idc,0,0,SRCCOPY);	DeleteDC(idc);	lastupdate = GetTickCount();	if(currentframe < animation.size()){		currentframe++;	}	else{		currentframe = 0;		active = false;	}}

main.cpp:
#include<windows.h>#include<vector>#include<string>#include<sstream>#include"animate.h"#include"map.h"#include"player.h"using namespace std;cAnimate boom;cMap cmap;bool done = false;cPlayer player4(400,400,"DAVID");LRESULT CALLBACK WndProc(HWND hwnd,UINT iMsg,WPARAM wParam,LPARAM lParam){	switch(iMsg){	case WM_DESTROY:		PostQuitMessage(0);		done = true;		return 0;		break;	case WM_LBUTTONDOWN:		cmap.setMouse(LOWORD(lParam),HIWORD(lParam));		cmap.isClicked(cmap.getPlayer(2));		break;	case WM_KEYDOWN:		RECT rect;		HDC hdc = GetDC(hwnd);		GetWindowRect(hwnd,&rect);		FillRect(hdc,&rect,(HBRUSH)GetStockObject(WHITE_BRUSH));		switch(wParam){		case VK_LEFT:			cmap.moveplayer(1);			break;		case VK_RIGHT:			cmap.moveplayer(2);			break;		case VK_UP:			cmap.moveplayer(3);			break;		case VK_DOWN:			cmap.moveplayer(4);			break;		}		cmap.display(hwnd);		break;	}	return DefWindowProc(hwnd,iMsg,wParam,lParam);}int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hpInstance,PSTR cmdLine,int iCmd){	HWND hwnd;	MSG msg;	WNDCLASS wc;	wc.cbClsExtra = NULL;	wc.cbWndExtra = NULL;	wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);	wc.hCursor = LoadCursor(NULL,IDC_ARROW);	wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);	wc.hInstance = hInstance;	wc.lpfnWndProc = WndProc;	wc.lpszClassName = "cory";	wc.lpszMenuName = NULL;	wc.style = CS_VREDRAW|CS_HREDRAW;	RegisterClass(&wc);	hwnd = CreateWindow("cory","window",WS_OVERLAPPEDWINDOW,0,0,800,600,NULL,NULL,hInstance,NULL);	ShowWindow(hwnd,iCmd);	UpdateWindow(hwnd);	cPlayer player(200,200,"Kara");	cPlayer player2(300,300,"Cory");	cPlayer player3(400,400,"Alex");		cmap.addplayer(player);	cmap.addplayer(player2);	cmap.addplayer(player3);	boom.addFrame((HBITMAP)LoadImage(0,"boom1.bmp",IMAGE_BITMAP,50,50,LR_LOADFROMFILE),50,50);	boom.addFrame((HBITMAP)LoadImage(0,"boom2.bmp",IMAGE_BITMAP,100,100,LR_LOADFROMFILE),100,100);	boom.addFrame((HBITMAP)LoadImage(0,"boom3.bmp",IMAGE_BITMAP,150,150,LR_LOADFROMFILE),150,150);	while(!done){		if(boom.isActive()){			int ticker = GetTickCount();			if(boom.getLastUpdate() + boom.getFrameTime() < ticker){				boom.display(hwnd);			}		}		if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)){			TranslateMessage(&msg);			DispatchMessage(&msg);		}		else{		}	}	UnregisterClass("cory",hInstance);	return 0;}

Finally the 11 errors:
--------------------Configuration: New - Win32 Debug--------------------Compiling...main.cppc:\program files\microsoft visual studio\myprojects\new\player.h(5) : error C2011: 'cPlayer' : 'class' type redefinitionMap.cppC:\Program Files\Microsoft Visual Studio\MyProjects\New\Map.cpp(32) : error C2065: 'cmap' : undeclared identifierC:\Program Files\Microsoft Visual Studio\MyProjects\New\Map.cpp(32) : error C2228: left of '.didcollide' must have class/struct/union typeC:\Program Files\Microsoft Visual Studio\MyProjects\New\Map.cpp(40) : error C2065: 'boom' : undeclared identifierC:\Program Files\Microsoft Visual Studio\MyProjects\New\Map.cpp(40) : error C2228: left of '.setX' must have class/struct/union typeC:\Program Files\Microsoft Visual Studio\MyProjects\New\Map.cpp(45) : error C2228: left of '.setX' must have class/struct/union typeC:\Program Files\Microsoft Visual Studio\MyProjects\New\Map.cpp(50) : error C2228: left of '.setY' must have class/struct/union typeC:\Program Files\Microsoft Visual Studio\MyProjects\New\Map.cpp(55) : error C2228: left of '.setY' must have class/struct/union typeC:\Program Files\Microsoft Visual Studio\MyProjects\New\Map.cpp(57) : error C2228: left of '.removeplayer' must have class/struct/union typeC:\Program Files\Microsoft Visual Studio\MyProjects\New\Map.cpp(58) : error C2228: left of '.removeplayer' must have class/struct/union typeC:\Program Files\Microsoft Visual Studio\MyProjects\New\Map.cpp(59) : error C2228: left of '.activate' must have class/struct/union typeError executing cl.exe.New.exe - 11 error(s), 0 warning(s)

Thanks a lot for whatever help u can give me.
-Cory Fisher

[Edited by - SSJCORY on June 24, 2005 10:57:22 AM]
Favorite Quotes:Gandalf: You cannot pass!|Smeagol: We don't need you!|Sloth: Hey you guys!|
Your code is very hard to read. Try putting some space between lines in appropriate places (such as between functions).

Also, in your cMap::display function, you do the following:
if(cmap.didcollide(...
and..
cmap.removeplayer(i);cmap.removeplayer(j-1);

Clearly you really shouldn't be doing that [smile]
You'd probably have found that one yourself when you seperate your code in to different files.

Sorry for double post but the one above is rather cluttered. I got it down to 1 error by taking cMap::display and putting it after main bc it has an instance of the cmap class in it.
The only error i get now is class cPlayer class redefenition in player.h and map.h
-Cory Fisher
EDIT heh i didnt double post but ya i figured that out just as u were posting i was posting lol. Now the only error is redefenition cuz i have to #include"player.h" in both player.cpp and map.h any ideas?
Favorite Quotes:Gandalf: You cannot pass!|Smeagol: We don't need you!|Sloth: Hey you guys!|
You'll need to put inclusion guards in your header files. The link provided to you by load_bitmap_file does cover them on this page.

Oh and your cMap::display function shouldn't have had a reference to an instance of the cMap class in it because display would be called by that instance of the class anyway.

Instead of
if(cmap.didcollide(...
that I pointed out earlier it should just be
if(didcollide(...
and the same for all the other references to cmap in that function.
Thanks for all your help mrp :-D u helped me greatly now i'm all organized :-D It took me a few to figure out inclusion guards but they are very usefull :-D
Thanks a lot bro,
COry
Favorite Quotes:Gandalf: You cannot pass!|Smeagol: We don't need you!|Sloth: Hey you guys!|
Now i'm trying to make it so that my cMap::display method can be defined in map.cpp instead of main. But my animation boom. is created in main which is used in cmap::display. I tried putting inside animation.h }boom; and now i get weird evil looking linker errors.
here they are:
--------------------Configuration: New - Win32 Debug--------------------Compiling...Map.cppmain.cppLinking...Map.obj : error LNK2005: "class cAnimate boom" (?boom@@3VcAnimate@@A) already defined in main.objAnimate.obj : error LNK2005: "class cAnimate boom" (?boom@@3VcAnimate@@A) already defined in main.objMap.obj : error LNK2005: "class cAnimate boom" (?boom@@3VcAnimate@@A) already defined in main.objAnimate.obj : error LNK2005: "class cAnimate boom" (?boom@@3VcAnimate@@A) already defined in main.objDebug/New.exe : fatal error LNK1169: one or more multiply defined symbols foundError executing link.exe.New.exe - 5 error(s), 0 warning(s)

i'm scared lol
-Cory
Favorite Quotes:Gandalf: You cannot pass!|Smeagol: We don't need you!|Sloth: Hey you guys!|

This topic is closed to new replies.

Advertisement