[DBarbarian Entry 6] - 25 Line Breakout
Posted in: enart.nnmj.com Date: March 11th, 2010

Bombsledder: I would be happy to take this entry out of the competition if you wish, as you did post about breakout first.
The collision response might be off sometimes when the ball just skims a corner of a brick. I was two if statements away from a complete collision detection system. :upset:
Don't steal my code bombsledder. ;) :)
this.pA = function(n,prop,val) {
this.methodsA = {beginFill:["c","a"],moveTo:["x","y"], lineStyle:["w","c","a"], lineTo:["x","y"], clear:, _x:["x"], _y:["y"],h2:["h"],w2:["w"], val:["v"],s:["s"],ang:["a"],mx:["x"],my:["y"],solid:["s"],sub:["s"],numT:["t"],col:["c"]};
(prop == "beginFill" or prop == "moveTo" or prop=="lineStyle" or prop=="lineTo" or prop=="clear") ? n[prop](val[this.methodsA[prop][0]],val[this.methodsA[prop][1]],val[this.methodsA[prop][2]],val[this.methodsA[prop][1]],val[this.methodsA[prop][3]]) : n[prop]=(val[this.methodsA[prop][0]]);
return ((n!=this.o1 and n!=this.o2 and n!=this.o3) ? n._parent._parent : n._parent);
}
this.reset = function() {
for (i=1;i<4;i++) {
this.createEmptyMovieClip("o"+i,i*10);
}
this.pA(this.o1,"lineStyle",{w:2,c:0xFFFFFF,a:100})[this].pA(this.o1,"lineTo",{x:390,y:0})[this].pA(this.o1,"lineTo",{x:390,y:345})[this].pA(this.o1,"lineTo",{x:0,y:345})[this].pA(this.o1,"lineTo",{x:0,y:0});
this.pA(this.o2,"beginFill",{c:0xFFFFFF,a:100})[this].pA(this.o2,"lineStyle",{w:5,c:0xFFFFFF,a:50})[this].pA(this.o2,"moveTo",{x:-30,y:-4.5})[this].pA(this.o2,"lineTo",{x:30,y:-4.5})[this].pA(this.o2,"lineTo",{x:30,y:4.5})[this].pA(this.o2,"lineTo",{x:-30,y:4.5})[this].pA(this.o2,"lineTo",{x:-30,y:-4.5})[this].pA(this.o2,"_x",{x:195})[this].pA(this.o2,"_y",{y:320});
this.pA(this.o3,"lineStyle",{w:10,c:0xFFFFFF,a:100})[this].pA(this.o3,"lineTo",{x:.2,y:0})[this].pA(this.o3,"_x",{x:195})[this].pA(this.o3,"_y",{y:(this.o2._y-4.5-5)})[this].pA(this.o3,"s",{s:0})[this].pA(this.o3,"ang",{a:-15*Math.PI/36})[this].pA(this.o3,"h2",{h:5})[this].pA(this.o3,"w2",{w:5})[this].pA(this.o3,"sub",{s:0});
for (i=0;i<312;i++) {
this.o1.createEmptyMovieClip(t="t_"+Math.floor(i/13)+"_"+(i%13),i+1).val = ((i<130) ? (random(9)-5) : 0);
(i<130 and this.o1[t].val>0) ? this.pA(this.o1[t],"beginFill",{c:("0x"+(9-2*this.o1[t].val+1)+(9-2*this.o1[t].val+1)+(2*this.o1[t].val-1)+(2*this.o1[t].val-1)+(5+2*this.o1[t].val)+(5+2*this.o1[t].val)),a:100}).pA(this.o1[t],"lineStyle",{w:2,c:0xFFFFFF,a:100}).pA(this.o1[t],"lineTo",{x:30,y:0}).pA(this.o1[t],"lineTo",{x:30,y:15}).pA(this.o1[t],"lineTo",{x:0,y:15}).pA(this.o1[t],"lineTo",{x:0,y:0}).pA(this.o1[t],"_x",{x:(i%13)*30}).pA(this.o1[t],"_y",{y:Math.floor(i/13)*15}).pA(this.o1[t],"solid",{s:"true"}).pA(this.o3,"numT",{t:++this.tT}):this.pA(this.o1[t],"solid",{s:"false"}).pA(this.o1[t],"val",{v:0});
}
}
this.move = function(n,mx,my) {
(n._y>345+n.h2) ? this.pA(n,"s",{s:0})[this].pA(n,"_x",{x:this.o2._x})[this].pA(n,"_y",{y:(this.o2._y-4.5-n.h2)})[this].pA(n,"ang",{a:-15*Math.PI/36}):null;
(Math.abs(n._x-this.o2._x)
this.hit = function(n,r,c) {
if ((this.o1["t_"+r+"_"+c].val>0 or this.o1["t_"+r+"_"+c].val==undefined) and Math.abs(n._x-(c*30)-15)<(n.w2+15) and Math.abs(n._y-(r*15)-7.5)<(n.h2+7.5) and (15)-Math.abs(n._x-(c*30)-15)<=(7.5)-Math.abs(n._y-(r*15)-7.5)) {
(this.o1["t_"+r+"_"+(c+((n._x<(c*30)+15) ? -1 : 1))].solid == "false") ? (this.pA(n,"_x",{x:(c*30)+15+((n._x<(c*30)+15) ? (-n.w2-16) : (n.w2+16))})[this].pA(n,"ang",{a:(Math.PI-n.ang)})[this].pA(n,"sub",{s:-1})) : (this.pA(n,"_y",{y:(r*15)+7.5+((n._y<(r*15+7.5)) ? (-n.h2-8.5) : (n.h2+8.5))})[this].pA(n,"ang",{a:-n.ang})[this].pA(n,"sub",{s:-1}));
} else if ((this.o1["t_"+r+"_"+c].val>0 or this.o1["t_"+r+"_"+c].val==undefined) and Math.abs(n._x-(c*30)-15)<(n.w2+15) and Math.abs(n._y-(r*15)-7.5)<(n.h2+7.5) and (15)-Math.abs(n._x-(c*30)-15)>(7.5)-Math.abs(n._y-(r*15)-7.5)) {
(this.o1["t_"+(r+((n._y<(r*15)+7.5) ? -1 : 1))+"_"+c].solid == "false") ? (this.pA(n,"_y",{y:(r*15)+7.5+((n._y<(r*15+7.5)) ? (-n.h2-8.5) : (n.h2+8.5))})[this].pA(n,"ang",{a:-n.ang})[this].pA(n,"sub",{s:-1})) : (this.pA(n,"_x",{x:(c*30)+15+((n._x<(c*30)+15) ? (-n.w2-16) : (n.w2+16))})[this].pA(n,"ang",{a:(Math.PI-n.ang)})[this].pA(n,"sub",{s:-1}));
}
(n.sub!=0 and (this.o1["t_"+r+"_"+c].val+n.sub)==0) ? (this.pA(this.o1["t_"+r+"_"+c],"val",{v:0}).pA(this.o1["t_"+r+"_"+c],"solid",{s:"false"}).pA(this.o1["t_"+r+"_"+c],"clear",{}).pA(n,"sub",{s:0}).pA(n,"numT",{t:(--this.tT)})):(this.pA(this.o1["t_"+r+"_"+c],"val",{v:this.o1["t_"+r+"_"+c].val+n.sub}).pA(this.o1["t_"+r+"_"+c],"col",{c:-n.sub}).pA(n,"sub",{s:0}));
(this.o1["t_"+r+"_"+c].col==1 and this.o1["t_"+r+"_"+c].val>0) ? this.pA(this.o1["t_"+r+"_"+c],"beginFill",{c:("0x"+(9-2*this.o1["t_"+r+"_"+c].val+1)+(9-2*this.o1["t_"+r+"_"+c].val+1)+(2*this.o1["t_"+r+"_"+c].val-1)+(2*this.o1["t_"+r+"_"+c].val-1)+(5+2*this.o1["t_"+r+"_"+c].val)+(5+2*this.o1["t_"+r+"_"+c].val)),a:100}).pA(this.o1["t_"+r+"_"+c],"lineStyle",{w:2,c:0xFFFFFF,a:100}).pA(this.o1["t_"+r+"_"+c],"lineTo",{x:30,y:0}).pA(this.o1["t_"+r+"_"+c],"lineTo",{x:30,y:15}).pA(this.o1["t_"+r+"_"+c],"lineTo",{x:0,y:15}).pA(this.o1["t_"+r+"_"+c],"lineTo",{x:0,y:0}).pA(this.o1["t_"+r+"_"+c],"col",{c:0}) : null;
return n;
}
this.onEnterFrame = function() {
(this._xmouse<(360) and (this._xmouse>30)) ? (this.o2._x = this._xmouse):(this.o2._x = 195+((this._xmouse-195)/Math.abs(this._xmouse-195))*(165));
(this.o3.s == 0) ? (this.o3._x = this.o2._x):this.move(this.o3,this.o3._x+=((this.o 3.s<6) ? (this.o3.s+=.0005):(this.o3.s))*Math.cos(this.o3.a ng),this.o3._y+=this.o3.s*Math.sin(this.o3.ang));
(this.o3.numT <1) ? this.reset() : null;
this.hit(this.o3,Math.floor(this.o3._y/15)+(((Math.round(this.o3._y)%15)<7.5) ? -1 : 1),Math.floor(this.o3._x/30))._parent.hit(this.o3,Math.floor(this.o3._y/15),Math.floor(this.o3._x/30)+(((Math.round(this.o3._x)%30)<15) ? -1 : 1))._parent.hit(this.o3,Math.floor(this.o3._y/15),Math.floor(this.o3._x/30));
}
this.onMouseDown = function() {
(this.o3.s == 0) ? this.pA(this.o3,"s",{s:2}) : null;
}
gl =)
kdd: thanks. :)
kirupa: :pleased:
Sinister Shadow: Thanks. And a BIG thanks for posting that function :thumb2:
kookaburra: Glad you like it.
ketan: thanks m8
jerez_z: Thank you. I think this will be my last one though. I really need to get started on my school work. :(
hybrid101: thanks
nathan99: Yea, Sinister posted it in the guidlines and kirupa said it was fine:
Also, sinister's method of having the lineTo/lineStyle/moveTo data being stored in an array is acceptable....and clever :hugegrin:
treatkor: Without the restriction, it's a lot easier to read with a lot of short if/else statements.
I originally planned to have set levels, so that's why the reset thing is there. But I ran out of room, so only random maps are regenerated. Glad you noticed though =)
sedthh: Yea, I can't believe it either, lol. :)
-Matt
So I'm not the only one then? I feel much better now! :geek:
That's funky, dbarb!
what would this code look like if written out "normally"? (without the 25 line restriction)
that's nice of you to say.
Don't steal my code bombsledder.
:lol:
very nice job...
nice work!.. but is this allowed?
or is that characterised as "daisy-chaining"?
#If you have any other info about this subject , Please add it free.# |
