Handling a party system

Anything related in any way to game development as a whole is welcome here. Tell us about your game, grace us with your project, show us your new YouTube video, etc.

Moderator: PC Supremacists

Post Reply
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Handling a party system

Post 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?
User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

Re: Handling a party system

Post 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
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
User avatar
MrDeathNote
ES Beta Backer
ES Beta Backer
Posts: 594
Joined: Sun Oct 11, 2009 9:57 am
Current Project: cocos2d-x project
Favorite Gaming Platforms: SNES, Sega Megadrive, XBox 360
Programming Language of Choice: C/++
Location: Belfast, Ireland
Contact:

Re: Handling a party system

Post by MrDeathNote »

avansc wrote:Its rather ugly but works
Certainly not the ugliest code i've ever seen ;)
http://www.youtube.com/user/MrDeathNote1988

Image
Image

"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: Handling a party system

Post 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?
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: Handling a party system

Post 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).
User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

Re: Handling a party system

Post 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.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: Handling a party system

Post 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:
Post Reply