Adventure Maker   
   Adventure Maker v4.5 Help Document  
Home (Adventure Maker website)

 

   
Help Contents

Search

Introduction
   Program Overview
   List of Features
   What's New

Creating software without scripting
   Getting Started Tutorials
   Some Techniques and Tips
   Creating puzzles without scripting

   Creating third person games
   Creating interactive 360-degree panoramas
   Creating software for
PSP
   Creating software for iPhone and iPod touch

Creating software with VBScript
(Full Edition only)

   Introduction to VBScript
   Language Reference
   Objects Reference
   VBScript Techniques and Tips

   Sample Source Code

Pictures, sounds and music
   => Creating Pictures
   Music Maker help
   Creative Painter quick help
   Sounds and Music
   Videos, Icons, Cursors

Plugins (Full Edition only)
   Overview of the Plugins System
   Downloading/Uploading Plugins
   The Plugin Properties window
   About the Flash Plugin

Tips
   User Interface Tips
   Reducing the project size
   End-User System Requirements

Advanced tutorials
(Full Edition only)

   Creating a custom startup menu
   Using ActiveX components (ocx)

Troubleshooting
   Common issues and solutions
   Known bugs and limitations

About us
   Credits
   Website
   Contacting us
   Helping out

"iPhone" and "iPod" are trademarks or registered trademarks of Apple Inc. "PSP" is a trademark of Sony Computer Entertainment Inc. All other trademarks are the property of their respective owners.

As of the release date of this version, Adventure Maker is NOT affiliated with, endorsed by, or sponsored by Apple Inc., Sony Corporation, SCEI, or any Apple or Sony subsidiary.

   

 

VBSCRIPT SAMPLE SOURCE CODE
(FULL EDITION ONLY, WINDOWS ONLY)


Where can I find the source code of the demonstration games that are included in the Adventure Maker package (Othello, Slider Puzzle, Memory Game...)?

To view the source code of the sample games that are included in the Adventure Maker package, just follow these steps:

1. Run Adventure Maker
2. Click "Load Project..."
3. Click "Jump to the "Projects" folder
4. Double-click on the sample game which code you want to view (for example "Othello")
5. Click "VBS Procedures...".
The source code will then appear in a new window.
Note: To view the list of the Global Variables, close the window with the source code, and click "VBS Variables...".

   For example, here is the source code of the sample game "Slider Puzzle":

'*******************************************
'* SLIDER PUZZLE                            *
'* VERSION 1.1                              *
'* FOR ADVENTURE MAKER V3.2 OR ABOVE       *
'*                                          *
'* You have the right to modify the code   *
'* below, and to use it in any application *
'* created with Adventure Maker.            *
'*                                          *
'* -- Special thanks to ShadowHunter --    *
'*******************************************



'A FEW NOTES TO HELP YOU BETTER UNDERSTAND THE SOURCE CODE,
'AS WELL AS CUSTOMIZE IT AND USE IT IN YOUR PROJECTS:



' 1. ABOUT PUBLIC VARIABLES:

'There are several Public (global) variables that are not declared below.
'These variables are declared in the "Variables" window of Adventure Maker,
'which you can open by clicking "Project Variables..." from either the
'"Frames Menu" or the "Frame Editor".

'These public variables are: "LevelNumber", "NumberOfMoves", and all the
'other variables that are listed under the "General Settings" section
'of the "InitializeTheGame" procedure (see below).


' 2. ABOUT WHICH PROCEDURES ARE EXECUTED, AND WHEN:

'When the game starts, the procedure named "InizializeTheGame" is called. To see
'where exactly it is called, go to the "Frame Properties" window of the frame
'named "Main", and then click the "Advanced" tab.

'Each time you click a tile, the procedure named "MoveTile" is called. To see
'where exactly it is called, go to the "HOTSPOT PROPERTIES" of one of the
'tiles (to do so, in the editor, right-click on a tile and select "Properties...")


' 3. ABOUT THE TILES, IN GENERAL:


'The Adventure Maker objects used for the tiles are internally called "hotspots".
'The 16 tiles used in the puzzle are called "Hotspot(1)", "Hotspot(2)", and so on
'up to "Hotspot(16)".

'When the player clicks on a hotspot that corresponds to a tile, the "MoveTile"
'procedure resets the "Picture" property of that hotspot so that is looks blank.
'The "MoveTile" procedure also changes the "Picture" property of the hotspot that
'was blank so that it holds the picture of the hotspot that has been clicked. In
'other words, instead of really moving the tiles, the "MoveTile" procedure only
'swaps the value of the "Picture" property of the two tiles (the one that has been
'clicked and the one that was blank).

'Since the "Picture" property can be changed but it cannot be retrieved (you cannot
'execute a statement such as "Print Hotspot(1).Picture"), this game uses the "tag"
'property to store the number that identifies the picture (the "tag" property
'is unused by Adventure Maker, and therefore you can use it to store any extra
'data needed for your project).

'The puzzle is solved as soon as the "Tag" property of each tile is the same as the
'number that identifies the tile (Hotspot(1).Tag=1, Hotspot(2).Tag=2, and so on...).


' 4. ABOUT THE RANDOMIZATION PROCEDURE:

'Simply arranging the tiles randomly would lead to combinations that are impossible
'to solve. To avoid this problem, the "RandomizePuzzle" procedure uses an algorithm
'that is very similar to the one you would use to randomize a real puzzle in real life.
'It starts with the puzzle solved, and then it "moves" the blank (empty) tile up, down,
'left or right (the direction is chosen randomly), as many times as specified in the
'variable "NumberOfMovesToRandomize", the value of which can be modified in the "General
'Settings" section of the "InitializeTheGame" procedure.


' 5. ABOUT HOW TO USE THE PUZZLE IN ANOTHER ADVENTURE MAKER PROJECT:

'1. First you need to copy/paste the code below into your project.
'2. Then create a new frame and MAKE SURE THAT IT DOES NOT CONTAIN ANY HOTSPOT YET.
'3. Go to the Properties of that frame and add the statement "InitializeTheGame"
' (without the quotes) to the VBScript text field that is under the "Advanced" tab.
'4. Create one hotspot that has the size of the tiles (the tiles used in this sample
' are 60 x 60 pixels). Then go to its properties and add the statement:
' "MoveTile Action.GetHotspotNumber" (without the quotes) to the VBScript text field
' that is under the "Advanced" tab of the "Hotspot Properties" window.
'5. Then duplicate the hotspot that you have created (to do so, right-click on the
' hotspot and then click "Duplicate"), so as to create 16 identical hotspots, which
' will be used for the tiles (arrange them in a 4 x 4 grid).
'6. Hold the mouse cursor over the hotspots in order to view the number that identifies
' each of them, and make sure that they are ordered as follows:
'
' #1 #2 #3 #4
' #5 #6 #7 #8
' #9 #10#11#12
' #13#14#15#16
'
'7. Create one large hotspot that will contain the picture of the puzzle solved.
' Make sure that it is the 17th hotspot you create (it must be named "Hotspot #17").
'8. Create two text boxes (to do so, right-click on the background in the editor,
' enter a text of your choice, click OK, select a font, and then click OK again).
' The two text boxes will be used to display the level number and the number of moves.
'9. Copy the graphic files that are in the "Areas" subfolder of the "Slider Puzzle"
' folder into the "Areas" subfolder of your project folder.
'10 That's all! Have fun! An acknowledgement in the credits would be appreciated but is
' not required.


' 6. ABOUT HOW TO CUSTOMIZE THE PUZZLE:

'To change the number of levels or the number of tiles, change the values that are under
'the "General Settings" section of the procedure named "InitializeTheGame". If you want,
'you can even create rectangular puzzles.

'To customize the graphics, edit the JPEG files that are in the "Areas" subfolder of the
'"Slider Puzzle" project folder. Rename the graphic files so that the filename contains
'both the number of the level and the number that identifies the tile. For example, the
'file "Level1_Tile6.jpg" corresponds to the 6th tile of the first level.




'**************************** START OF CODE *********************************


'************************* GAME INITIALIZATION ******************************

'(This procedure is called when the game starts)


Sub InitializeTheGame()
   

    'GENERAL SETTINGS:
    'ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ


    NumberOfLevels = 3
    NumberOfTilesHorizontally = 4
    NumberOfTilesVertically = 4
    NumberOfMovesToRandomize = 300
    SolutionHotspotNumber = 17


    'START FIRST LEVEL:
    'ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

    LevelNumber = 1
    InitializeTheLevel

