Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Digital Mosaic Games on Tue 19/04/2011 14:12:02

Title: Catch me if you can!
Post by: Digital Mosaic Games on Tue 19/04/2011 14:12:02
Hey AGSers,

my character should be followed continuous by another character. I tried it with "cCharacter1.FollowCharacter(cCharacter2.x, cCharacter2.y, eNoBlock);" but there the following character stopped when my maincharacter stoppen. I want that the stalker walks all the time towards to my character.
"cCharacter1.Walk(cCharacter2.x, cCharacter2.y, eNoBlock, eAnywhere);" made that the followers fac location was ever to the character but he walked on the place and didn't moved.
Does somebody know how to do that?

Thanks!
Title: Re: Catch me if you can!
Post by: Matti on Tue 19/04/2011 14:35:31
cCharacter1.FollowCharacter(cCharacter2.x, cCharacter2.y, eNoBlock);  ???

That didn't give any error message? Isn't it supposed to be

Character.FollowCharacter(Character* chartofollow, optional int dist, optional int eagerness) ?

If you set dist to 0 then the character shouldn't stop until he reaches the other one.

Title: Re: Catch me if you can!
Post by: Khris on Tue 19/04/2011 14:39:44
Yeah, and why isn't this in Beginner's?
Title: Re: Catch me if you can!
Post by: Digital Mosaic Games on Tue 19/04/2011 14:47:04
Quote from: Matti on Tue 19/04/2011 14:35:31
cCharacter1.FollowCharacter(cCharacter2.x, cCharacter2.y, eNoBlock);  ???

That didn't give any error message? Isn't it supposed to be

Character.FollowCharacter(Character* chartofollow, optional int dist, optional int eagerness) ?

If you set dist to 0 then the character shouldn't stop until he reaches the other one.



I just wrote that example quickly down, that you know what I mean. Sorry if that irritated you. I have already tried to set the distance to 0 but there my problem was, that the stalker was just next to him and not in his centre.

Title: Re: Catch me if you can!
Post by: Ali on Tue 19/04/2011 16:18:56
This may be a patronising question... but are both characters standing on the central point of the sprite?
Title: Re: Catch me if you can!
Post by: Digital Mosaic Games on Tue 19/04/2011 18:18:55
Maybe I should have started the thread a bit else. I want that my "hero" has to run away from the "enemy". The enemy wants to kill the hero. So if the stalking enemy catches the hero there should appear an animation how the hero is killed. This animation can appear in 4 different directions(down, keft, right, up). Now lets put aside my first question because maybe this will also be clear with the answer of this question. How can I script that it should happen the specific animation for each direction of the attack. For example if the enemy is "under" the character and is colliding with him and he can look whereever he want. Than it should appear an animation how he looks down and is killed by the enemy. I hope my aim is clear now.

I know that I've got to use the "IsCollidingWithChar"-Event in the repeadly executed funtion. But I don't know how to script these specific areas(down, up...). :-\

This "running away game" isn't something new. Its the same concept like in Gabriel Knight 1. Look! this is what I mean(first minutes):
http://www.youtube.com/watch?v=0SIyPAag_zM
Title: Re: Catch me if you can!
Post by: Khris on Tue 19/04/2011 18:37:19
You need a function to calculate the distance and relative position of the enemy.

pseudocode:

x = enemy.x - player.x;
y = (enemy.y - player.y)*2;   // *2 to compensate for ground perspective

distance = Maths.Sqrt(x*x + y*y);

angle = Maths.RadiansToDegrees(Maths.ArcTan2(y/x));
// angle = -180 - 179.9
// e.g. -45 - 45 -> enemy is to the right of player
Title: Re: Catch me if you can!
Post by: Digital Mosaic Games on Tue 19/04/2011 19:06:30
Quote from: Khris on Tue 19/04/2011 18:37:19
You need a function to calculate the distance and relative position of the enemy.

pseudocode:

x = enemy.x - player.x;
y = (enemy.y - player.y)*2;   // *2 to compensate for ground perspective

distance = Maths.Sqrt(x*x + y*y);

angle = Maths.RadiansToDegrees(Maths.ArcTan2(y/x));
// angle = -180 - 179.9
// e.g. -45 - 45 -> enemy is to the right of player

It's good that we put that to the beginners. ::) With your code I get the idea on how to go this thing on but I don't know where to put these lines in. I tried to define the "x" and the "y" in the first lines but after I noticed that have not enough knowledge to do that. I would be very pleased if you could give me a few more tips. Thanks a lot!

