Actionscript Tennis

holy cow you guys are still goin !!! awesome !!

i can’t wait to see the final result !! better be good :a:

but i know it wil be !!!

peace out
E1kO

wow, that is the longest piece of code i have ever seen in my entire life :stuck_out_tongue:

A nice anti-asteroids field if you press SHIFT :slight_smile:

/****************
* Volleys
* #1: Ahmed, 7/15
* #2: Senocular, 7/15
* #3: Thoriphes, 7/16
* #4: Ilyas, 7/17
* #5: Ahmed, 7/31
* #6: Ilyas, 8/03
* #7: Master64, 8/04
* #8: Ahmed, 8/05
* #9: Ilyas, 8/13
****************/

StageDim = {width:Stage.width, height:Stage.height}; // Stage Dimensions (renamed by sen 7/15)
MovieClip.prototype.move = function () {
        if ( this._x > 0 ) this._x -= this.speed ;
        else {
                this._x = StageDim.width + 20 ;
                this._y = random (StageDim.height);
        }
}
container = []; // contains circles created by createCircle
MovieClip.prototype.makeCircle = function ( size, col, alpha ) {
        this.moveTo ( 0, 0 ) ;
        this.lineStyle ( size, col, alpha ) ;
        this.lineTo ( .45, .15 ) ;
}
this.createEmptyMovieClip("BackgroundLayer", 99)
for(i=0; i<15; i++) {
        clip = BackgroundLayer.createEmptyMovieClip("mc"+i, i);// create an empty clip to contain the circle
        clip.makeCircle (size=10+Math.random()*30, 0xff0000,100); // define random linestyle
        (new Color (clip)).setTransform ({ga:70+random(30),ba:0,ra:70+random(30)}) ;
        clip._x = Math.random()*StageDim.width ; // position circle based on Stage Dimensions
        clip._y = Math.random()*StageDim.height;
        container.push(clip); // add circle clip to container
        clip.speed = size / 5 ;
		clip.onEnterFrame = move ;
}

//***********

this.BackgroundLayer.createEmptyMovieClip ( "DeepSpace9", -100 ).beginFill ( 0, 100 ) ;
edges = [{x:0, y:0}, {x:StageDim.width, y:0}, {x:StageDim.width, y:StageDim.height}, {x:0, y:StageDim.height}] ;
for ( var p=0; p < edges.length; p++ )
this.BackgroundLayer.DeepSpace9[p == 0 ? "moveTo" : "lineTo"](edges[p].x, edges[p].y);

//***********

// create a clip at depth 100 as an "object layer" with more managable
// depths using ObjectLayer.depth++ to prevent overlapping
// in ObjectLayer create a spaceShip clip and define an outline for it
this.createEmptyMovieClip("ObjectLayer", 100).createEmptyMovieClip("spaceShip", ObjectLayer.depth++).outline = [[91,19],[31,-35],[-26,-20],[-76,-45],[-98,-43],[-60,-13],[-77,-4],[-76,9],[-58,15],[-31,15],[-53,47],[-20,43],[34,2],[75,20],[91,19]];
// drawOutlines: draws lines defined by points in an array in a movieclip
// allows optional lineStyle and fillStyle parameters
MovieClip.prototype.drawOutlines = function(points, lStyle, fStyle){
        if (lStyle != undefined) this.lineStyle.apply(this, lStyle); // apply linestyle if passed
        if (fStyle != undefined) this.beginFill.apply(this, fStyle); // apply fillstyle if passed
        for (var i=0; i<points.length; i++){ // cycle through all the points in the array
                if (i) this.lineTo(points*[0],points*[1]); // use a line if not the first point
                else this.moveTo(points*[0],points*[1]);} // otherwise, move to the point if the first
        if (fStyle != undefined) this.endFill(); // end the fill if passed
};
// defines 'ship' in this timeline and draws its outlines with specified line and fill
(ship = ObjectLayer.spaceShip).drawOutlines(ObjectLayer.spaceShip.outline, [2,0,100], [0xbfbfbf,100]);

//****************

afterBurner = ship.createEmptyMovieClip("Afterburner",99); // container clip
col = 0xff0000 ; // base color of the flame
for ( var i = 0; i < 20 ; i++ ) {
        // We make a bunch of small clips that get red little by little
        var clip = afterBurner.createEmptyMovieClip ( "b" + i, i ) ;
        clip.makeCircle ( size = 5 + 10*Math.cos ( a+= .15 ), col += 0x001000, 20 ) ;
        clip.makeCircle ( size + 10, 0xffff00, 10 ) ;
        clip._x = -90 -3 * i ;
        clip._y = 5 ;
}
afterBurner.onEnterFrame = function () {
        // The afterburner is visible only when a key is pressed
        this._visible = Key.isDown(Key.UP) + Key.isDown(Key.DOWN) + Key.isDown(Key.RIGHT) ;
}

//***************

ship.accel = 1.01;
ship.decel = 0.99;
ship.maxvel = 10;
ship.vx = ship.vy = 0;
MovieClip.prototype.obeyControls = function () {
        this._x += this.vx;
        this._y += this.vy;
        this.vx *= .96 ;
        this.vy *= .96 ;
};	
ship.onEnterFrame = obeyControls ;
Key.addListener(keyList = new Object());
keyList.onKeyDown = function () {
        ship.vx = Key.isDown(Key.RIGHT) ? ship.vx + (ship.vx <= ship.maxvel ? ship.accel : 0) : Key.isDown(Key.LEFT) ? ship.vx - (ship.vx >= -ship.maxvel ? ship.decel : 0) : ship.vx;
        ship.vy = Key.isDown(Key.DOWN) ? ship.vy + (ship.vy <= ship.maxvel ? ship.accel : 0) : Key.isDown(Key.UP) ? ship.vy - (ship.vy >= -ship.maxvel ? ship.decel : 0) : ship.vy;
}

//****************

rad = 150
MovieClip.prototype.repel = function() {
	for(i=0; i<container.length; i++) {
		var cl = container* ;
		var dx = this._x-cl._x ;
		var dy = this._y-cl._y ;
		var dist = Math.sqrt(dx*dx+dy*dy) ;
		if (dist <= rad) {
			var force = (rad-dist)/30
			cl._x = cl._x-10*force*dx/dist
			cl._y = cl._y-10*force*dy/dist
		}
	}
}

//****************

MovieClip.prototype.fire = function(){
        if(this.count > 100) this.count = 0 ;
        shot = this._parent.createEmptyMovieClip("shot"+this.count++,this.count+200);
        shot.makeCircle(5,0xff6600,100);
        shot._y = ship._y+19; shot._x = ship._x+91;
        shot.onEnterFrame = function(){
                /* begin ahmed's edit */
                // loop through all 'starships' and hitTest them
                for(var i=0; i<container.length; i++) {
                        if (this.hitTest(container*)) {
                                // if bullet hits a starship, delete startship, bullet, and reference in array
                                container*.removeMovieClip();
                                container* = null;
                                this.removeMovieClip();
                        }
                }
                /* end ahmed's edit */
                this._x += 12
        }
}
this.createEmptyMovieClip("shotTime",98).onEnterFrame = function () {
        this.interval++;
        if (Key.isDown(Key.SPACE) && this.interval > 7) {
			ship.fire(); 
			this.interval = 0;
		}
}

//***********

MovieClip.prototype.makeShield = function () {
	var mc = this.createEmptyMovieClip ("shield", 1000) ;
	mc.makeCircle ( 220, 0xffff00, 30 ) ;
}
// Would be cool if we could put all the key actions within the same handler... : )
myKeyListener = {} ;
myKeyListener.onKeyDown = function () {
	if (Key.isDown(Key.SHIFT)) {
		ship.makeShield () ;
		ship.onEnterFrame = function () {
			this.repel ();
			this.obeyControls ();
		}
	}
}
myKeyListener.onKeyUp = function () {
	if (!Key.isDown(Key.SHIFT)) {
		ship.shield.removeMovieClip() ;
		ship.onEnterFrame = obeyControls;
	}
}
Key.addListener(myKeyListener) ;

*Originally posted by Ilyas Masa *
A nice anti-asteroids field if you press SHIFT :slight_smile:
That’s very smart :thumb:

Thanks! That repel function is pretty cool :beam:

come on guys you almost finished !!

i am hanging out to see this thing !!

PEACE
E1kO

lol… what more can we do?

you can script faster !! lol thats what you can do :beam:

PEACE
E1kO

*Originally posted by ahmed *
**lol… what more can we do? **
Does it mean that it’s finished? :eye:

THat is one funky anti asteroid sheild

so… is this like the finish of this cause there hasn’t been any action for quite a while now !!

just wondering

peace
E1kO

It looks like it :frowning: