PDA

View Full Version : [DBarbarian Entry 6] - 25 Line Breakout


dbarbarian
01-18-2006, 12:14 AM
Man. Finally finished this thing. :ko:

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)<n.w2+30 and Math.abs(n._y-this.o2._y)<n.h2+4.5) ? (this.pA(n,"_y",{y:(this.o2._y-4.5-n.h2)})[this].pA(n,"ang",{a:(-Math.PI/2+((n._x-this.o2._x)/(n.w2+30))*(Math.PI/3))})):null;
}

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;
}

ElectricGrandpa
01-18-2006, 12:57 AM
Sweet job. Since you're using a "chaining" function too(pA), do you find that it takes a hell of a long time to program in that form? It's so much of a pain it almost makes me want to make a parser to convert normal code into chained function code... heh

kdd
01-18-2006, 01:07 AM
Bombsledder: I would be happy to take this entry out of the competition if you wish, as you did post about breakout first.
that's nice of you to say.

Don't steal my code bombsledder.
:lol:

very nice job...

kirupa
01-18-2006, 01:13 AM
Really nice :)

Sinister Shadow
01-18-2006, 01:15 AM
Sweet job. Since you're using a "chaining" function too(pA), do you find that it takes a hell of a long time to program in that form? It's so much of a pain it almost makes me want to make a parser to convert normal code into chained function code... heh

So I'm not the only one then? I feel much better now! :geek:

That's funky, dbarb!

kookaburra
01-18-2006, 01:20 AM
Really nice one.

ketan
01-18-2006, 01:23 AM
Really Gr8

jerez_z
01-18-2006, 01:55 AM
wow... they keep getting better and better. well done

hybrid101
01-18-2006, 07:10 AM
wow man, that's pretty good!

nathan99
01-18-2006, 07:25 AM
(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]]);

nice work!.. but is this allowed?

or is that characterised as "daisy-chaining"?

treatkor
01-18-2006, 08:52 AM
:thumb: i love that it resets to a new level when a level is cleared. it plays well and is complete.
what would this code look like if written out "normally"? (without the 25 line restriction)

Sammo
01-18-2006, 01:14 PM
I think nathan99's right, that isn't one line.

sed|thh
01-18-2006, 01:22 PM
can't belive it's only 25 lines! great job :)

dbarbarian
01-18-2006, 02:08 PM
electricGrandpa: Yea, it sure is a pain. And all those parentheses are making my eyes hurt :stare:

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 =)

sed|thh: Yea, I can't believe it either, lol. :)

ElectricGrandpa
01-18-2006, 02:42 PM
Yeah the line he used IS allowed, it's almost the same thing that I used in my "Is this illegal?" example, basically just a way of passing all the arguments to the function in a chain function.

-Matt

bombsledder
01-18-2006, 03:24 PM
hey lol i like it =( you did post first so you can use it plus when i started making mine i made a couple of extra* features and it ended up being 400+ lines of code but my 25 line one isnt quite as good as yours anyways so

gl =)

dbarbarian
01-20-2006, 08:22 PM
bombsledder: I too planned to have powerups and such, but ran out of lines. Thanks for letting me use this :)