NiñoScript
January 17th, 2006, 04:20 PM
Code so far:
MovieClip.prototype.drawArray = function(array:Array, lineStyle:Object):MovieClip {
var mc:MovieClip = this.createEmptyMovieClip("mc"+this.getNextHighestDepth()+"_mc", this.getNextHighestDepth());
//1
mc.lineStyle(lineStyle.thickness);
//2
for (var i = 0; i<array.length; i++) {
//3
array[i].line ? mc.lineTo(array[i].x, array[i].y) : mc.moveTo(array[i].x, array[i].y);
//4
}
return mc;
//5
};
_global.stuff = {shot_time:20, drawings:{ship_drawing:[{line:false, x:-20, y:-20}, {line:true, x:20, y:0}, {line:true, x:-20, y:20}, {line:true, x:-10, y:0}, {line:true, x:-20, y:-20}, {line:true, x:-20, y:20}, {line:false, x:-20, y:0}, {line:true, x:-10, y:0}, {line:false, x:-10, y:-10}, {line:true, x:10, y:0}, {line:true, x:-10, y:10}], asteroid:[{line:false, x:-5, y:-100}, {line:true, x:25, y:-90}, {line:true, x:35, y:-80}, {line:true, x:45, y:-80}, {line:true, x:55, y:-60}, {line:true, x:45, y:-50}, {line:true, x:45, y:-30}, {line:true, x:35, y:-10}, {line:true, x:15, y:10}, {line:true, x:-5, y:10}, {line:true, x:-15, y:20}, {line:true, x:-35, y:10}, {line:true, x:-35, y:0}, {line:true, x:-55, y:-20}, {line:true, x:-55, y:-40}, {line:true, x:-45, y:-60}, {line:true, x:-45, y:-80}, {line:true, x:-25, y:-100}, {line:true, x:-5, y:-100}, {line:false, x:-25, y:-100}, {line:true, x:-25, y:-90}, {line:true, x:-35, y:-80}, {line:true, x:-45, y:-80}, {line:false, x:-35, y:10}, {line:true, x:-25, y:10}, {line:true, x:-15, y:20}, {line:false, x:45, y:-80}, {line:true, x:45, y:-70}, {line:true, x:55, y:-60}, {line:false, x:-5, y:-60}, {line:true, x:5, y:-70}, {line:true, x:25, y:-60}, {line:true, x:25, y:-40}, {line:false, x:-25, y:-30}, {line:true, x:-25, y:-40}, {line:true, x:-5, y:-50}, {line:true, x:5, y:-40}, {line:false, x:-5, y:-50}, {line:true, x:-15, y:-40}, {line:true, x:-25, y:-40}, {line:false, x:5, y:-70}, {line:true, x:5, y:-60}, {line:true, x:25, y:-60}, {line:false, x:-5, y:-10}, {line:true, x:5, y:-10}, {line:true, x:25, y:-20}]}, friction:.97, degreesToRadians:Math.PI/180, bulletSpeed:5};
//6 (1627 chars)
Object.prototype.change = function(stuff:Array, addToAsteroidArray) {
//stuff = [[property:String, changer:Value, ?change:add;:Boolean], [property, changer, ?change:add;], etc...]
for (var i = 0; i<stuff.length; i++, i == stuff.length and addToAsteroidArray ? asteroids.push(this) : null) {
//7
this[stuff[i][0]] = stuff[i][2] ? stuff[i][1] : this[stuff[i][0]]+stuff[i][1];
//8
}
};
_root.drawArray(_global.stuff.drawings.ship_drawin g, {thickness:0}).change([["_x", Stage.width/2, true], ["_y", Stage.height/2, true], ["shot_counter", _global.stuff.shot_time, true], ["speed", {x:0, y:0, acc:.8, rot:0, max:8}, true], ["onEnterFrame", function () {
//9
Key.isDown(Key.UP) ? this.speed.change([["x", Math.min(this.speed.max, this.speed.x+Math.cos(this._rotation*_global.stuff .degreesToRadians)*this.speed.acc), true], ["y", Math.min(this.speed.max, this.speed.y+Math.sin(this._rotation*_global.stuff .degreesToRadians)*this.speed.acc), true]]) : Key.isDown(Key.DOWN) ? this.speed.change([["x", Math.max(-this.speed.max, this.speed.x-Math.cos(this._rotation*_global.stuff.degreesToRad ians)*this.speed.acc), true], ["y", Math.max(-this.speed.max, this.speed.y-Math.sin(this._rotation*_global.stuff.degreesToRad ians)*this.speed.acc), true]]) : null;
//10
Key.isDown(Key.LEFT) ? this.speed.rot -= this.speed.acc*2 : Key.isDown(Key.RIGHT) ? this.speed.rot += this.speed.acc*2 : null;
//11
this.change([["shot_counter", Math.max(0, this.shot_counter-1), true], ["_x", this.speed.x *= _global.stuff.friction, false], ["_y", this.speed.y *= _global.stuff.friction, false], ["_rotation", this.speed.rot *= (_global.stuff.friction*11/12), false]]);
//12
this._x<-this._width/2 ? this._x=550+this._width/2 : this._x>550+this._width/2 ? this._x=-this._width/2 : this._y<-this._height/2 ? this._y=400+this._height/2 : this._y>400+this._height/2 ? this._y=-this._height/2 : null;
//13
(Key.isDown(Key.SPACE) and this.shot_counter == 0) ? (this.shot_counter=_global.stuff.shot_time, _root.drawArray([{line:false, x:-5, y:0}, {line:true, x:+5, y:0}], {thickness:0}).change([["_x", this._x, true], ["_y", this._y, true], ["_rotation", this._rotation, true], ["speed", {x:Math.cos(this._rotation*_global.stuff.degreesTo Radians)*_global.stuff.bulletSpeed, y:Math.sin(this._rotation*_global.stuff.degreesToR adians)*_global.stuff.bulletSpeed}, true], ["onEnterFrame", function () {
//14
this._x<-this._width/2 or this._x>550+this._width/2 or this._y<-this._height/2 or this._y>400+this._height/2 ? this.removeMovieClip() : this.change([["_x", this.speed.x, false], ["_y", this.speed.y, false]]);
//15
for (i=0; i<asteroids.length; i++) {
//16
asteroids[i].hitTest(this) ? (this.onEnterFrame=null, asteroids[i].killAsteroid(this, i)) : null;
//17
}
}, true]])) : null;
}, true]]);
var asteroids = [];
//18
function createAsteroid(x, y, lvl) {
_root.drawArray(_global.stuff.drawings.asteroid, {thickness:0}).change([["lvl", lvl == undefined ? lvl=5 : lvl, true], ["_xscale", 20*lvl, true], ["_yscale", 20*lvl, true], ["_x", x, true], ["_y", y, true], ["speed", {x:Math.cos((this.rotation=random(360))*_global.st uff.degreesToRadians)*2, y:Math.sin(this.rotation*_global.stuff.degreesToRa dians)*2, rot:(random(5)+2)/2}, true], ["onEnterFrame", function () {
//19
this.change([["_x", this.speed.x, false], ["_y", this.speed.y, false], ["_rotation", this.speed.rot, false]]);
//20
this._x<-this._width/2 ? this._x=550+this._width/2 : this._x>550+this._width/2 ? this._x=-this._width/2 : this._y<-this._height/2 ? this._y=400+this._height/2 : this._y>400+this._height/2 ? this._y=-this._height/2 : null;
//21
}, true]], true);
}
MovieClip.prototype.killAsteroid = function(bullet:MovieClip, asteroid_index:Number) {
bullet.removeMovieClip();
//22
!this.lvl ? this.removeMovieClip() : this.change([["_xscale", 20*(--this.lvl), true], ["_yscale", 20*(this.lvl-1), true]]);
//23
//createAsteroid(this._x-50+random(100), this._y-50+random(100), this.lvl)
//24
};
createAsteroid(500, 300, 8);
//25
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.