Demo ready

Published July 22, 2007
Advertisement
Right, the path finding is implemented, so time for the first demo.

First up a screenshot to make the post look pretty.



Demo is HERE. Just click on a square for the character to find the fastest route there, uncovering the fog as he moves.

Press Alt+F4 to exit.

Give it a test, although should be fine.

Here's the source for the path finding.

(BTW, CVector<> is just a little wrapper for std::vector<> that throws one of my game exceptions on a subscript out of range. Don't want anyone to think I'm writing my own vector class [smile]).

bool CPath::Target(int Ox,int Oy,int Tx,int Ty){	CVector Vc,Vn;	Steps.clear();	Pos=0;	if(Ox==Tx && Oy==Ty) return true;	if(!Open(Tx,Ty)) return false;	Grid.Fill(INT_MAX);	Grid(Tx,Ty)=0;	Vc.push_back(CPoint(Tx,Ty));		int Value=0;	bool Found=false;	while(Vc.size())		{		for(std::vector::iterator I=Vc.begin();I!=Vc.end();++I)			{			int X=I->X;			int Y=I->Y;			if(Grid(X,Y)==Value)				{				if(Y>0 && Open(X,Y-1) && Grid(X,Y-1)==INT_MAX){ Grid(X,Y-1)=Value+1; Vn.push_back(CPoint(X,Y-1)); }				if(X1
&& Open(X+1,Y) && Grid(X+1,Y)==INT_MAX){ Grid(X+1,Y)=Value+1; Vn.push_back(CPoint(X+1,Y)); }
if(Y1 && Open(X,Y+1) && Grid(X,Y+1)==INT_MAX){ Grid(X,Y+1)=Value+1; Vn.push_back(CPoint(X,Y+1)); }
if(X>0 && Open(X-1,Y) && Grid(X-1,Y)==INT_MAX){ Grid(X-1,Y)=Value+1; Vn.push_back(CPoint(X-1,Y)); }
}
}

Vc.swap(Vn);
Vn.clear();

++Value;

if(Grid(Ox,Oy)!=INT_MAX){ Vc.clear(); Found=true; }
}

if(!Found) return false;

int X=Ox,Y=Oy;
bool Finished=false;

while(!Finished)
{
int Min=INT_MAX;

if(Grid(X-1,Y-1)<=Min && Open(X-1,Y) && Open(X,Y-1)) Min=Grid(X-1,Y-1);
if(Grid(X+1,Y-1)<=Min && Open(X+1,Y) && Open(X,Y-1)) Min=Grid(X+1,Y-1);
if(Grid(X-1,Y+1)<=Min && Open(X-1,Y) && Open(X,Y+1)) Min=Grid(X-1,Y+1);
if(Grid(X+1,Y+1)<=Min && Open(X+1,Y) && Open(X,Y+1)) Min=Grid(X+1,Y+1);

if(Grid(X,Y-1)<=Min) Min=Grid(X,Y-1);
if(Grid(X+1,Y)<=Min) Min=Grid(X+1,Y);
if(Grid(X,Y+1)<=Min) Min=Grid(X,Y+1);
if(Grid(X-1,Y)<=Min) Min=Grid(X-1,Y);

CVector Choices;

if(Grid(X-1,Y-1)==Min) Choices.push_back(CPoint(-1,-1));
if(Grid(X+1,Y-1)==Min) Choices.push_back(CPoint(1,-1));
if(Grid(X-1,Y+1)==Min) Choices.push_back(CPoint(-1,1));
if(Grid(X+1,Y+1)==Min) Choices.push_back(CPoint(1,1));

if(Grid(X,Y-1)==Min) Choices.push_back(CPoint(0,-1));
if(Grid(X+1,Y)==Min) Choices.push_back(CPoint(1,0));
if(Grid(X,Y+1)==Min) Choices.push_back(CPoint(0,1));
if(Grid(X-1,Y)==Min) Choices.push_back(CPoint(-1,0));

CPoint Pt=Choices[std::rand()%Choices.size()];

Steps.push_back(Pt);

X+=Pt.X;
Y+=Pt.Y;

if(X==Tx && Y==Ty) Finished=true;
}

return true;
}






Any comments on the demo appreciated.
Previous Entry Bit of progress
Next Entry FOV
0 likes 5 comments

Comments

Sir Sapo
Thats a pretty cool little demo, I like the style, it reminds me of playing Warlocked on my GameBoy Color back in the day[grin]

July 22, 2007 01:54 PM
ukdm
I only found one problem with the demo. You can click to move the knight somewhere on the map and he doesn't respond. This is because you can click on a tree and he obviously won't move there, but it means the clicking to move doesn't always give you a result.

My suggestion is make the fog of war still display the basic map layout but hide any enemies or buildings until you uncover them. Not sure how that fits with your gameplay though, or how easy it would be to do.

Nice start, I am watching with interest as it develops. Good luck finding work for next month, agency work is very boring but pays the bills.
July 22, 2007 01:57 PM
diablo_tk
Quote:Original post by ukdm
I only found one problem with the demo. You can click to move the knight somewhere on the map and he doesn't respond. This is because you can click on a tree and he obviously won't move there, but it means the clicking to move doesn't always give you a result.

My suggestion is make the fog of war still display the basic map layout but hide any enemies or buildings until you uncover them. Not sure how that fits with your gameplay though, or how easy it would be to do.

Nice start, I am watching with interest as it develops. Good luck finding work for next month, agency work is very boring but pays the bills.


Noticed that to. Mabey make it move to a tile near a blocked one.
July 22, 2007 03:44 PM
dcosborn
I enjoyed the demo as well. Nice and smooth.
July 22, 2007 03:45 PM
Aardvajk
Good ideas. I'll have to have a think about that.

Later in development, the idea is that clicking on the fog won't accept a move, so you can only click where you have uncovered.

Whether that will solve the problem, or whether clicking on a tree should make you move as close as possible I don't know.
July 22, 2007 04:57 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement