Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Marion on Sun 25/02/2007 12:16:37

Title: Is it possible to disable up-left-right-down loops ?
Post by: Marion on Sun 25/02/2007 12:16:37
Hi everyone :)
I am working on a new AGS game. It will use an isometric view, with mouse control (no keyboard).
I would like that my characters walk only in diagonal directions. That means that the up, left, right and down directions won't be used, and the character can't walk directly up, left, right and down (he has to walk diagonally to reach a point each time).
Is it possible ?
How ?

Thank you very much for your help.

I have searched the forum yet and found some tips about isometric games making, but nothing interesting for me (keyboard control, etc).
Title: Re: Is it possible to disable up-left-right-down loops ?
Post by: Joe on Sun 25/02/2007 15:27:06
It's simple, do not fill the four first loops
Title: Re: Is it possible to disable up-left-right-down loops ?
Post by: Marion on Sun 25/02/2007 19:45:31
I tried, of course, but when I want to test the game, AGS says me that it can't because there is no frame in the first loop... :(
Title: Re: Is it possible to disable up-left-right-down loops ?
Post by: GarageGothic on Sun 25/02/2007 20:15:54
I can think of several ways to do it. They all require scripting, and they'll all have some problems with walkable areas. I'm not sure if you're familiar enough with AGS script to use the following for anything, but maybe it'll help someone else:

By far the easiest would be to create two Views for the character. They will use the same sprites, so it doesn't mean creating more content or a bigger file size. The idea is that we "remove" directions up, left, down and right by putting diagonal walking sprites in their loops.
For example, both loop 1 (left) and 3 (up) will share the up-left diagonal sprite. But, now we get a problem, what if the character is walking upwards but more to the right? This is why we need a second View for the same character. Here you give the cardinal directions the sprites possible sprites which they DIDN'T have in the first View. So in this case, the second View would have down-left diagonal sprite for loop 1 (left) and up-right diagonal sprite for loop 3 (up).

Then, in the repeatedly_execute() function, you could do something like this (first declare ints oldx and oldy in the top of the Global Script):


if (player.Moving == true) {
   if ((player.x > old.x) && (player.y <= old.y)) { //he's moving to the right and upwards
      player.ChangeView(2); //if the two different Views we mentioned before are 1 and 2, this would be 2
      }
   else if ((player.x < old.x) && (player.y <= old.y)) { //he's moving left and upwards
      player.ChangeView(1);
      }
   //add more cases here (down left, down right) according to the Views you made.
  }
oldx = player.x; //store player's current position to see which direction he is moving
oldy = player.y;
Title: Re: Is it possible to disable up-left-right-down loops ?
Post by: Marion on Sun 25/02/2007 20:28:17
Thank you, GarageGothic, I think it's a good idea, in fact.
But if I understand the code, the problem is that the character can still walk up, left, right or down on the screen, we only change the view here, not the directions he walks.  :-\
Title: Re: Is it possible to disable up-left-right-down loops ?
Post by: GarageGothic on Sun 25/02/2007 20:44:10
You want to lock the characters walking direction too? That certainly is possible but it sounds like a pain - imagining having to walk in zig-zag left and right instead of walking directly upwards. The problem isn't catching the mouse-click and having the player move in a straight diagonal more-or-less towards the direction of the cursor, but it's a bit complicated if you want the pathfinding to work at the same time. I'm thinking of workaround, but nothing really efficient springs to mind except writing your own pathfinding code.

Do you want the character only to be able to move in straight 45 degree diagonals (as if moving along a chess board), or are "sort of" diagonals also ok?
Title: Re: Is it possible to disable up-left-right-down loops ?
Post by: Marion on Sun 25/02/2007 21:43:33
That's it, only in 45 degree diagonal. But I think you're right, it will  be complicated... I will keep the others directions.
Thank for your help :)
Title: Re: Is it possible to disable up-left-right-down loops ?
Post by: Khris on Mon 26/02/2007 07:46:04
There is a quick'n'dirty way to do it:

function abs(int a) {
  if (a>=0) return a;
  return -a;
}

function sgn(int a) {
  if (a>0) return 1;
  if (a<0) return -1;
  return 0;
}

function on_mouse_click(MouseButton button) {
  ...
  // left click, walk mode
  int x=mouse.x+GetViewportX()-player.x;
  int y=mouse.y+GetViewportY()-player.y;
  int d=(abs(x)+abs(y))/2;
  x=d*sgn(x);
  y=d*sgn(y);
  player.WalkStraight(player.x+x, player.y+y);
  ...
}


Example:
With the player at 100;100, clicking 130;140 will make him walk to 135;135.
With the player at 150;150, clicking 120;100 will make him walk to 110;110.

Edit: I'm not sure which loop is used when walking exactly NW, NE, SW or SE.
So you'll probably need GG's code, too.
Title: Re: Is it possible to disable up-left-right-down loops ?
Post by: Marion on Mon 26/02/2007 12:40:27
It looks a bit complicated, but I'll try.