Home | Help Forums | Web Design Tutorials | Free Swishmax Downloads | All Downloads

 

 

Company

Home

Nework Details

Tutorials

SWiSH 2

SWiSHMax

Flash MX

PHP & MySQL

HTML / JScript

Adobe Photoshop

Corel Draw

Gimp

Miscellaneous

Downloads

Templates

Plugins

Fonts

Wallpapers

Free Images

Scripts and Codes

Products

E-Books

SWiSH BB

SWiSH Templates

SWiSH-DB Newsletter
Subscribe to our newsletter : GO
  Partners / Affiliates

   Swish Templates
   SWiSH Climax
   GimpTalk
   Idea Designs
   Sposatoettore
   Try Acai Berry Diet
   Download Free Ringtones
   Swishzone

Manage your site with Flax Article Content Management System
Making SWiSHMax Puzzle Game in 5 minutes
Category : SWiSHMax | Level : Intermediate | Language : English
Ask Question | Read Comments | Post tutorial | Previous | Next

Web www.swish-db.com

There is no need to define/write any actionscript for any button.

Follow steps

CODE

1. Start new empty SWiSH Max file
2. Insert desired image or draw rectangle and use Titled Image
  but dimensions of the the shape must be round (e.g. 201 not 201.2)
3. Break the shape into desired number of pieces using desired columns
  and rows e.g. 4 and 4. so the total pieces become (4x4) 16.
4. These pieces will automatically be grouped, your simply UpGroup them
  by pressing Ctrl+U.
5. Select all shapes click Convert to Button. So that each shape is
  converted into separate button.
6. Now rename the buttons in series are they are ordered,
  from top to bottom as b1,b2,b3, upto b16.
7. Slect the button, which you want be acting as blank piece, and set
  its alpha to 0
8. Now paste following code in you main timeline:
onLoad() {
   bw=b1._width;
   bh=b1._height;
   blankPiece = b13; //
   Result = new Array();  
   
   TOTAL_PIECES = 16;
   
   swap = function (obj1, obj2) {
       temp = new Object();
       temp._x=obj1._x;
       temp._y=obj1._y;
       
       obj1._x=obj2._x;
       obj1._y=obj2._y;
       
       obj2._x=temp._x;
       obj2._y=temp._y;
       delete temp;
   };
   
   cx=cy=0;
   for(i=TOTAL_PIECES; i>0; i--) {
       btn = eval("b"+i);
       Result[i]=new Object();
       Result[i].XX = btn._x;
       Result[i].YY = btn._y;
       
       btn.useHandCursor=false;
       if(btn == blankPiece)
           continue;
       btn.onRollOver = function() {
           this._alpha=50;
       };
       btn.onRollOut = function() {
           this._alpha=100;
       };
       btn.onPress = function() {
           if( //TOP
           blankPiece._x==this._x &&
           blankPiece._y==this._y-bh
           ) {
               swap(this,blankPiece);
               this._alpha=100;
           } else
           if( //LEFT
           blankPiece._x==this._x-bw &&
           blankPiece._y==this._y
           ) {
               swap(this,blankPiece);
               this._alpha=100;
           } else
           if( //BOTTOM
           blankPiece._x==this._x &&
           blankPiece._y==this._y+bh
           ) {
               swap(this,blankPiece);
               this._alpha=100;
           } else
           if( //RIGHT
           blankPiece._x==this._x+bw &&
           blankPiece._y==this._y
           ) {
               swap(this,blankPiece);
               this._alpha=100;
           }        
           if(CheckMove()) {
      gameWon();          
           }
       };
   }
   RandomShuffle = function (N) {
       for(i=0; i<N; i++) {
           v1=int(Math.randomRange(0,TOTAL_PIECES+1));
           v2=int(Math.randomRange(0,TOTAL_PIECES+1));
           o1 = eval("b"+v1);
           o2 = eval("b"+v2);
           swap(o1,o2);
       }      
   };
   RefreshAll = function() {
       for(i=TOTAL_PIECES; i>0; i--) {
           bt = eval("b"+i);
           bt._x=Result[i].XX;
           bt._y=Result[i].YY;
       }
   };
   CheckMove = function() {
       for(i=TOTAL_PIECES; i>0; i--) {
           bt = eval("b"+i);
           if(bt._x != Result[i].XX
               || bt._y != Result[i].YY)
           return false;
       }
       return true;
   }
}

9. Change the button name in following line of code
  I had b13 acting as blank piece you may assign any button name
  which is used as blank piece

  blankPiece = b13;

10. Then assign the value to variable TOTAL_PIECES as the number of
   pieces. If you have 16 buttons, just assign 16 to it

   e.g.
   TOTAL_PIECES = 16;

GAME IS READY

now

I. To refresh the board use thi way

on(press) {
  RefreshAll();
}

II. To shuffle blocks/pieces use

on(press) {
  RandomShuffle(3);
}

where 3 is the number of shuffles, to make game more tough increase it



Q. How to know the user has completed the game?

implement function 'gameWin()' in your main timeline and write code in it
what soever yo uwish to do when user wins, such as

function gameWin() {
Message = "Congratulations! You have compelted";
}

or even you may implement it within onLoad event handler of the
main timeline such as

onLoad() {
   ......
   ......
   ......
   ......
   ......
   ......
   
   gameWin = function() {
Message = "Congratulations! You have compelted";
   };
}

That's it.


recomendation:

To have 100% results use image of sme width and height
and put imge on round position before cutting in pieces (as X:110, Y:112 not X:110.3, Y:112.45)



Please download the example file from
http://www.swish-db.com/forum/index.php?sh...topic=13192&hl=


All rights reserved - swish-db.com