End sub


'************************* LEVEL INITIALIZATION ****************************************
'(This procedure is called both when the game starts and when it goes to the next level)


Sub InitializeTheLevel()
   

    'PREPARE VARIABLES AND TEXT MESSAGES:
    'ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

    NumberOfMoves = 0
    Text(1).Caption = "Number of moves: 0"
    Text(2).Caption = "Level " + Cstr(LevelNumber)


    'LOAD THE PICTURE OF THE PUZZLE SOLVED ON THE LEFT:
    'ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

    Action.LoadAPicture Hotspot(SolutionHotspotNumber), "Level"+cstr(LevelNumber)+"_Solved.jpg"


    'RANDOMIZE THE PUZZLE:
    'ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

    RandomizePuzzle()

End sub


'************** PROCEDURE TO MOVE THE TILE THAT HAS BEEN CLICKED ******************
'(This procedure is called when the player clicks on a tile)


Sub MoveTile(TileNumber)


    'PREPARE VARIABLES:
    'ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

    Dim TotalNumberOfTiles, NOTH, NOTV, i
    NOTH = NumberOfTilesHorizontally
    NOTV = NumberOfTilesVertically
    TotalNumberOfTiles = NOTH * NOTV


    'FIND THE BLANK TILE:
    'ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

    Dim BlankTileNumber
    BlankTileNumber = 0


        'LOOK UP:
        'ŻŻŻŻŻŻŻŻ

        if TileNumber > (NOTH) then if Hotspot(TileNumber - NOTH).tag = 0 then BlankTileNumber = TileNumber - NOTH

        'LOOK DOWN:
        'ŻŻŻŻŻŻŻŻŻŻ

        if TileNumber < ((NOTV - 1) * NOTH + 1) then if Hotspot(TileNumber + NOTH).tag = 0 then BlankTileNumber = TileNumber + NOTH

        'LOOK LEFT:
        'ŻŻŻŻŻŻŻŻŻŻ

        if (TileNumber mod NOTH) <> 1 then if Hotspot(TileNumber - 1).tag = 0 then BlankTileNumber = TileNumber - 1

        'LOOK RIGHT:
        'ŻŻŻŻŻŻŻŻŻŻŻ

        if (TileNumber mod NOTH) <> 0 then if Hotspot(TileNumber + 1).tag = 0 then BlankTileNumber = TileNumber + 1


    'IF NO BLANK TILE WAS FOUND, QUIT:    
    'ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

    if BlankTileNumber = 0 then exit sub


    'MOVE TILE:
    'ŻŻŻŻŻŻŻŻŻŻ

    Action.LoadAPicture Hotspot(BlankTileNumber), "Level"+cstr(LevelNumber)+"_Tile"+cstr(Hotspot(TileNumber).tag)+".jpg"
    set Hotspot(TileNumber).Picture = Nothing
    Hotspot(BlankTileNumber).tag = Hotspot(TileNumber).tag
    Hotspot(TileNumber).tag = 0


    'INCREASE THE "NUMBER OF MOVES" COUNTER:
    'ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

    NumberOfMoves = NumberOfMoves + 1
    Text(1).Caption ="Number of moves: " + Cstr(NumberOfMoves)


    'CHECK TO SEE IF THE PUZZLE IS SOLVED:
    'ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

    Dim PuzzleSolved : PuzzleSolved = True : i = 1
    do until i >= TotalNumberOfTiles or PuzzleSolved = False
        If CInt(Hotspot(i).Tag) <> CInt(i) then PuzzleSolved = False
        i = i + 1
    loop


    'IF THE PUZZLE IS SOLVED, SHOW THE HIDDEN TILE AND THEN LOAD THE NEXT LEVEL:
    'ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

    If PuzzleSolved = True then
        Action.LoadAPicture Hotspot(TotalNumberOfTiles), "Level" + CStr(LevelNumber) + "_Tile" + CStr(TotalNumberOfTiles) + ".jpg"
        MsgBox "Congratulations! You have completed Level"+CStr(LevelNumber)+" in "+CStr(NumberOfMoves)+" moves!", vbInformation, "Congratulations!"
        If LevelNumber < NumberOfLevels then
            LevelNumber = LevelNumber + 1
            InitializeTheLevel()
        Else
            MsgBox "You have completed all the levels!" + vbcrlf + vbcrlf + "Click OK to restart from Level1.", vbInformation, "Game Over"
            InitializeTheGame()
        End if
    End if

End sub


'************************ PROCEDURE TO RANDOMIZE THE PUZZLE **************************
'(This procedure is called at the end of the level initialization)


Sub RandomizePuzzle()


    'PREPARE VARIABLES:
    'ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

    Dim TotalNumberOfTiles, NOTH, NOTV, i, BlankTileNumber, NumberOfMovesLeft
    NOTH = NumberOfTilesHorizontally
    NOTV = NumberOfTilesVertically
    TotalNumberOfTiles = NOTH * NOTV
    BlankTileNumber = NOTH * NOTV
    NumberOfMovesLeft = NumberOfMovesToRandomize


    'INITIALIZE THE PUZZLE:
    'ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

    i = 1
    Hotspot (BlankTileNumber).tag = 0
    do until i >= TotalNumberOfTiles
        Hotspot(i).tag = i
        i = i + 1
    loop


    'MOVE TILES RANDOMLY:
    'ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

    Dim n : n=1
    Do Until n > NumberOfMovesLeft

        'RANDOMLY CHOOSE A TILE THAT IS CLOSE TO THE BLANK TILE (CALLED "SURROUNDING TILE"):
        'ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

        Dim Direction, SurroundingTileNumber
        SurroundingTileNumber = 0
        Randomize
        Direction = int (rnd * 4)

        'IF RANDOM DIRECTION IS UP:
        'ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

        If Direction = 0 then if BlankTileNumber > NOTH then SurroundingTileNumber = BlankTileNumber - NOTH

        'IF RANDOM DIRECTION IS DOWN:
        'ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

        If Direction = 1 then if BlankTileNumber < ((NOTV - 1) * NOTH + 1) then SurroundingTileNumber = BlankTileNumber + NOTH

        'IF RANDOM DIRECTION IS LEFT:
        'ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

        If Direction = 2 then if (BlankTileNumber mod NOTH) <> 1 then SurroundingTileNumber = BlankTileNumber - 1

        'IF RANDOM DIRECTION IS RIGHT:
        'ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

        If Direction = 3 then if (BlankTileNumber mod NOTH) <> 0 then SurroundingTileNumber = BlankTileNumber + 1

        'IF A VALID SURROUNDING TILE HAS BEEN CHOSEN, MOVE IT:
        'ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

        If SurroundingTileNumber <> 0 then
            Hotspot(BlankTileNumber).Tag = Hotspot(SurroundingTileNumber).Tag
            Hotspot(SurroundingTileNumber).Tag = 0
            BlankTileNumber = SurroundingTileNumber
        Else
            NumberOfMovesLeft = NumberOfMovesLeft + 1
        End If

    n = n + 1
    Loop


    'MOVE THE BLANK TILE TO THE BOTTOM-RIGHT CORNER OF THE PUZZLE:
    'ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
        'MOVE IT VERTICALLY:
        'ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

        Do Until BlankTileNumber >= ((NOTV - 1) * NOTH + 1)
            Hotspot(BlankTileNumber).Tag = Hotspot(BlankTileNumber + NOTH).Tag
            Hotspot(BlankTileNumber + NOTH).Tag = 0
            BlankTileNumber = BlankTileNumber + NOTH
        loop

        'MOVE IT HORIZONTALLY:
        'ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

        Do Until BlankTileNumber = TotalNumberOfTiles
            Hotspot(BlankTileNumber).Tag = Hotspot(BlankTileNumber + 1).Tag
            Hotspot(BlankTileNumber + 1).Tag = 0
            BlankTileNumber = BlankTileNumber + 1
        loop


    'LOAD ALL THE PICTURES:
    'ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

    i = 1
    do until i > TotalNumberOfTiles
        If Hotspot(i).Tag <> 0 then
            Action.loadapicture Hotspot(i), "Level" + CStr(LevelNumber) + "_Tile" + CStr(Hotspot(i).tag) + ".jpg"
        Else
            Set Hotspot(i).Picture = Nothing
        End If
        i = i + 1
    loop

End Sub



'******************************** END OF CODE *******************************

'ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