Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Buckethead on Sun 25/07/2010 19:04:14

Title: slider puzzle
Post by: Buckethead on Sun 25/07/2010 19:04:14
I want to make a simple slider puzzle with 9 tiles. 8 are filled, 1 is open.

This is the code I've got so far. I copied it from a thread from around 2005. It runs but doesn't seem to work properly.
I can't really figure it out. The titles go all over the place, even outside the "box" some times.


int button_pressed=0;
Object *ob;
Hotspot *hot;



function Checksolved()
{
Display("moved");
}




function oclip1_click()
{
//script for Object 0: Any click on object
object[0].Move(object[0].X + 78,  object[0].Y,  7, eBlock, eWalkableAreas);
}



function room_RepExec()
{
 
// script for Room: Repeatedly execute
 
  if (mouse.IsButtonDown(eMouseLeft)) {
    if (button_pressed==0) {
      button_pressed = 1;
      ob = Object.GetAtScreenXY(mouse.x, mouse.y);
    }
  }
  else {
    button_pressed=0;
    if (ob != null) {
      ob.Baseline = 0;
      if (Object.GetAtScreenXY(ob.X + 78, ob.Y) == null && GetWalkableAreaAt(ob.X+78, ob.Y) != 0) {
ob.Move(ob.X+78, ob.Y, 5, eBlock);
Checksolved();
}
else if (Object.GetAtScreenXY(ob.X - 78, ob.Y) == null  && GetWalkableAreaAt(ob.X-78, ob.Y) != 0) {
ob.Move(ob.X-78, ob.Y, 5, eBlock);
Checksolved();
}
else if (Object.GetAtScreenXY(ob.X, ob.Y-78) == null  && GetWalkableAreaAt(ob.X, ob.Y-78) != 0) {
ob.Move(ob.X, ob.Y-78, 5, eBlock);
Checksolved();
}
else if (Object.GetAtScreenXY(ob.X, ob.Y+78) == null  && GetWalkableAreaAt(ob.X, ob.Y+78) != 0) {
ob.Move(ob.X, ob.Y+78, 5, eBlock);
Checksolved();
}
ob = null;
    }
  }
}



Could someone have a look and see what's wrong?
Title: Re: slider puzzle
Post by: Khris on Sun 25/07/2010 20:37:22
I built it myself and found that the coordinates of an object aren't at its bottom left corner but the pixel below.
Adjusting the Y values did the trick:

      if (Object.GetAtScreenXY(ob.X + 78, ob.Y-1) == null && GetWalkableAreaAt(ob.X+78, ob.Y) != 0) {
        ob.Move(ob.X+78, ob.Y, 5, eBlock);
        Checksolved();
      }
      else if (Object.GetAtScreenXY(ob.X - 78, ob.Y-1) == null  && GetWalkableAreaAt(ob.X-78, ob.Y) != 0) {
        ob.Move(ob.X-78, ob.Y, 5, eBlock);
        Checksolved();
      }
      else if (Object.GetAtScreenXY(ob.X, ob.Y-79) == null  && GetWalkableAreaAt(ob.X, ob.Y-78) != 0) {
        ob.Move(ob.X, ob.Y-78, 5, eBlock);
        Checksolved();
      }
      else if (Object.GetAtScreenXY(ob.X, ob.Y+77) == null  && GetWalkableAreaAt(ob.X, ob.Y+78) != 0) {
        ob.Move(ob.X, ob.Y+78, 5, eBlock);
        Checksolved();
      }
Title: Re: slider puzzle
Post by: Buckethead on Mon 26/07/2010 12:09:23
Thanks !

It does seems to work better now. But the tiles still seem to move under eachother occasionally.

Do these objects need to be arranged in a certain order?

Title: Re: slider puzzle
Post by: Khris on Mon 26/07/2010 14:46:14
Since in the code, they move 78 pixels, I made them 78x78 squares. Then I put them directly next to each other, without margins.
The walkable area is supposed to be a square that just encompasses the nine lower left corners.
Title: Re: slider puzzle
Post by: Buckethead on Wed 28/07/2010 16:17:34
Another step forward but it still doesn't work totally. I made sure every tile is exactly in place but it still doesn't work. Perhaps I should upload my source code...