PDA

View Full Version : help me make this into a game!


freshrod
04-22-2009, 04:09 AM
Greetings

I made this:
http://www.freshrod.com/box2.swf

It's basically a digital version of a 3D art project I also made... nothing special. Basically I was trying to figure out how to manipulate MovieClips.

But then I got the idea that this could be a little mini-game. You move the MovieClips to match a picture. But that's where I start to get stuck...

How will I do that? The best I can come up with is if you could have a variable for each MovieClip position (I can imagine the rotation, but not the flipping. I used a transform matrix...), then a button that check the current positions against whatever the picture positions are.

But even if I'm right, I really have no idea how you would do that. Can someone point me in the right direction? Perhaps I'm way off and there is a better way? I'm open to suggestions. Thanks.

bluemagica
04-22-2009, 07:32 AM
WTF? transformation matrix for this? ...... oh well
on clockwise rotation button press: mc1._rotation*=90;
on anti-clockwise rotation button press: mc1._rotation*=-90;
on horizontal flip button press: mc1._xscale*=-1;
on vertical flip button press: mc1._yscale*=-1;

freshrod
04-22-2009, 01:42 PM
ummm.... Thanks for the reply, I guess.

The reason for the transform matrix is that mc1._xscale*=-1; (in addition to being AS2, and I use AS3) won't give the desired effect once the MovieClip is rotated. It's based off the reference point. Once the MovieClip rotates it would no longer flip it the same way. Hence, the transform matrix which is based off the MovieClips current orientation.

Next time could you make your response relevant to the question?
Grand Wizard? WTF???

rrh
04-22-2009, 02:16 PM
If it's a matching game, then you'll need to acknowledge things like two flips looks the same as rotating 180 degrees.

So each time you move one, you check that all the layers are layered in the same order. If they are, then you compare the orientation of each layer to the corresponding layer in the target.

freshrod
04-22-2009, 03:09 PM
Thanks for the reply (seriously), rrh

I agree with what you said, and I think I have an idea about how to do the orientation... at least with the rotation. Instead of checking each frame (which I am worried would cause slowdown) I was thinking of having a button that will initiate the check. The user would click it when they thought they have a match.

But I really don't know how to do the layer check, nor how to address the flips. Anyone have an idea how I could check this against what they should be?

scarce
04-22-2009, 04:06 PM
Thanks for the reply (seriously), rrh

I agree with what you said, and I think I have an idea about how to do the orientation... at least with the rotation. Instead of checking each frame (which I am worried would cause slowdown) I was thinking of having a button that will initiate the check. The user would click it when they thought they have a match.

But I really don't know how to do the layer check, nor how to address the flips. Anyone have an idea how I could check this against what they should be?

What about if you place it in it's correct manor on the stage, get each items x and y then if the pieces are placed where they should be, you win, constantly check it from on enter_frame function

bluemagica
04-22-2009, 05:06 PM
I still don't see why the heck the transformation matrix is needed for something like this! Simply put the mc within a parent mc, and while rotating, rotate the child, while flipping, flip the parent!

As for matching, just let the mcs have variables denoting their x,y, flip angles, depths, and rotations, and match these with the player set!

runawayprisoner
04-22-2009, 06:05 PM
Thanks for the reply (seriously), rrh

I agree with what you said, and I think I have an idea about how to do the orientation... at least with the rotation. Instead of checking each frame (which I am worried would cause slowdown) I was thinking of having a button that will initiate the check. The user would click it when they thought they have a match.

But I really don't know how to do the layer check, nor how to address the flips. Anyone have an idea how I could check this against what they should be?

Well, a matching game... if it's a simple game where you decide the shapes to match, then all you need to do is store the correct values of the transformations inside, and match those values with the transformation matrix values of the object every time the player tries to match.

Say... if it's a game where the player must use the mouse and drag the shape around, then do the match every time there is mouse movements.

Easiest way to do a flip is to have a container so you can flip the shape inside whichever way you want, then rotate the container.

If you decide to go with transformation matrices, though, better use the a b c d values of the matrices. Relying on its functions is not a good idea...

freshrod
04-22-2009, 10:16 PM
... to clear up any confusion.

I originally tried this:

function flipClickRot(e:Event):void
{
tmp_mc.scaleX *= -1;
}


... this was to flip the MovieClip hortizontally, which it did, but after you rotate the MovieClip 90 degrees it no longer flips it hortizontally, but vertically. I want it to always flip it hortizontally, in relationship to the stage. Perhaps there is a way to do it... if you can actually show me a working model I will believe you, but I couldn't get it to work.

So I did this:

import flash.display.DisplayObject;
import flash.geom.Matrix;

var aLayer:layer_one = new layer_one();
var bLayer:layer_two = new layer_two();
var cLayer:layer_three = new layer_three();
var dLayer:layer_four = new layer_four();
var tmp_mc:MovieClip;

btnOne_mc.addEventListener(MouseEvent.CLICK, oneClick);
btnTwo_mc.addEventListener(MouseEvent.CLICK, twoClick);
btnThree_mc.addEventListener(MouseEvent.CLICK, threeClick);
btnFour_mc.addEventListener(MouseEvent.CLICK, fourClick);
btnCW_mc.addEventListener(MouseEvent.CLICK, cwClickRot);
btnCCW_mc.addEventListener(MouseEvent.CLICK, ccwClickRot);
btnFlipY_mc.addEventListener(MouseEvent.CLICK, reflectAboutParentYAxis);
btnFlipX_mc.addEventListener(MouseEvent.CLICK, reflectAboutParentXAxis);

function oneClick(e:Event):void
{
addChild(aLayer);
aLayer.x= 400;
aLayer.y = 225;
aLayer.gotoAndPlay(1);
tmp_mc = aLayer;
}

function twoClick(e:Event):void
{
addChild(bLayer);
bLayer.x= 400;
bLayer.y = 225;
bLayer.gotoAndPlay(1);
tmp_mc = bLayer;
}

function threeClick(e:Event):void
{
addChild(cLayer);
cLayer.x= 400;
cLayer.y = 225;
cLayer.gotoAndPlay(1);
tmp_mc = cLayer;
}

function fourClick(e:Event):void
{
addChild(dLayer);
dLayer.x= 400;
dLayer.y = 225;
dLayer.gotoAndPlay(1);
tmp_mc = dLayer;
}

function cwClickRot(e:Event):void
{
tmp_mc.rotation += 90;
}

function ccwClickRot(e:Event):void
{
tmp_mc.rotation += -90;
}

function reflectAboutParentYAxis( e:Event ) : void
{

var T:Matrix = tmp_mc.transform.matrix;

T.a = -T.a;
T.c = -T.c;

tmp_mc.transform.matrix = T;

}

function reflectAboutParentXAxis( e:Event ) : void
{

var M:Matrix = tmp_mc.transform.matrix;

M.b = -M.b;
M.d = -M.d;

tmp_mc.transform.matrix = M;

}


...and now it works, mostly.

So, like I was saying, I think I can figure out how to check the rotation of each ( an if statement that checks if a var for a, b, c, or dLayer rotation = whatever it should.
But I'm not sure how to check the flip.

Also, would you put this check in a switch statement?

rrh
04-22-2009, 11:58 PM
Perhaps there is a way to do it... if you can actually show me a working model I will believe you, but I couldn't get it to work.
What Bluemagica said:
Simply put the mc within a parent mc, and while rotating, rotate the child, while flipping, flip the parent!Your problem arose when you applied the flip and the rotation to the same movieclip.

So, like I was saying, I think I can figure out how to check the rotation of each ( an if statement that checks if a var for a, b, c, or dLayer rotation = whatever it should.
But I'm not sure how to check the flip.Like I said, the real tricky part is checking the rotation and flip at the same time, when two flips are visually equivalent to 180 degrees.


Also, would you put this check in a switch statement?That's probably not necessary, since you only have two possible results, win or don't win.

freshrod
04-24-2009, 04:13 AM
ok... I'm really trying here. I'm know I'm not an AS3 expert, but I still don't understand.

I admit I didn't catch that bluemagica was refering to two different clips (even though it didn't sound like he was in his first post), but I tried it that way too, just for the sake of being able to honestly say I tried it that way, and I couldn't get it to work.

The idea sounds good, as long as you are talking about a single MovieClip. I have four. And in order to have the button functions effect only the current top MovieClip, I had to introduce a var for it.
I don't know how you would create a var that targets the child MovieClip inside the current parent MovieClip. How would you do that?

But anyway, I have a method that works. What I REALLY need help with is the matching part. I really have no idea where to start with this. Can someone point me in the right direction? Give me some suggestions on similar functions? Show me a related tutorial or example?

I appreciate all the help. But I'm really not any closer to what I was looking for. Has anyone seen anything similar to this that would help me?

bluemagica
04-24-2009, 04:43 AM
ok try to understand this time....

1) say you have 4 symbols! Make them child of a single mc, that way, you can simply use gotoAndStop to create different symbols, and at the same time use the nested flip-rotation method i said earlier!

2) On the stage add 4 copies of the final mc, and use gotoAndStop to get the 4 symbols you need!

3) Now to get control of the movieclips, you can use a list of vars, arrays, whatever....... OR you can use the simplest method of getChildAt()....sorting through the display list based on depth is a powerful and handy feature of as3! (Another simpler method is to use the variables you used when you would addChild the mc in the first place)

4) As for the matching part there are several ways! But i think it gets easier if you generate/arrange the Actual symbols through code too.... then they will have some properties which you need to just compare with the symbols the player arranged, like if(plmc1.rotation==q1.rotation||plmc1.rotation==(q 1.rotation+180)||plmc1.rotation==(q1.rotation-180))
{
l1_match = true;
}