Pipeline

http://www.flash-game.net/game/2267/balloon-parky.html
i am trying to develop this type of game so i dont want

to write hitTest on every clips , is ther any other logic which can help to connect the pipes and change their color when they are connected with each other , pipes can be randomly placed within tiles…any help

i’d say use an array

for eg;

var pipes:Array = [
[0, 0, 0, 1, 0, 0, 1, 0, 1],
[0, 0, 0, 1, 1, 1, 1, 0, 1],
[0, 0, 0, 0, 0, 1, 0, 0, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 1]
];

Where the value 1 will represent a block of pipe; then check if there’s a value of 1 before or after, or in the corresponding items in the previous or following arrays.

Hittest? I wouldn’t have even thought of using hittest for this, so I really don’t grok how you’re approaching this.

I would have a square array of pipes, but not just numbers like nathan did. I would make a pipe class, with a rotate method, and four methods that return values for top, bottom, right, left. And also a change colour method, which is passed a direction and a colour value. If it is open in that direction and it is not already that colour, it changes colour and calls the change colour method on all tiles it is connected to.

O I didn’t look at the link - so it’s different to what I originally thought - If I get time I’ll make a demo

[quote=rrh;2331317]Hittest? I wouldn’t have even thought of using hittest for this, so I really don’t grok how you’re approaching this.

I would have a square array of pipes, but not just numbers like nathan did. I would make a pipe class, with a rotate method, and four methods that return values for top, bottom, right, left. And also a change colour method, which is passed a direction and a colour value. If it is open in that direction and it is not already that colour, it changes colour and calls the change colour method on all tiles it is connected to.[/quote]

can you show me the demo …

[quote=nathan99;2331258]i’d say use an array

for eg;
ActionScript Code:
[LEFT][COLOR=#000000]var[/COLOR] pipes:[COLOR=#0000FF]Array[/COLOR] = [COLOR=#000000][[/COLOR]
[COLOR=#000000][[/COLOR][COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]1[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]1[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]1[/COLOR][COLOR=#000000]][/COLOR],
[COLOR=#000000][[/COLOR][COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]1[/COLOR], [COLOR=#000080]1[/COLOR], [COLOR=#000080]1[/COLOR], [COLOR=#000080]1[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]1[/COLOR][COLOR=#000000]][/COLOR],
[COLOR=#000000][[/COLOR][COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]1[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]1[/COLOR][COLOR=#000000]][/COLOR],
[COLOR=#000000][[/COLOR][COLOR=#000080]1[/COLOR], [COLOR=#000080]1[/COLOR], [COLOR=#000080]1[/COLOR], [COLOR=#000080]1[/COLOR], [COLOR=#000080]1[/COLOR], [COLOR=#000080]1[/COLOR], [COLOR=#000080]1[/COLOR], [COLOR=#000080]1[/COLOR], [COLOR=#000080]1[/COLOR][COLOR=#000000]][/COLOR],
[COLOR=#000000][[/COLOR][COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]1[/COLOR][COLOR=#000000]][/COLOR],
[COLOR=#000000][[/COLOR][COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]1[/COLOR][COLOR=#000000]][/COLOR]
[COLOR=#000000]][/COLOR];

[/LEFT]

Where the value 1 will represent a block of pipe; then check if there’s a value of 1 before or after, or in the corresponding items in the previous or following arrays.[/quote]

but i want to rotate the pipe when user click on that, 1 shows the existence of pipe now how to rotate with diff shapes…

here is my fla

i got the solutions .

That’s a pretty cool monologue you have there.

I think you should post the “solutions” you have for people that might find this topic in a search, looking for the same problem.

rahul_7star is there any chance you could post your file in flash 8

thanks

neil

That’s if you are only talking about binary array… You can use rest of whatever is flash’s integer values.

Considering the pipes rotate in one direction, this is very easy.

You can say,

0 = empty space
1 = horizontal pipe
10 = elbow pipe
20 = cross pipe

then,

2 = horizontal pipe in vertical position
11 = elbow pipe from top to left
12 = elbow pipe from left to down
13 = elbow pipe from down to right
14 = elbow pipe from right to top

and you can even make use of other numbers…

111 = elbow pipe from top to left in blue color
211 = elbow pipe from top to left in yellow colour.

… so in the end, it’s all how you set the convention.

When you are checking if a path exist, you just have to check if one of the gas outlet is linked with, say, any pipe line with values greater than 100 or 200…etc.

So to use the array example above, following will be a winning combo


pipes:Array = [
[101,    0,     0,     1,    0,    0,     1,     0, 201],
[    0,    0,     0,     1,    1,    1,     1,     0, 201],
[    0,    0, 113, 101, 101, 101, 101, 101, 201],
[101, 101, 111,    1,     1,    1,     1,     1, 201],
[    0,    0,     0,    0,     0,    0,     0,     0, 201],
[    0,    0,     0,    0,     0,    0,     0,     0, 201]
];

[quote=misterooga;2332646]That’s if you are only talking about binary array… You can use rest of whatever is flash’s integer values.

Considering the pipes rotate in one direction, this is very easy.

You can say,

0 = empty space
1 = horizontal pipe
10 = elbow pipe
20 = cross pipe

then,

2 = horizontal pipe in vertical position
11 = elbow pipe from top to left
12 = elbow pipe from left to down
13 = elbow pipe from down to right
14 = elbow pipe from right to top

and you can even make use of other numbers…

111 = elbow pipe from top to left in blue color
211 = elbow pipe from top to left in yellow colour.

… so in the end, it’s all how you set the convention.

When you are checking if a path exist, you just have to check if one of the gas outlet is linked with, say, any pipe line with values greater than 100 or 200…etc.

So to use the array example above, following will be a winning combo


pipes:Array = [
[101,    0,     0,     1,    0,    0,     1,     0, 201],
[    0,    0,     0,     1,    1,    1,     1,     0, 201],
[    0,    0, 113, 101, 101, 101, 101, 101, 201],
[101, 101, 111,    1,     1,    1,     1,     1, 201],
[    0,    0,     0,    0,     0,    0,     0,     0, 201],
[    0,    0,     0,    0,     0,    0,     0,     0, 201]
];

[/quote]

Thanks for this reply , but its ok that you can place pipe of any size either “L” shape or “U"shape , but the problem is that whenevr you click on 'U” shape U should move and should not call “L” shape, here is my fla …chk it.

whenver you click on “I” shape “I” should move in corresponding direction and it should not call U shape …

a

[quote=neilmmm;2332628]rahul_7star is there any chance you could post your file in flash 8

thanks

neil[/quote]

HI here is flash 8 fla

[quote=misterooga;2332646]That’s if you are only talking about binary array… You can use rest of whatever is flash’s integer values.

Considering the pipes rotate in one direction, this is very easy.

You can say,

0 = empty space
1 = horizontal pipe
10 = elbow pipe
20 = cross pipe

then,

2 = horizontal pipe in vertical position
11 = elbow pipe from top to left
12 = elbow pipe from left to down
13 = elbow pipe from down to right
14 = elbow pipe from right to top

and you can even make use of other numbers…

111 = elbow pipe from top to left in blue color
211 = elbow pipe from top to left in yellow colour.

… so in the end, it’s all how you set the convention.

When you are checking if a path exist, you just have to check if one of the gas outlet is linked with, say, any pipe line with values greater than 100 or 200…etc.

So to use the array example above, following will be a winning combo


pipes:Array = [
[101,    0,     0,     1,    0,    0,     1,     0, 201],
[    0,    0,     0,     1,    1,    1,     1,     0, 201],
[    0,    0, 113, 101, 101, 101, 101, 101, 201],
[101, 101, 111,    1,     1,    1,     1,     1, 201],
[    0,    0,     0,    0,     0,    0,     0,     0, 201],
[    0,    0,     0,    0,     0,    0,     0,     0, 201]
];

[/quote]

2 = horizontal pipe in vertical position
11 = elbow pipe from top to left
12 = elbow pipe from left to down
13 = elbow pipe from down to right
14 = elbow pipe from right to top

these are just frame number i thnk…is it…!

ty for the file

what is that[quote=neilmmm;2333711]ty for the file[/quote]

[quote=rahul_7star;2333705]2 = horizontal pipe in vertical position
11 = elbow pipe from top to left
12 = elbow pipe from left to down
13 = elbow pipe from down to right
14 = elbow pipe from right to top

these are just frame number i thnk…is it…![/quote]

Yes, I have been thinking in copyPixel too much lately… haha.

plz see my Fla , i need help ,[quote=misterooga;2333734]Yes, I have been thinking in copyPixel too much lately… haha.[/quote]

i like the game and have had a go … gone in a completely different direction … i don’t think it is the right direction

but here is my code … perhaps someone will respnd to help move it on

var counter:Number = 0;
var mc_id:Number;
var mcConnectionArray:Array=new Array();
var tempArray:Array=newArray();
var mc_type:String;
var empty:MovieClip=this.createEmptyMovieClip("holder",this.getNextHighestDepth());
var target_mc:MovieClip;
function checkleft (target) {
 //trace("checkleft called");
 //trace (empty["pipe"+target]._name)
 //trace ("target array ="+empty["pipe"+target].mcConnectionArray.length)
 /*for (k=0;k<empty["pipe"+target].mcConnectionArray.length;k++) {
  trace(empty["pipe"+target].mcConnectionArray[k])
}
for (i=0;i<tempArray.length;i++) {
 trace (" checking left fornd tempArray = "+tempArray*);
}*/
//if (empty["pipe"+target].mc_type=="straight") {
 if (empty["pipe"+target].mcConnectionArray[1]=="right"&&empty["pipe"+(target+1)].mcConnectionArray[3]=="left") {
  trace("yep");
  trace ("cuurent frame ="+empty["pipe"+(target+1)]._currentframe);
  empty["pipe"+(target+1)].gotoAndStop(2);
}else{
 trace("no");
 empty["pipe"+(target+1)].gotoAndStop(1);
}

//}
}
 
function spinPipe () {
 
 for (k=0;k<this.mcConnectionArray.length;k++) {
  //trace(this.mcConnectionArray[k])
}
 this._rotation+=90;
 
 if (this._rotation==0) {
  //trace ("rotation =0");
  this.mcConnectionArray=["top","right","no","no"];
}else if(this._rotation==90){
 //trace ("rotation =90");
 this.mcConnectionArray=["no","right","bottom","no"];
}else if(this._rotation==180){
 //trace ("rotation =180");
 this.mcConnectionArray=["no","no","bottom","left"];
}else{
 //trace ("rotation =-90");
 this.mcConnectionArray=["top","no","no","left"];
}
 tempArray=[];
 
 //trace(this.mc_id);
 //trace(this._rotation);
 for (k=0;k<this.mcConnectionArray.length;k++) {
  //trace(this.mcConnectionArray[k])
  tempArray.push(this.mcConnectionArray[k]);
  //trace("tempArray "+k+" = "+tempArray[k]);
}
trace("");
trace(this._name);
trace (this.mc_id-1)
checkleft(this.mc_id-1);
 
 
}
for (i=0; i<10; i++) {
 for (j=0; j<10; j++) {
  counter++;
  if (j==0) {
   var mc:MovieClip =  empty.attachMovie("straightPipe", "pipe"+counter, counter);
  mc._x = mc._width*j;
  mc._y = mc._height*i;
  mc.mc_type="straight";
  mc.gotoAndStop(2);
mc.mcConnectionArray=["no","right","no","left"];
  
  mc._rotation=90;
  mc.mc_id=counter;
  //mc.onRelease=spinPipe;
   
   
}else if (j==9){
var mc:MovieClip =  empty.attachMovie("straightPipe", "pipe"+counter, counter);
  mc._x = mc._width*j;
  mc._y = mc._height*i;
  mc.mc_type="straight";
  mc.gotoAndStop(3);
mc.mcConnectionArray=["no","right","no","left"];;
  
  mc._rotation=90;
  mc.mc_id=counter;
}else{
  var mc:MovieClip =  empty.attachMovie("elbowPipe", "pipe"+counter, counter);
  mc._x = mc._width*j;
  mc._y = mc._height*i;
  mc.mc_type="elbow";
  mc._rotation=(Math.floor(Math.random()*4)*90);
  mc.mc_id=counter;
  //// add rotatio id
  if (mc._rotation==0) {
  
  mc.mcConnectionArray=["top","right","no","no"];
}else if(mc._rotation==90){
 
 mc.mcConnectionArray=["no","right","bottom","no"];
}else if(mc._rotation==180){
 
 mc.mcConnectionArray=["no","no","bottom","left"];
}else{
 
 mc.mcConnectionArray=["top","no","no","left"];
}
  
  
  /// end rotation id
  mc.onRelease=spinPipe;
}
 }
 
}
empty._xscale=empty._yscale=130
0;
 empty._x=(Stage.width- empty._width)/2;
 empty._y=(Stage.height- empty._height)/2;

if you look at the attach file

a pipe will change colour if it connects to the one on the left but not dependent on touching one on the left or right

to check right is roughly the asme code but target is +1, to check up is target -10, to below is target +10

i might do more at a later date …if i feel i am going in the right direction