PDA

View Full Version : so ive made a flash jigsaw


daman2k
02-28-2005, 11:19 PM
what code would i use to display a congratulations message when the puzzle is complete?

PabloPicasso
02-28-2005, 11:36 PM
you could tell it that once the jigsaw is complete(using arrays) to jump to a frame with congrats or whatever on....

:)

daman2k
02-28-2005, 11:38 PM
ah ok, mate im a newbie, could u show me an example of the code?

Doccie
02-28-2005, 11:43 PM
Here (http://cmdstud.khlim.be/~phelsen/Puzzel.zip) you'll find a puzzel I did... That should do the trick...

Basically you have to create a variable that stores the location of the pieces and then when they're all on the right place, go to a frame or make a textfield displaying 'You win' or whatever :)

youknowsit
02-28-2005, 11:49 PM
Well how do you know when your puzzle is complete? Do you just drag objects together and do they snapto on hit with another object. Do you use co-ordinates or vectors to tell if they are in the correct place? If you could explain a bit more about how you made your puzzle, prehaps with some code, that would be a great help.

Generally conditional statements will solve this problem i.e. for co-ordinate based...

for (i = 1; i == 9; i++)
{object[i];
if
{
(object[i]._x + 30 == object[i+1]._x) && (object[i]._y == object[i+1]._y)
trace("Well done mate...");
}

Use the trace to see if it works. After that create a dynamic text box on the form and set that as a string variable and set the value of the string to your congrats message.

daman2k
02-28-2005, 11:53 PM
ok mate, what i have done is used co-ordinates so that when they get near there location they snap into place

example of the code

on(press)
{
startDrag("aa1");
}
on(release)
{
stopDrag();
if(aa1._x >80 &aa1._x < 170 && aa1._y> 70 && aa1._y<160)
{
setProperty("aa1",_x,"128.9")
setProperty("aa1",_y,"113.5")

}
}

youknowsit
03-01-2005, 12:35 AM
What I would do is have the properties for each piece within the object such as:-

on(press)
{
startDrag("aa1");
}
on(release)
{
stopDrag();

within each pieces actions.

Then have a function to implement the match for each possible match:-

So far piece 1....

function setPiece1():Boolean
{
if((aa1._x > 80 && aa1._x < 170) && (aa1._y> 70 && aa1._y< 160))
{
setProperty("aa1",_x,"128.9") /* or aa1._x = 128.9; will do the trick if using actionscript 2.0*/
setProperty("aa1",_y,"113.5")
var match:Boolean = true;
};

For each possible match.

Declare boolean variables called piece1, piece2 etc...

this.onEnterFrame = function:Void()
{
var piece1:Boolean = setPiece1;
var piece2:Boolean = setPiece2;....etc
if{
(match1 == true) && (match2 == true);...etc
var fscore = "well done";
}
}

This is a long winded way of doing it and could be simplified in terms of time and lines of coding using arrays but I think it should solve your problem. This is where fscore is the dynamic text box variable.

daman2k
03-01-2005, 12:40 AM
thanks a lot mate, ill give that a go in the morning

youknowsit
03-01-2005, 12:45 AM
No probs mate! Should work, I been doing a similar thing and mine works fine for matching shapes.

daman2k
03-01-2005, 09:51 AM
lol i am strugling with this, it stops by bits from moving?

youknowsit
03-01-2005, 09:39 PM
Your bits should move fine as long as the on(press) and on(release) functions are within the actions for each piece.

on(press)
{
startDrag(this, false);

}
on(release)
{
stopDrag();
}

youknowsit
03-01-2005, 09:43 PM
Your bits should move fine as long as the on(press) and on(release) functions are within the actions for each piece. So the actions for aa1 would be....

on(press)
{
startDrag(this, false);
}
on(release)
{
// Tis below can be used as deggugging info to check your shapes go where you think they will
_root.xpos = getProperty(_target, _x);
trace("Piece x pos = ");
trace(this._x);
_root.ypos = getProperty(_target, _y);
trace("Piece y pos = ");
trace(this._y);
depth = _root.getDepth();
trace("Depth");
trace(depth);
stopDrag();
}