JigSaw Puzzle with VBS script

This forum is meant for people to share their knowledge by writing their own tutorials for Adventure Maker.

Moderators: time-killer-games, Vengeance66, Candle, reneuend, GM-Support

JigSaw Puzzle with VBS script

Postby mercedes » Fri Jan 30, 2009 12:09 am

Ok here is the Jigsaw puzzle done with VBS script..Thanks to Juhu..:D~ this puzzle is done..I also included sound so when u place the piece, it adds a nice effect to it..I had initially wanted to add a flash of a picture to it first..but I figured not everyone would want that effect or do that much work either..takes a bit of time to do that..

Here is what you will need..

KeyGuard --For Key up and Key down feature--102 & 103 are the KeyID's

An icon made of each picture; Name them piece1 piece2 etc.

Pictures of the puzzle pieces as GIF's Name the pieces piece_1, piece_2..etc..

First place all pictures on the Left side of the frame and place pictures accordingly so they look together..

Also make sure they go from 1-21 or whatever number they end at..--Then make them TRansparent

Place the "actual" pictures in their place on the right side of frame.

Here's a picture of it..You don't have to download it..Just give it a second..
PictureHere

For the puzzle pieces on the Right.[the ones u see] Place this in the Advance of hotspot
puzzlehotspot=Action.GetHotspotNumber

Put an EXIT button on the frame also..

Variables puzzleready piececorrect and puzzlehotspot

Then place this in the Global Procedures..

Code: Select all
Sub KeyGuard_MouseButtonPressed(KeyID)

numberofpuzzlepieces=21'--Make sure this is the amount of yours.'

Dim XPos, YPos

Select Case KeyID(0)

Case 102

XPos = Cint(Component("KeyGuard").Object.MouseXPos)
YPos = Cint(Component("KeyGuard").Object.MouseYPos)

        If puzzlehotspot>numberofpuzzlepieces Then
Hotspot(puzzlehotspot).Move -300*15,-300*15
piecename="piece" & puzzlehotspot-numberofpuzzlepieces &".ico"
Action.ChangeDefaultCursor piecename
   End If

Case 103

XPos = Cint(Component("KeyGuard").Object.MouseXPos)
YPos = Cint(Component("KeyGuard").Object.MouseYPos)

      If XPos<=0 or XPos>=800 or YPos<=0 or Ypos >=715 Then
Action.ChangeDefaultCursor ""
Hotspot(puzzlehotspot).Move 400*15,350*15
Exit Sub
      End If

'----------------------------------

     If puzzlehotspot>numberofpuzzlepieces Then
Action.ChangeDefaultCursor ""
Hotspot(puzzlehotspot).Move XPos*15,YPos*15
hotspottop=(Hotspot((puzzlehotspot-numberofpuzzlepieces)).Top)/15
hotspotleft=(Hotspot((puzzlehotspot-numberofpuzzlepieces)).Left)/15
hotspotwidth=(Hotspot((puzzlehotspot-numberofpuzzlepieces)).width)/15
hotspotheight=(Hotspot((puzzlehotspot-numberofpuzzlepieces)).height)/15
puzzlepiecename="piece_" & (puzzlehotspot-numberofpuzzlepieces) & ".gif"
      
 

      If XPos>hotspotleft and XPos<(hotspotleft+hotspotwidth) and YPos>hotspottop and YPos<(hotspottop+hotspotwidth) Then
PlaySound GetPath(2)+"cheng.mp3",False
Action.LoadAPicture Hotspot((puzzlehotspot-numberofpuzzlepieces)),puzzlepiecename
Hotspot(puzzlehotspot).Move -300*15,-300*15
piececorrect=piececorrect+1
If piececorrect=numberofpuzzlepieces Then
puzzleready=1
     End If
     End If
     puzzlehotspot=0
     End If
    End Select

End Sub


In the Exit button make sure that picture isn't visible till PuzzleReady =1

Make sure you have the Sound Script in the Procedures with this..:)

Change the number of pieces to suit your project, mine happen to be 21..~

Also the peice to be found don't have to be in the inventory..The user can simply find what looks like ripped paper and be taken to this screen to complete it..Up to u how u do it..:)

I hope i didn't forget anything..~

Again Thanks to those who made this happen..Juhu Lyberodoggy..and of course ShadowHunter for Keyguard..:D

Enjoy!~
Last edited by mercedes on Sat Jan 31, 2009 2:04 am, edited 1 time in total.
User avatar
mercedes
VIP
 
Posts: 2460
Joined: Sun Mar 09, 2008 10:43 pm
Location: Canada..~

Postby Lyberodoggy » Fri Jan 30, 2009 9:20 am

Great job Mercedes and Juhu!

I liked the way the hotspot anchors (based on a reference to its "mirror" hotspot)

This was great!

I feel my brains growing of knowledge! :lol:
User avatar
Lyberodoggy
Administrator
 
Posts: 2526
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby marina » Fri Jan 30, 2009 4:20 pm

Fantastic Mercedes and Juhuwoorps! :D
I'll try to realize it...

Thanks a lot!
Have a nice weekend everybody :)
I'm fond of Rhem-like games!
User avatar
marina
Member
 
Posts: 44
Joined: Sun Nov 23, 2008 8:27 pm
Location: Rome

Postby juhuwoorps » Fri Jan 30, 2009 8:26 pm

Try it out. It's easy to use if you follow the tutorial step for step :)
juhuwoorps
Code Master
 
Posts: 622
Joined: Tue Jul 08, 2008 3:13 pm

Postby marina » Fri Jan 30, 2009 8:59 pm

Of course I will! :D
Going to start working on it with my first mug of coffee tomorrow morning.
I'll post as soon as I'll be done with it, or... to ask some questions :wink:

Thanks for your great work!
I'm fond of Rhem-like games!
User avatar
marina
Member
 
Posts: 44
Joined: Sun Nov 23, 2008 8:27 pm
Location: Rome

Postby Jaked » Fri Jan 30, 2009 9:20 pm

Very thorough tutorial on Jigsaw puzzles, to the point that I'm able to use it. On a different note, I noticed on the JPG that it was a very good letter-thing. Are you using it for Murder Mystery Behind It?
My sig changes more often than Doctor Who (see your national BBC channel) regenarates into new melancholy actors. Oh look, Matt Smith! Gerard Butler! Colin Mochrie! That wolf from Twilight: New Moon!
User avatar
Jaked
Code Master
 
Posts: 729
Joined: Wed Jun 25, 2008 4:26 am

Postby Imari » Fri Jan 30, 2009 10:43 pm

Nice, mercedes. Thanks.
User avatar
Imari
VIP
 
Posts: 872
Joined: Fri Jun 20, 2003 4:49 pm
Location: Virginia, USA

Postby mercedes » Sat Jan 31, 2009 2:06 am

You're very welcome..:D

Are you using it for Murder Mystery Behind It?


Yes I am..:D..

THanks Guys..:D


Peace
User avatar
mercedes
VIP
 
Posts: 2460
Joined: Sun Mar 09, 2008 10:43 pm
Location: Canada..~

Postby marina » Sun Feb 01, 2009 8:11 am

Here... it was the second option... I have some questions :oops:
Well, it's just one question: where's the mistake(s)?

Mercedes tut is so clear and complete that I didn't think something could go wrong; I followed carefully each step, naming both files.gif and icons (32x32) as she did and in the code I only changed the number of pieces from 21 to 25, which is the number of my pieces, and deleted the line on playing sound as I didn't have any in my project and I got an error message.
Maybe, being the number of pieces different, I should have changed something else?

