Zigsaw Puzzle

Started by Ghostlady, Thu 19/06/2008 02:53:26

Previous topic - Next topic

Ghostlady

According to the documentation, the limit on objects per room is 40.  I was planning on creating a zigsaw puzzle with 70 pieces.  Anyone know a way to do this?
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven
Haunting at Cliffhouse

monkey0506

You could use characters instead. As of AGS 3.0 there's no longer a limit on the number of characters, and they don't bloat the file size much more than an object would anyway. You could consider the "raw draw" route using the DrawingSurface methods, but that would be slower and lacks built-in interaction methods.

Ghostlady

Can you work a drop and drag with characters?  Do you code the same as an object but just use a character?
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven
Haunting at Cliffhouse

monkey0506

The coding between objects and characters is very similar. Drag and drop is a bit more complicated, but it could be done. You could turn the character off using one of several methods (using the unsupported on property, using the Transparency property, moving the character to a different room, etc.), copy the character's graphic temporarily to the mouse's graphic, and then do the reverse when dropping.

Ghostlady

I guess I can't have 70 hotspots either.  Would I need to check where the mouse is?
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven
Haunting at Cliffhouse

monkey0506

Checking where the mouse is at isn't complicated. Just use (mouse.x, mouse.y). And actually you may just be able to directly modify the character's (x, y) to match the mouse's for drag-n-drop instead of what I said earlier which would simplify the process somewhat.

Ghostlady

So if I made a square grid and checked if the mouse was somewhere within a space in that grid and then checked where the character was (but wouldn't the character be there if it was on the mouse?) and if the character fell within the square of the grid?  Something like that?  Not sure what you mean by "modify the character's (x,y).
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven
Haunting at Cliffhouse

GarageGothic

#7
The easiest method (in that you wouldn't have to create as many characters as the number of jigsaw pieces and the maximum number could always be changed) would be to store all the pieces, their current coordinates, their target coordinates and their graphics in a struct. They would be purely virtual items, and you'd write a simple rectangular mouseover check function. You'd use DrawingSurface.DrawImage to update the board, and to avoid a framerate drop while dragging a piece you could turn that piece into an Overlay while dragging it.

If you use a grid based structure (all pieces are imagined to be the same height/width), you would not even have to use true coordinates for their target location, because that could be a pain to set up. Instead you could just initialize each piece with a function like InitJigsawPiece(int targetgridx, int targetgridy, int sprite, int startx, int starty) where (startx, starty) would be true screen coordinates which could be assigned Random() values, and (targetgridx,targetgridy) would be grid coordinates (for instance top left field would be 0,0 while the seventh piece from the left and one piece down would be (7,1).

This may seem overly complicated, but in reality it would be a much more generalized function which could be reused for any jigsaw puzzle in the game. To make things super easy to set up, requiring little manual initialization, you could even assign all jigsaw pieces to a View, where loops would signify rows in the puzzle grid while frames would signify each individual piece. Views, Loops and Frames are all unlimited as of the latest couple of AGS versions. Your init function would then be something like InitJigsaw(int view, int x, int y, int width, int height) where the latter four parameters is the "playing field" and also act as the bounds for the area which the initial location of each piece can be randomized within.

Since the size of the grid is independent of the sprite sizes, they could be offset by (spritewidth-gridunitwidth)/2, (spriteheight-gridunitheight)/2. This would allow you to draw every sprite with a transparent border area and allow "notches" that fit into other pieces. A snap-to-grid functionality when releasing a piece close enough to a grid coordinate shouldn't be hard to do and would make things easier for the player.

In fact, this whole thing might be a good idea for a module. SSH, where are you? :)

Edit: I should say that I would never suggest this method in the beginner's forum if I wasn't aware that you've already made a couple of games with pretty advanced non-standard puzzles.

Edit 2: Also, check out the responses to this thread, though some of the code is a bit obsolete.

Maverick

Quote from: Ghostlady on Thu 19/06/2008 03:04:41
I guess I can't have 70 hotspots either.  Would I need to check where the mouse is?

Yes you can have way more than that by being a little creative. Set up a grid with hotspots on the vertical and regions on the horizontal like in the image below. In the example I effectively created 25 hotspots by using only 5 hotspots and 5 regions.



I agree with GarageGothic on using a Struct to create this puzzle and calling in the module master is an even better idea.

Cheers

Ghostlady

That's actually quite ingenious, Maverick.

GarageGothic you have opened my eyes.  I have some studying to do.
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven
Haunting at Cliffhouse

SMF spam blocked by CleanTalk