Page 1 of 1

Handling a party system

Posted: Tue Dec 07, 2010 9:44 am
by N64vSNES
Kay dudes, I need some advice.

EQ Is a party based RPG and up until now it been really fucked up because I'm trying to clone Chrono Triggers following system where you controle one party member and the rest of them follow your every footstep.

At first I didn't mind if it wasn't 100% exact but the issue is that if they don't retrace your every step then they can get stuck behind walls and stuff.

So does anybody know how I should go about implementing somthing like this?

Re: Handling a party system

Posted: Tue Dec 07, 2010 12:00 pm
by avansc
Its rather ugly but works, also this does shortest path following and not actual path.

Code: Select all

#ifndef _cCharacter_h
#define _cCharacter_h

#include <stdlib.h>
#include <GLUT/GLUT.h>

#include "cEntity.h"

class cCharacter : cEntity
{
public:
	cCharacter()
	{
		this->col[0] = 1;
		this->col[1] = 1;
		this->col[2] = 1;
		this->follow = NULL;
	}
	
	cCharacter(cPoint loc)
	: cEntity(loc)
	{
		this->col[0] = 1;
		this->col[1] = 1;
		this->col[2] = 1;
		this->follow = NULL;
	}
	
	void chase(cEntity *p)
	{
		this->follow = p;
	}
	
	void update()
	{
		if(this->follow != NULL)
		{
			cPoint vec = cPoint(follow->loc.getX() - this->loc.getX(),follow->loc.getY() - this->loc.getY());
			
			if(vec.length() > 10)
			{
				vec.normalize();
			
				this->loc.setX(this->loc.getX() + vec.getX()*0.01);
				this->loc.setY(this->loc.getY() + vec.getY()*0.01);
			}
			
		}else {
		
		}

	}
	
	void draw()
	{
		glPushMatrix();
		
		glTranslatef(this->loc.getX(), this->loc.getY(), 0);
		glColor3f(0, 1, 0);
		glutSolidSphere(2, 6, 6);
	
		glPopMatrix();
	}
	
private:
	cEntity *follow;
	float col[3];
};

#endif

Re: Handling a party system

Posted: Tue Dec 07, 2010 12:52 pm
by MrDeathNote
avansc wrote:Its rather ugly but works
Certainly not the ugliest code i've ever seen ;)

Re: Handling a party system

Posted: Tue Dec 07, 2010 2:41 pm
by N64vSNES
Ok know i feel retarded :lol:

Thanks avansc I'll see how it goes :)

EDIT: The only thing I can see that is ugly is glut ;)

EDIT EDIT:
Whats the cPoint class? I don't think its delcared anywhere is it just a vector?

Re: Handling a party system

Posted: Tue Dec 07, 2010 3:35 pm
by Falco Girgis
The actual method used in Chrono Trigger is to have a simple static buffer of the last 30 or so previous locations of the party leader and bump each position down a notch when the next position is pushed in (like a queue). Then each of the party members will be positioned at index 15 and 30 (assuming a 30 node queue).

Re: Handling a party system

Posted: Tue Dec 07, 2010 4:55 pm
by avansc
yeap cPoint is just a 2 dim vector, its actually misnamed, I added stuff to it, it really should be called cVec2 or something of that nature. but all the function names should be fairly self explanatory.

Re: Handling a party system

Posted: Wed Dec 08, 2010 7:35 am
by N64vSNES
GyroVorbis wrote:The actual method used in Chrono Trigger is to have a simple static buffer of the last 30 or so previous locations of the party leader and bump each position down a notch when the next position is pushed in (like a queue). Then each of the party members will be positioned at index 15 and 30 (assuming a 30 node queue).
I'd considered this but it seemed like it would only end out a mess but I'll defnitly try it then :)
Thanks.
avansc wrote:yeap cPoint is just a 2 dim vector, its actually misnamed, I added stuff to it, it really should be called cVec2 or something of that nature. but all the function names should be fairly self explanatory.
Thanks I was confused because you were normalizing lol.
Thanks again. :)

EDIT: Holy shit working asif its straight from chrono trigger, your a fucking genius Falco! I must have walked around aimlessly in chrono trigger for houres trying to figure it out. :bow: