PDA

View Full Version : FlashType - Sinister Shadow



Sinister Shadow
January 17th, 2006, 05:32 AM
Remember R-Type? Well how about a really, REALLY cut down version in flash? How cool would that be?!

Well, ponder no more, I give you the answer!

21 lines of AS goodness (not including 'else') with room for improvement!

Changelog
------
Now even better with 21 lines of code (kookaburra) - 20/01/06
Can no longer shoot after dying (pointed out by hybrid101) - 20/01/06
Stole Ben's idea through telepathy - 17/01/06


chain(chain(chain(chain(chain(chain(chain(chain(ch ain(chain(chain(chain(chain(createEmptyMovieClip("ship", 0), "beginFill", [0x000000, 100]), "lineTo", [20, 10]), "lineTo", [0, 20]), "lineTo", [0, 0]).duplicateMovieClip("enemy", 1, {_x:830, _y:-100, enemynum:200, onEnterFrame:generateEnemy}), "clear", []), "beginFill", [0x000000, 100]), "lineTo", [20, 0]), "lineTo", [20, 20]), "lineTo", [0, 20]), "lineTo", [0, 0]).duplicateMovieClip("shot", 2, {_x:-30, _y:-100, shotnum:50, lastshot:0, delay:3}), "clear", []), "lineStyle", [2, 0x000000, 100]), "lineTo", [10, 0]).onEnterFrame = function() {
this.lastshot -= (this.lastshot == 0 ? 0 : 1);
};

function chain(target:MovieClip, method:String, params:Array):MovieClip
{
target[method](params[0], params[1], params[2], params[3], params[4]);
return target;
}

function onEnterFrame():Void
{
this["ship"]._y = ((this["ship"]._y += 10 * (Number(Key.isDown(Key.DOWN)) + (-1 * Number(Key.isDown(Key.UP))))) < 0 ? 0 : (this["ship"]._y > (600 - this["ship"]._height) ? (600 - this["ship"]._height) : this["ship"]._y));
this["ship"]._x = ((this["ship"]._x += 10 * (Number(Key.isDown(Key.RIGHT)) + (-1 * Number(Key.isDown(Key.LEFT))))) < 0 ? 0 : (this["ship"]._x > (800 - this["ship"]._width) ? (800 - this["ship"]._width) : this["ship"]._x));

if (this["ship"] && Key.isDown(Key.SPACE) && this["shot"].lastshot <= 0)
chain(this["shot"], "duplicateMovieClip", ["shot" + (this["shot"].shotnum == 100 ? this["shot"].shotnum = 10 : this["shot"].shotnum), this["shot"].shotnum++, {_x:this["ship"]._x + 20, _y:this["ship"]._y + 10, onEnterFrame:checkShot}])._parent["shot"].lastshot = this["shot"].delay;
}

function checkShot():Void
{
if((this._x += 10) > 800)
this.removeMovieClip();
}

function generateEnemy():Void
{
if (Math.round(Math.random() * 10) == 0)
this.duplicateMovieClip("enemy" + (this["enemynum"] == 300 ? this["enemynum"] = 200 : this["enemynum"]), this["enemynum"]++, {_x:820, _y:Math.random() * 580, onEnterFrame:this._parent.checkEnemy});
}

function checkEnemy():Void
{
if (this.hitTest(_parent["ship"]))
{
_parent["ship"].removeMovieClip();
}
else if((this._x -= 10) < -this._width)
{
this.removeMovieClip();
}
else
{
for (var i:Number = 10; i <= _parent["shot"].shotnum; i++)
{
if (this.hitTest(_parent["shot" + i]))
{
_parent["shot" + i].removeMovieClip();
this.removeMovieClip();
break;
}
}
}
}

Have fun! :hitman:

hybrid101
January 17th, 2006, 07:29 AM
i'm still able to fire after i die:krazy:
nice work, looks cool, runs smoothly!

Ben H
January 17th, 2006, 02:31 PM
:lol:

I just had that idea in the car!

-Ben

kookaburra
January 18th, 2006, 12:43 AM
Too good for 25 lines.

Sinister Shadow
January 20th, 2006, 05:26 PM
Update #1

I've just updated a few issues and finished the code to meet the 25 line rule... it's only 21 lines! :krazy:

Check the first post for the swf and code. Expect more updates to this over the week!

Joppe
January 20th, 2006, 05:36 PM
Is it suposed to be an clock?

Sinister Shadow
January 20th, 2006, 05:40 PM
Whoops! :lol: Thanks for pointing that out Joppe. I uploaded a seperate project I'm working on by accident! Updated it with the correct file now.