• entries
    743
  • comments
    1924
  • views
    578649

Demo ready

Sign in to follow this  
Aardvajk

89 views

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.
Sign in to follow this  


5 Comments


Recommended Comments

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]

Share this comment


Link to comment
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.

Share this comment


Link to comment
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.

Share this comment


Link to comment
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.

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now