Title: Re: Catch me if you can!
Post by: Khris on Tue 19/04/2011 19:36:48
Your original question very much belonged into Beginner's. (And don't quote the previous post in full.)

The code obviously goes into repeatedly_execute since the distance must be checked all the time.
Plus there are threads about handling this already, with full code examples.

And if you try to do something and it doesn't work, POST YOUR CODE.
Title: Re: Catch me if you can!
Post by: Scarab on Tue 19/04/2011 19:41:36
Quote from: NEON-GAMES on Tue 19/04/2011 19:06:30
Quote from: Khris on Tue 19/04/2011 18:37:19
You need a function to calculate the distance and relative position of the enemy.

pseudocode:

x = enemy.x - player.x;
y = (enemy.y - player.y)*2;   // *2 to compensate for ground perspective

distance = Maths.Sqrt(x*x + y*y);

angle = Maths.RadiansToDegrees(Maths.ArcTan2(y/x));
// angle = -180 - 179.9
// e.g. -45 - 45 -> enemy is to the right of player

It's good that we put that to the beginners. ::) With your code I get the idea on how to go this thing on but I don't know where to put these lines in. I tried to define the "x" and the "y" in the first lines but after I noticed that have not enough knowledge to do that. I would be very pleased if you could give me a few more tips. Thanks a lot!

I'm fairly certain the following should work:


////at top of function////
int x, y;
float distance, angle;

////in room_RepEx()////
x = enemy.x - player.x;
y = (enemy.y - player.y)*2;   // *2 to compensate for ground perspective

distance = Maths.Sqrt(x*x + y*y);

angle = Maths.RadiansToDegrees(Maths.ArcTan2(y, x));
//alternately Maths.RadiansToDegrees(Maths.Arctan(y/x));

if(distance <= 10.0){
   //run attacking function
}

////in whatever function is called for the attack////
if( (angle > 45.0) && (angle <= 135.0) ){
//run animations for direction 1
// ( I believe this would be upwards, and anticlockwise from there,)
}
else if( (angle > 135.0) && (angle <= 225.0) ){
//run animations for direction 2
}
else if( (angle > 225.0) && (angle <= 315.0) ){
//run animations for direction 3
}
else {
//run animations for direction 4
}
//death funciton for player (audio files, restoregame GUIs, etc.)



You wouldn't need to define the variables outside the function if you are calling the entire thing from RepEx(), although the use of functions is far cleaner.

Also note that the Khris' code has a typo in the syntax of Maths.ArcTan2() which takes an x and a y value, rather than a single (y/x) value (which is supported by Maths.ArcTan().
Title: Re: Catch me if you can!
Post by: Digital Mosaic Games on Tue 19/04/2011 20:00:46
Quote from: Scarab on Tue 19/04/2011 19:41:36
Quote from: NEON-GAMES on Tue 19/04/2011 19:06:30
Quote from: Khris on Tue 19/04/2011 18:37:19
You need a function to calculate the distance and relative position of the enemy.

pseudocode:

x = enemy.x - player.x;
y = (enemy.y - player.y)*2;   // *2 to compensate for ground perspective

distance = Maths.Sqrt(x*x + y*y);

angle = Maths.RadiansToDegrees(Maths.ArcTan2(y/x));
// angle = -180 - 179.9
// e.g. -45 - 45 -> enemy is to the right of player

It's good that we put that to the beginners. ::) With your code I get the idea on how to go this thing on but I don't know where to put these lines in. I tried to define the "x" and the "y" in the first lines but after I noticed that have not enough knowledge to do that. I would be very pleased if you could give me a few more tips. Thanks a lot!

I'm fairly certain the following should work:


////at top of function////
int x, y;
float distance, angle;

////in room_RepEx()////
x = enemy.x - player.x;
y = (enemy.y - player.y)*2;   // *2 to compensate for ground perspective

distance = Maths.Sqrt(x*x + y*y);

angle = Maths.RadiansToDegrees(Maths.ArcTan2(y, x));
//alternately Maths.RadiansToDegrees(Maths.Arctan(y/x));

if(distance <= 10.0){
    //run attacking function
}

////in whatever function is called for the attack////
if( (angle > 45.0) && (angle <= 135.0) ){
//run animations for direction 1
// ( I believe this would be upwards, and anticlockwise from there,)
}
else if( (angle > 135.0) && (angle <= 225.0) ){
//run animations for direction 2
}
else if( (angle > 225.0) && (angle <= 315.0) ){
//run animations for direction 3
}
else {
//run animations for direction 4
}
//death funciton for player (audio files, restoregame GUIs, etc.)



