help with changing actors linear paths

Non-platform specific questions.

help with changing actors linear paths

Postby foleyjo » Sat Jul 09, 2011 1:48 pm

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);
}
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest