Slider puzzle trouble (solved)

Started by Akril15, Sun 27/02/2011 23:52:11

Previous topic - Next topic

Akril15

I've been trying to integrate a slider puzzle into my game. I downloaded a room with one in it from this thread (obviously, this was before Geocities ceased to be), and tried to edit it so that it would work in my game.

The only real differences between the sample room and my game is that the sample room was made in AGS 2.72 at a resolution of 320x240, while and my game is still being made in AGS 3.1 at a resolution of 640x480. I wouldn't think these differences would create much of a problem, but as it turns out, they do.

Like the original room, there are 8 tiles arranged in a 3x3 grid, each of them 80x80 pixels each. I've got the tiles moving and confined to a square in the middle of the screen, but they don't move properly. They slide underneath adjacent tiles, and they only slide sideways, not up or down. Strangely, when I tried decreasing the X values to 20 instead of 40, the tiles did move in the right direction, but of course, they'd only move halfway between their current location and their new one.

I've looked at various threads containing similar pieces of code, but I couldn't find a solution to my problem in any of them, and I finally decided that I needed to ask for help here. Here is the relevant code for the room:

Code: ags

function on_puzzle_solved() {
  Wait(15);
  slider_solved=true;
  player.ChangeRoom(35);
 
}

int button_pressed=0;
Object *ob;
int correct = 0;


function room_RepExec()
{
  if (Object.GetAtScreenXY(mouse.x, mouse.y) == object[9]) {
    object[9].Graphic=2046;
      }
  else object[9].Graphic=2045;
  
  
  
 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.Move(ob.X+40, ob.Y, 3, eBlock, eWalkableAreas);
      }
      else if (Object.GetAtScreenXY(ob.X - 40, ob.Y-1) == null  && 
GetWalkableAreaAt(ob.X-40, ob.Y-1) != 0) {
        ob.Move(ob.X-40, ob.Y, 3, eBlock, eWalkableAreas);
      }
      else if (Object.GetAtScreenXY(ob.X, ob.Y-41) == null  && 
GetWalkableAreaAt(ob.X, ob.Y-39) != 0) {
        ob.Move(ob.X, ob.Y-40, 3, eBlock, eWalkableAreas);
      }
      else if (Object.GetAtScreenXY(ob.X, ob.Y+39) == null  && 
GetWalkableAreaAt(ob.X, ob.Y+40) != 0) {
        ob.Move(ob.X, ob.Y+40, 3, eBlock, eWalkableAreas);
      }
      ob = null;
    }
  }

  //---- solved-check -------------------------------------------------------------
  correct=1;
  int i=1;
  while (i <= 8) { // number of slide-pieces
    Hotspot *hot = Hotspot.GetAtScreenXY(object[i].X+20, object[i].Y-20); // middle of tile
    correct = correct * (hot.ID == i); // for each object check if its number corresponds to hotspot number
    i++;
  }

  if (correct) on_puzzle_solved(); // run on_puzzle_solved() function if the puzzle's solved
  //-------------------------------------------------------------------------------


}


Thanks in advance!

Akril15

This thread got pushed down to the second page, so I figured I'd nudge it back up.

TonyJ

hi don't know if this will be any help , but, in the quest for a puzzle or two or at least a hint as to how they all screw together, i downloaded the module and plug in bundles assembled by some fine personage, in the graphics, misc, folder there is a jigsaw puzzle module that with very minor mods works well with latest AGS release, all that needs to be done really is to open and save it with 2.72, then reopen with latest release, copy across the relevant files and voila a puzzle room.  As for the problems with your code, bearing in mind that i'm a complete noob ;D I've a feeling that it's similar to some probs I had with constructing a new jigsaw type puzzle in that the parameters for the graphic included an offset to allow for overlapping areas and until I'd worked out what actually caused the bunching of pieces the results seem to have been very similar

Ishmael

#3
...

EDIT: Are you sure you have the room set up properly? Because the code seems ok to me after a bit of reacquinting myself with the object coordinate system...
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

Akril15

After a bit of experimentation, I finally figured out what the problem was: the images I was using. I remember reading in another thread that it's important that the tiles in the puzzle are touching each other. There's a thin transparent border around each of the images I was trying to use, and apparently, even though the edges of the tiles were all touching each other, that border was enough to make the game think otherwise. Even putting a partially transparent color in place of the transparent region didn't work. I then tried refilling the border with an opaque color...problem solved!

Thank you for the replies, Tony and Ishmael. Assuring me that the code was okay helped point me in the right direction and figure this conundrum out.

SMF spam blocked by CleanTalk