Leapfrog puzzle (Solved)

Started by Maverick, Tue 01/08/2006 14:02:46

Previous topic - Next topic

Maverick

I'm working on a puzzle which is pretty much the same as the slider puzzle here

I'm working on a puzzle, which is pretty, much the same as the slider puzzle here. The only difference is that the background contains only 7 horizontal blocks. There are 6 objects (7 if you include
  • which is not in use) on this grid with a blank space in the centre. The objective is to swap all the objects on the left with those on the right and vice verse. Objects can only move in one direction and can move to a blanks space adjacent to its current coordinates (x+40) or jump over an obstructing object (leapfrog x+80) providing the next blank space is open. I got the whole thing to work up to a point i.e. the pieces are moving in the right direction etc) but when an object gets to the leftmost or rightmost positions and you left click on it again it jumps out of alignment.

    Another problem that I would like to get around is the fact that when an object needs to move past an object (leapfrog) it currently slides behind the obstructing object. Is there a way that I can make it look like its jumping over this object?

    I'm using AGS 2.71

    My code:


    In the repeatedly exe
    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 + 40, ob.Y-1) == null && GetWalkableAreaAt(ob.X+40, ob.Y-1) != 0 && ob.ID <=3) {
    Ã,  Ã,  Ã,  Ã,  ob.Move(ob.X+40, ob.Y, 3, eBlock);
    Ã,  Ã,  Ã,  }
    if (Object.GetAtScreenXY(ob.X + 80, ob.Y-1) == null && GetWalkableAreaAt(ob.X+80, ob.Y-1) != 0 && ob.ID <=3) {
    Ã,  Ã,  Ã,  Ã,  ob.Move(ob.X+80, ob.Y, 3, eBlock);
    Ã,  Ã,  Ã,  }

    Ã,  Ã,  Ã,  else if (Object.GetAtScreenXY(ob.X - 40, ob.Y-1) == nullÃ,  && GetWalkableAreaAt(ob.X-40, ob.Y-1) != 0 && ob.ID>=4) {
    Ã,  Ã,  Ã,  Ã,  ob.Move(ob.X-40, ob.Y, 3, eBlock);
    Ã,  Ã,  Ã,  }
    Ã,  else if (Object.GetAtScreenXY(ob.X - 80, ob.Y-1) == nullÃ,  && GetWalkableAreaAt(ob.X-80, ob.Y-1) != 0 && ob.ID>=4) {
    Ã,  Ã,  Ã,  Ã,  ob.Move(ob.X-80, ob.Y, 3, eBlock);
    Ã,  Ã,  Ã,  }

    ob = null;
    Checksolved();
    }
    }
    }

    Any suggestions on how I can fix these issues?

    edit
    The function to check if the puzzle is solved:
    //Top of room script
    // called when the puzzle is solved:
    function CheckSolved() {
    Ã, 
       int correct;
       int i = 1;
       while (i<=6) {// Or number of slide pieces
             Hotspot *hot = Hotspot.GetAtScreenXY(object.X+20, object.Y-20); //middle of tile
             if(hot.ID==i) correct++;
             else correct = 0;
             i++;
             }
       if(correct==6) {// Or number of slide pieces
          Display("Solved");

          }


    Ã, 
    }



    int button_pressed=0;
    Object *ob;
    Ã,  Ã, 

Alynn

One way to make it "jump" would be to make it use a walkable area, and have your walkable areas leap over the other spaces, This would be easiest

More difficult would be to use the math functions and calculate the jump motion and have it move that way.

SSH

Object baselines determine whether one object is drawn in front of another, and you can use the "Z" co-ordinate to give an object height, it would be easy to do a Z-co-ord jump where the trajectory was shaped like a "^".

As for the end-locations not working, I'm not sure which bit of code that you have is supposed to be checking for this situation... can you elaborate?
12

Maverick

#3
Quote from: SSH on Tue 01/08/2006 14:42:32
As for the end-locations not working, I'm not sure which bit of code that you have is supposed to be checking for this situation... can you elaborate?

I edited my post to include the code that checks if the puzzle is solved.
I managed to resolve the slider pieces going out of alignment ( if I used the code that I posted in the actual game code it would have worked the first time around but thats what you get for working on stuff till 02h00 am).

As for the second part of my problem, I still have to find a way to make the slider pieces "jump". Alynn mentioned that I can use a walkable area but as I'm already using one for the slider pieces to move on a horizontal line, how do I code it so the slider pieces will use walkable area 1 when they need to move to the adjacent empty square and walkable area 2 when they need to "jump" over an obstructing pieces?

Would it work if I changed this line of code:
ob.Move(ob.X+80, ob.Y, 3, eBlock);

to
GetWalkableAreAt(ob.X, ob.Y-40);
ob.Move(ob.X+80, ob.Y, 3, eBlock);

if I include a second walkable area above the slider pieces?

SSH

If you use the Z coordinate I mentioned, you only need the walkable areas that you already have
12

Maverick

It is exactly what I want (I think) but just for a moment assume that you are dealing with a total idiot that knows very little about coding, how would such a mentally challenged individual go about changing the z property of an object. I read in the manual that you can change the z property of a character but couldn't find the same "type" of command, which allows you to change this parameter for an object. ::)

SSH

Ooops, it may only exist for Characters, not objects! Sorry!
12

Maverick

#7
Thanks SSH!

I got it to sort of do what I want by using:
ob.Move(ob.X, ob.Y-40, 3, eBlock,eAnywhere);
ob.Move(ob.X+40, ob.Y, 3, eBlock,eAnywhere);
ob.Move(ob.X, ob.Y+40, 3, eBlock,eAnywhere);

Although this works just fine its not exactly what is was hoping to do.
I'll just have to redraw the graghics to someting that would be more suited to this type of movement.Ã, 

SMF spam blocked by CleanTalk