Page 1 of 1

help with changing actors linear paths

PostPosted: Sat Jul 09, 2011 1:48 pm
by foleyjo
Just need a bit of help. Not sure if the title explains it correctly :lol:

I have cloned actors (Maximum of 10 on screen at once) which start at 1 point and travel in a straight line till they get to an end point and then they are destroyed. (simple yeah)

When an arrow key is pressed the actor needs to move in the appropriate direction. This in turn makes the end point of the line move forming a new line for the actor to follow.

Now the code I'm doing seems to do this however for no apparent reason (apparent to me that is) it will suddenly stop working and the actors won't change position on the key press.

I'm also unsure if this is the best way of doing this so can someone confirm if I should be using a different method and what that method would be

Code: Select all
char* key = GetKeyState();
Actor * ThisActor
int speed = -2;
int xspeed = 0;
int yspeed = 0;
int Actors = ActorCount("Actor");
int i;

xspeed = (key[KEY_RIGHT]- key[KEY_LEFT]) *speed;
yspeed = (key[KEY_UP]- key[KEY_DOWN]) *speed;

for(i=0; i<Actors;i++)
{
  ThisActor = getclone2("Actor",i);
  ThisActor->x +=xspeed;
  ThisActor->y +=yspeed;
  ThisActor->Actorendx += xspeed;
  ThisActor->Actorendy += yspeed;
  ThisActor->angle = direction(ThisActor->x, ThisActor->y, ThisActor->Actorendx,  ThisActor->Actorendy);
}