You wouldn't need to define the variables outside the function if you are calling the entire thing from RepEx(), although the use of functions is far cleaner.

Also note that the Khris' code has a typo in the syntax of Maths.ArcTan2() which takes an x and a y value, rather than a single (y/x) value (which is supported by Maths.ArcTan().




Well I put
int x, y;
float distance, angle;

on the top of my room script.
x = enemy.x - player.x;
y = (enemy.y - player.y)*2;   // *2 to compensate for ground perspective

distance = Maths.Sqrt(x*x + y*y);

angle = Maths.RadiansToDegrees(Maths.ArcTan2(y, x));
//alternately Maths.RadiansToDegrees(Maths.Arctan(y/x));

if(distance <= 10.0){
    //run attacking function
}

This in the repeatly executed function and the rest in a functon I called "attack".

Now I get an error:

Failed to save room room36.crm; details below
room36.asc(32): Error (line 32): Type mismatch: cannot convert 'int' to 'float'

The line is:
"distance = Maths.Sqrt(x*x + y*y);"

Maybe it has to do sth with "Maths.ArcTan()" but I'm not sure what that is.


Title: Re: Catch me if you can!
Post by: TomatoesInTheHead on Tue 19/04/2011 20:13:55
(As Khris said, please don't quote the full post, only the relevant parts, if any. It's hard to read and spot the new things otherwise)

The error is indeed that AGS cannot convert an int to a float. That is: x and y are integer values, and the Maths functions (here: Sqrt) take floats as input. The functions to convert values are FloatToInt and IntToFloat.
You may either declare x and y as floats instead of ints, and convert the values you store in x and y, or you can leave it as is, and convert x and y to float where you need them as floats (that is, everywhere). Generally, I'd prefer the first option, but it doesn't make much of a difference in this case, as far as I see.
Title: Re: Catch me if you can!
Post by: Khris on Tue 19/04/2011 20:23:36
Here's a distance function:

int GetDistanceFrom(this Character*, Character*c) {

  float dx = IntToFloat(c.x - this.x);
  float dy = IntToFloat(c.y - this.y);

  float dis = Maths.Sqrt(dx*dx + dy*dy);

  return FloatToInt(dis, eRoundNearest);
}


Usage:
  if (player.GetDistanceFrom(cZombie) < 30) ...
Title: Re: Catch me if you can!
Post by: monkey0506 on Tue 19/04/2011 21:37:18
I don't see why he even needs a distance function for this. It seems to me that he wants the character to be constantly chasing after the other, and if they collide, then do something about it. Per the manual:

QuoteCharacter.FollowCharacter

As a special case, setting DIST=0 and EAGERNESS=0 makes CHARID behave as if it is chasing CHARTOFOLLOW - it will try and get there as quickly as possible. Setting EAGERNESS=0 also tells the character not to stop when they reach CHARTOFOLLOW, but instead to randomly wander around the character - useful perhaps for a very energetic dog or something.

So, wouldn't it be as simple as:

cZombie.FollowCharacter(player, 0, 0);

// rep_exec
if (cZombie.IsCollidingWithChar(player))
{
  // attack
}


It doesn't give as fine a level of control, but based on the original request it seems to me that it fits better anyway.
Title: Re: Catch me if you can!
Post by: Digital Mosaic Games on Fri 22/04/2011 00:14:52
Quote from: Khris on Tue 19/04/2011 20:23:36
Here's a distance function:

int GetDistanceFrom(this Character*, Character*c) {

  float dx = IntToFloat(c.x - this.x);
  float dy = IntToFloat(c.y - this.y);

  float dis = Maths.Sqrt(dx*dx + dy*dy);

  return FloatToInt(dis, eRoundNearest);
}


Usage:
  if (player.GetDistanceFrom(cZombie) < 30) ...


I placed your lines at the top of the roomscript. Right?
Than I deletet these first lines because an error appeared:
////in room_RepEx()////
x = enemy.x - player.x;
y = (enemy.y - player.y)*2;   // *2 to compensate for ground perspective

distance = Maths.Sqrt(x*x + y*y);