I'll try to describe the problem as clearly as I can:
When I test the frame and start dragging the pieces around, strange things happen... the cursor change to the shape of a piece that is not the one I picked up or change shape when I release the mouse button. Some pieces get stuck in the wrong place and partially out of the game window and some appear more than once.
It's very difficult for me to describe any single oddity happening, so if someone would like (well... like is not the proper word) to have a look of his own could download the project here:
KEYJIG.rar:
http://files.filefront.com/KEYJIGrar/;13161417;/fi

I don't want to waste anybody's time, nor ask anybody to fix the problem for me but I would like to understand where I did something wrong and why... maybe mercedes and juhuwoorps that worked on it could easily understand? Since yesterday early morning I spent all day and part of the night trying to understand but I really can't figure it out myself.

Thanks a lot in advance! :)
I'm fond of Rhem-like games!
User avatar
marina
Member
 
Posts: 44
Joined: Sun Nov 23, 2008 8:27 pm
Location: Rome

Postby juhuwoorps » Sun Feb 01, 2009 8:36 am

Hi!
You don't start with HS1 for the done puzzle (The hotspots you make transparent)
You have to start with HS1 and piece_1.gif. then HS2 and piece_2.gif and so on up to HS25

If you have 25 puzzlepieces the first draggable hotspot must have number 26 with piece_1.gif , 27 with piece_2.gif and so on up to HS50.

If you do it like this, it should work properly.
juhuwoorps
Code Master
 
Posts: 622
Joined: Tue Jul 08, 2008 3:13 pm

Postby marina » Sun Feb 01, 2009 9:33 am

Thanks for your fast reply juhu!
According to mercedes tutorial I made first the 25 HS with piece_1 to 25.gif and arranged them assembled in the left of the frame before giving them the transparency, so the "draggable" HS, containing same pictures, are HS 26 to 50.

You wrote:
You don't start with HS1 for the done puzzle (The hotspots you make transparent)

and you also wrote:
the first draggable hotspot must have number 26 with piece_1.gif


I'm afraid it's not so clear to me... if I don't have to start with HS to be made transparent, those for the done puzzle, then they should be 26 to 50, but in the second sentence I quoted it sounds as HS 26 to 50 should be the draggable ones...
In my puzzle HS 1-25 are the invisible ones in the left and HS 26-50 are the draggable ones, both containing piece_1 to 25. gif and the icons are named, in the order, piece1 to 25.ico. Is that as it should be? In this case I wonder what the problem is... sorry for my dumbness.
I'm fond of Rhem-like games!
User avatar
marina
Member
 
Posts: 44
Joined: Sun Nov 23, 2008 8:27 pm
Location: Rome

Postby juhuwoorps » Sun Feb 01, 2009 10:03 am

In your puzzle the invisible hotspots are 2 - 26.

Your draggable hotspot starts with 1 and then 27 up to 50.

You have done all right, but the hotspotnumbers are not in correct order.

I think you have clicked "Move to bottom" at one hotspot.

Hope it's clearer now.
juhuwoorps
Code Master
 
Posts: 622
Joined: Tue Jul 08, 2008 3:13 pm

Postby mercedes » Sun Feb 01, 2009 12:13 pm

Hi there..Mirana...:D

I have 21 pieces..

On the Left side of screen the Transparent hotspots..I have them set up as Hotspot(1) = Piece_1.gif..Hotspot(2)=Piece_2.gif

In the draggable hotspots on the Right..I have them starting at
Hotspot(22)=Piece_1.gif---- My icon is Piece1.ico---This should happen automatically..

My Icon's numbers start at Piece1 and end at Piece21.ico..
My GIF's numbers start at Piece_1 and end at Piece_21

The "Exit" button should be the very last button on the frame..

I hope that helps..:)

Peace~
User avatar
mercedes
VIP
 
Posts: 2460
Joined: Sun Mar 09, 2008 10:43 pm
Location: Canada..~

Postby marina » Sun Feb 01, 2009 2:29 pm

Yes juhuwoorps!
Thanks so much for having had a look at my project :D

It's exactly what I've done. I sent to bottom one of the draggable HS because it had its square edges very neats over all the others and I didn't like it... never thought that it would cause a bug in the code. I thought that moving hotspots up and down wouldn't change their reference number. Good to know; I'll keep it in mind for the future!

Hi mercedes! Thanks for your reply. Your tut is so clearly explained that it's hard to make mistakes... the problem has been highlighted by juhu, moving one HS to the bottom...

*EDIT*
It's working perfectly! Thanks so much!!! :D

P.S. It's due to a "professional deformity"... I must have thought that hotspots were similar to Photoshop levels and that moving them up and down would only change their look... :oops:
I'm fond of Rhem-like games!
User avatar
marina
Member
 
Posts: 44
Joined: Sun Nov 23, 2008 8:27 pm
Location: Rome

Postby juhuwoorps » Mon Feb 02, 2009 1:51 am

Glad to help you!
And I must say thanks to Mercedes!
juhuwoorps
Code Master
 
Posts: 622
Joined: Tue Jul 08, 2008 3:13 pm

Postby mercedes » Mon Feb 02, 2009 6:39 am

Yes I found that out the hard way as well...:D, I thought it was like layers too..but it makes a difference in AM when u do that..:P..Glad you guys could figure it out..!~..:D..
User avatar
mercedes
VIP
 
Posts: 2460
Joined: Sun Mar 09, 2008 10:43 pm
Location: Canada..~

Postby Ron_Emad2 » Mon Feb 02, 2009 9:23 am

hello
thanks about this puzzel
can you upload this project file ?
with thanks
emad
Hello
I from iran
i cant speak english correctly
please forgive me
User avatar
Ron_Emad2
Active Member
 
Posts: 85
Joined: Fri Oct 13, 2006 12:08 pm
Location: Iran-Kashan

Postby marina » Mon Feb 02, 2009 9:26 am

@ Mercedes
I was lucky that Juhu at once focalized the problem, otherwise it could take me ages to understand :D

I wasn't as lucky when trying to paste the code in my project... ctrl+P (as it is written at the bottom of the window) doesn't work at all; so I had to write the whole code manually before discovering that it had to be ctrl+V :shock:
(by the way - did anyone notice that?)

(You know, I have an utter difficulty... I'm not at all familiar with Windows; in my job I have to work on a Mac, and mine is an old one, with different keys position and commands.)

Thanks again, and thanks to Shadowhunter for his KeyGuard! :)
I'm fond of Rhem-like games!
User avatar
marina
Member
 
Posts: 44
Joined: Sun Nov 23, 2008 8:27 pm
Location: Rome

Postby Lyberodoggy » Mon Feb 02, 2009 12:46 pm

control+v is the shortcut for paste, control+p for print... I often mistake them too...

Working on a Mac must be nice ;)
User avatar
Lyberodoggy
Administrator
 
Posts: 2526
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby marina » Tue Feb 03, 2009 9:54 am

To me is very nice Lyberodoggy :)
I love my old mate, a G4 first generation; I didn't upgrade to System X because it would be as moving to another home (I think it happens for some PC users in regard to Vista as well).
Anyway since I'm working on AM I feel a bit, er... schizofrenic.. passing from qwerty to qzerty and trying to right-click on my single-button apple mouse or dragging any sort of thing as easily in Windows...
Up to now, about Windows XP, I only knew how to install adventure games!
I'm afraid I went a bit OT... sorry :(

@ Ron
I assume that in Mercedes game that puzzle is well integrated and uploading it would be sort of a spoiler... let me know if you want me to upload mine (the fixed one of course), which is fairly apart from the entire game and... up to the moment I'll manage to finish my game ( :cry: ) it will be longly forgotten...
:)
I'm fond of Rhem-like games!
User avatar
marina
Member
 
Posts: 44
Joined: Sun Nov 23, 2008 8:27 pm
Location: Rome


Return to Post Your Own Tutorials

Who is online

Users browsing this forum: No registered users and 0 guests

cron