Now I still get an error. In this line:
angle = Maths.RadiansToDegrees(Maths.ArcTan2(y, x));
There's a undefined symbol 'x'.
Maybe I need another code for "angle". Is that possible? Or it is again because the ints. which can't be readen right? But how can I change it if it is this case?
Title: Re: Catch me if you can!
Post by: Digital Mosaic Games on Fri 22/04/2011 11:53:44
I've made all the kill_animations(4 directions) but I don't know how to go on as I described in my last post. ??? I want to use all this animations so that they are not for nothing. Please help me!!! Thank you so much. I tried it also many times with own methods but they didn't gave me the right aim. My Character was ever just attacked from one side. I think your methods are much better but as I wrote there is this error with the undefined symbol 'x' and I tried to solve it on my own but I noticed that I have not enough knowledge in this part of scripting.
Title: Re: Catch me if you can!
Post by: Sephiroth on Fri 22/04/2011 13:49:00
"Undefined symbol" Output means you probably forgot to declare the mentioned variable. Decalaring x and y is accomplished with this line you must have forgotten in the process:



int x, y;



If you only use x and y inside Attack() then put these lines inside the function, otherwise outside.
Title: Re: Catch me if you can!
Post by: Digital Mosaic Games on Tue 26/04/2011 10:23:12
Quote from: Sephiroth on Fri 22/04/2011 13:49:00
"Undefined symbol" Output means you probably forgot to declare the mentioned variable. Decalaring x and y is accomplished with this line you must have forgotten in the process:



int x, y;



If you only use x and y inside Attack() then put these lines inside the function, otherwise outside.

Thank you but this is not much help. :'( It seems that nothing wants to work. Everytime the same cannot convert int to float error. And I cannot solve this damned error! I tried so many ways but it still doesn't work. Is there someone who could send me a whole script or module for this?? Don't think I'm lazy! I tried my best ever and ever again but I can't handle that. This thing is to difficult for me. This moment would be so beautiful if it works perfectly! :) So I thank everyone who helped me before but there comes an error if thought I solved the error before and I don't really see the point. It would be sooo glad if you could help me again! Thanks alot for your time guys!!!
Title: Re: Catch me if you can!
Post by: Khris on Tue 26/04/2011 10:50:42
A "cannot convert int to float error" is by far the easiest thing to solve.
If you don't post the surrounding piece of code, we can hardly help you though. (Who would've thought?)
Title: Re: Catch me if you can!
Post by: Digital Mosaic Games on Tue 26/04/2011 11:03:00
Quote from: Khris on Tue 26/04/2011 10:50:42
A "cannot convert int to float error" is by far the easiest thing to solve.
If you don't post the surrounding piece of code, we can hardly help you though. (Who would've thought?)

Sorry, of course... Look this is what I got at the moment. There are some parts which I just deleted because the errors. Before I tried to change them but with no good results.

At the top of room script(including distance function by Khris):
int x, y;
int angle;

int GetDistanceFrom(this Character*, Character*c) {

  float dx = IntToFloat(c.x - this.x);
  float dy = IntToFloat(c.y - this.y);

  float dis = Maths.Sqrt(dx*dx + dy*dy);

  return FloatToInt(dis, eRoundNearest);
}


In repeadly execute:
x = cDog.x - player.x;
    y = (cDog.y - player.y)*2; 

    if (player.GetDistanceFrom(cDog) <= 10.0){
    Attack();
}


And in the Attack function(I still havent scripted the animation stuff because this will not be difficult):
  if( (angle > 45.0) && (angle <= 135.0) ){
//run animations for direction 1
// ( I believe this would be upwards, and anticlockwise from there,)
}
else if( (angle > 135.0) && (angle <= 225.0) ){
//run animations for direction 2
}
else if( (angle > 225.0) && (angle <= 315.0) ){
//run animations for direction 3
}
else {
//run animations for direction 4
}
//death funciton for player (audio files, restoregame GUIs, etc.)


Title: Re: Catch me if you can!
Post by: Khris on Tue 26/04/2011 11:13:40
Inside the distance function, add "*2.0":

  float dy = IntToFloat(c.y - this.y)*2.0;

In rep_ex, get rid of the first two lines, you don't need them.
Then change the 10.0 to 10. GetDistanceFrom() is an int, thus you can't compare it to a float.
Title: Re: Catch me if you can!
Post by: Digital Mosaic Games on Tue 26/04/2011 11:41:25
Quote from: Khris on Tue 26/04/2011 11:13:40
Inside the distance function, add "*2.0":

  float dy = IntToFloat(c.y - this.y)*2.0;

In rep_ex, get rid of the first two lines, you don't need them.
Then change the 10.0 to 10. GetDistanceFrom() is an int, thus you can't compare it to a float.

Thank you very much! There are no more errors. But one big fault! :( Like in my own tries before everytime when the enemy catches my character(from every direction/angle) there just appears the same animation(my player faces right and is attacked from the enemy who comes from the right). I thought maybe it's because the view of the enemy. So I changed his view to the same like the players. But still the same fault! I set the distance from 10 to 5. I also tried this: player.Solid=false. But no changes.  :-\
I'm not really sure if it is a scripting or maybe a "graphical" fault.  ???

Now this is my Attack script:


if( (angle > 45) && (angle <= 135) ){
    cJohn.FaceLocation(cJohn.x, cJohn.y-100);//UP
    Wait(30);
    cJohn.LockView(36);
    cJohn.ManualScaling=true;
    cJohn.Scaling=100;
    cDog.ChangeRoom(0);
    cJohn.Animate(107, 3, eOnce, eBlock);
// ( I believe this would be upwards, and anticlockwise from there,)
}
else if( (angle > 135) && (angle <= 225) ){
cJohn.FaceLocation(cJohn.x-100, cJohn.y);//LEFT
Wait(30);
cJohn.LockView(36);
cJohn.ManualScaling=true;
    cJohn.Scaling=100;
cDog.ChangeRoom(0);
cJohn.Animate(105, 3, eOnce, eBlock);
}
else if( (angle > 225) && (angle <= 315) )
cJohn.FaceLocation(cJohn.x, cJohn.y+100);//DOWN
Wait(30);
cJohn.LockView(36);
cJohn.ManualScaling=true;
    cJohn.Scaling=100;
cDog.ChangeRoom(0);
cJohn.Animate(104, 3, eOnce, eBlock);
}
else {
cJohn.FaceLocation(cJohn.x+100, cJohn.y);//RIGHT
Wait(30);
cJohn.LockView(36);
cJohn.ManualScaling=true;
    cJohn.Scaling=100;
cDog.ChangeRoom(0);
cJohn.Animate(106, 3, eOnce, eBlock);
}
Title: Re: Catch me if you can!
Post by: Khris on Tue 26/04/2011 13:07:46
I'll hazard a wild guess: you aren't calculating the angle anywhere => it stays 0 => the else block (right) is executed every time.

You need to try to understand how and why the code we posted does what it does. It's no use if you blindly paste stuff without knowing what you're doing.
Title: Re: Catch me if you can!
Post by: Digital Mosaic Games on Tue 26/04/2011 13:48:12
Quote from: Khris on Tue 26/04/2011 13:07:46
I'll hazard a wild guess: you aren't calculating the angle anywhere => it stays 0 => the else block (right) is executed every time.

You need to try to understand how and why the code we posted does what it does. It's no use if you blindly paste stuff without knowing what you're doing.

I knew that I need an angle function as I mentioned in one of my posts before and I already tried to script that in a kind of way like your distance function. And I know that the angle is something different and in my opinion more difficult to script as the distance. I understand the script but I think I don't know enough to script an angle function. The distance function is simple(the idea): y1-y2 & x1-x2 but the angle function is to compare something with a clock and which time it shows. I know maybe this sounds like cheese but I just want to tell you that I can't put the idea of the angle function in a script.

Here this was my try:

int GetAngleFrom(Character*c) {
   float ax = IntToFloat(c.x);
   float ay = IntToFloat(c.y);
   
   float angle = Maths.RadiansToDegrees(Maths.ArcTan2(ay, ax));
}
Title: Re: Catch me if you can!
Post by: Khris on Tue 26/04/2011 14:11:07
That's not far off, however you're calculating the angle at (0;0) right now.

To calculate the proper angle, you need to calculate the vector from player to cDog.

This should do it:

int angle;

int GetDistanceFrom(this Character*, Character*c) {

  float dx = IntToFloat(c.x - this.x);
  float dy = IntToFloat(c.y - this.y);

  float dis = Maths.Sqrt(dx*dx + dy*dy);

  angle = FloatToInt(Maths.RadiansToDegrees(Maths.ArcTan2(dy, dx)), eRoundNearest);

  return FloatToInt(dis, eRoundNearest);
}


Now everytime you calculate the distance, the angle is stored in the script's int angle.
Thus as soon as the distance is low enough, you'll automatically have the current angle already stored.
Title: Re: Catch me if you can!
Post by: Digital Mosaic Games on Tue 26/04/2011 15:15:29
Thanks alot man! But I'm sorry that I have to admit that I still have a problem. :-\
At first the animations are now on the right place. It doesn't start with upwards but with right.
No problem but now in the game the enemy ever just attacks my player from 2 sites. Or should I better say there are just two animations which can appear(enemy from RIGHT and DOWN). And if the enemy should normally attack from LEFT he walks down to my player and the same DOWN-animation appears. The same when the enemy shoul usually attack from UP. He goes to the RIGHT and attacks from there. In my opinion the script must usually work. I havent found the fault in it. And believe me I tested a long time and I don't think it's a matter of probability.

Here's my Attack function at the moment:

function Attack()
{
  if( (angle > 45) && (angle <= 135) ){
    cJohn.FaceLocation(cJohn.x-100, cJohn.y);//player faces LEFT
Wait(30);
cJohn.LockView(36);
cJohn.ManualScaling=true;
    cJohn.Scaling=100;
cDog.ChangeRoom(0);
cJohn.Animate(106, 3, eOnce, eBlock);//enemy faces RIGHT
// ( I believe this would be upwards, and anticlockwise from there,)
}
else if( (angle > 135) && (angle <= 225) ){
cJohn.FaceLocation(cJohn.x, cJohn.y-100);//player faces UP
    Wait(30);
    cJohn.LockView(36);
    cJohn.ManualScaling=true;
    cJohn.Scaling=100;
    cDog.ChangeRoom(0);
    cJohn.Animate(104, 3, eOnce, eBlock);//enemy faces DOWN
}
else if( (angle > 225) && (angle <= 315) ){
  cJohn.FaceLocation(cJohn.x+100, cJohn.y);//player faces RIGHT
Wait(30);
cJohn.LockView(36);
cJohn.ManualScaling=true;
    cJohn.Scaling=100;
cDog.ChangeRoom(0);
cJohn.Animate(105, 3, eOnce, eBlock);//enemy faces LEFT
}
else if( (angle > 315) && (angle <= 45) ){
cJohn.FaceLocation(cJohn.x, cJohn.y+100);//player faces DOWN
Wait(30);
cJohn.LockView(36);
cJohn.ManualScaling=true;
    cJohn.Scaling=100;
cDog.ChangeRoom(0);
cJohn.Animate(107, 3, eOnce, eBlock);//enemy faces UP
}
   
//death funciton for player (audio files, restoregame GUIs, etc.)
}
Title: Re: Catch me if you can!
Post by: Khris on Tue 26/04/2011 15:58:14
Quote from: Khris on Tue 19/04/2011 18:37:19
angle = Maths.RadiansToDegrees(Maths.ArcTan2(y/x));
// angle = -180 - 179.9
// e.g. -45 - 45 -> enemy is to the right of player

As you can see, back when I wrote that I told you the possible return values of angle, not 0-360 but -180 to 180, with 0 being to the right and positive being at the top. Scarab did get it wrong first though, but why didn't you use a Display() or something to check the value of angle? This is basic debugging.

Also, look at this:

else if( (angle > 315) && (angle <= 45) ){

It's wrong independently of what value angle is going to have since a number can't be greater than 315 and smaller than 45 at the same time. This also wasn't in the originally posted code, it just said "else".

Btw, there's lots of duplicate code in there.
All that changes depending on the angle is the loop and the direction cJohn's going to face in which should be replaceable by a FaceLocation(dog coords) command.

Consider this:

function Attack() {

  cJohn.FaceLocation(cDog.x, cDog.y); //player faces dog
  Wait(30);
  cJohn.LockView(36);
  cJohn.ManualScaling=true;
  cJohn.Scaling=100;
  cDog.ChangeRoom(0);
  if (angle < -135) angle += 360;
  int l = (angle+135)/90 + 104;  // convert angle to loop
  cJohn.Animate(l, 3, eOnce, eBlock);//enemy faces RIGHT
}


angle is -180 to 179
the if line turns this into -135 to 224 (so we don't have two separate ranges for left (-180 to -135 and 135 to 180)

now:
angle + 135 is 0 to 359
(angle+135)/90 = 0(down), 1(right), 2(up), 3(left)
add 104 and you get 104(down), 105(right), 106(up), 107(left)

Just rearrange the sprites in the loops to reflect that setting and you should be set.
Title: Re: Catch me if you can!
Post by: Digital Mosaic Games on Tue 26/04/2011 17:15:29
Okay! Everything works fine now! Thanks to all especially you Khris! ;)