In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

forked from: forked from: forked from: forked from: LaserShield

Get Adobe Flash player
by Libr8d 14 Jun 2009
// forked from Libr8d's forked from: forked from: forked from: LaserShield
// forked from h_sakurai's forked from: forked from: LaserShield
package {
    import flash.display.*
    public class Test extends Sprite {
        public function Test() {
            main = this
            initialize()
        }
    }
}
import flash.display.*
import flash.events.*
import flash.geom.*
import flash.text.*

var main:Sprite
const W:int = 465, H:int = 465
var isMousePressed:Boolean = false
var screen:BitmapData = new BitmapData(W, H, false, 0)
var dbg:TextField = new TextField();
function initialize():void {
    main.addChild(new Bitmap(screen))
    main.stage.addEventListener(MouseEvent.MOUSE_DOWN,
        function(e:Event):void { isMousePressed = true; } );
    main.stage.addEventListener(MouseEvent.MOUSE_UP  ,
        function(e:Event):void { isMousePressed = false; } );
  
    main.addEventListener("enterFrame", update)
    main.addChild(dbg)
    dbg.text += "ok"
}
var ticks:int = 0
function update(e:Event):void {
    dbg.text = ""+isMousePressed
    screen.fillRect(screen.rect, 0xeeeeee)
    player.update()
    ticks++
    if(ticks % 100 == 0)addCircle(1)

    var nextCircles:Vector.<Circle1> = new Vector.<Circle1>
    for each(var c:Circle1 in circles) {
        c.update()
        if(c.move!= null)nextCircles.push(c)
    }
    circles = nextCircles

    var nextBullets:Vector.<Bullet> = new Vector.<Bullet>
    for each(var b:Bullet in bullets) {
        b.update()
        if(b.move!= null)nextBullets.push(b)
    }
    bullets = nextBullets

    var nextShots:Vector.<Shot> = new Vector.<Shot>
    for each(var s:Shot in shots) {
        s.update()
        if(s.move!= null)nextShots.push(s)
    }
    shots = nextShots

    var nextParticles:Vector.<Particle> = new Vector.<Particle>
    for each(var p:Particle in particles) {
        p.update()
        if(p.move!= null)nextParticles.push(p)
    }
    particles = nextParticles

}

var rect:Rectangle = new Rectangle
var player:Player = new Player
class Player extends Vector3D {
    public function update():void {
        x = main.stage.mouseX
        y = main.stage.mouseY
        if (isMousePressed) {
            addShot(x,y, Math.PI)
//            addBullet(x,y,0)
        }
        rect.width = rect.height = 7
        var a:Number = ticks * 0.1
        var r:Number = 10
        for(var i:int = 0; i < 4; i++) {
            rect.x = Math.sin(a)*r + x - 2
            rect.y = Math.cos(a)*r + y - 2
            screen.fillRect(rect, 0xbbbb00)
            rect.x -= 1
            rect.y -= 1
            screen.fillRect(rect, 0xffff00)
            a += Math.PI * 2 / 4
        }
    }
}
function addCircle(no:int):void {
    var c:Circle1 = new Circle1();
    switch(no){
    case 1:
        c.x = Math.random() * W
        c.y = -70-20
        c.radius = 70
        c.move = c.move1
        c.childrenRadius = 50
        c.angle = 0
        circles.push(c)
        for(var i:int = 0; i < 5; i++) {
            var c2:Circle1 = new Circle1()
            c2.parent = c
            c2.radius = 20
            c2.move = c2.childMove
            c2.angle = i-1
            c2.no = i
            c.children.push(c2)
        }
    }
}

var circles:Vector.<Circle1>= new Vector.<Circle1>
var p1:Point = new Point
var p2:Point = new Point
class Circle1 extends Vector3D {
    public var angle:Number = 0
    public var parent:Circle1
    public var children:Vector.<Circle1> = new Vector.<Circle1>
    public var radius:int = 0
    public var childrenRadius:int = 0
    public var move:Function
    public var no:int=0
    public var ticks:int = 0
    public var hit:int=10
    public function update():void {
        if(move != null) {
            move()
            var nextChildren:Vector.<Circle1> = new Vector.<Circle1>
            for each (var c:Circle1 in children) {
                c.update()
                if(c.move != null){
                    c.no=nextChildren.length
                    nextChildren.push(c)
                }
            }
            children = nextChildren
            rect.width = rect.height = 7
            var a:Number = angle
            for(var i:int = 0; i < 16; i++) {
                rect.x = Math.sin(a)*radius + x - 3
                rect.y = Math.cos(a)*radius + y - 3
                screen.fillRect(rect, 0xbbbb00)
                a += Math.PI * 2 / 16
            }
        }
    }
    public function move1():void {
        y += 2
        if( y - radius + 10 > H) move = null
        angle += 0.01
    }
    public function brotherAngle(add:int):Number {
        var len:int = parent.children.length
        if (len <= 1) return 0;
        return parent.children[(no+len+add)%len].angle
    }
    public function childMove():void {
        x = parent.x + Math.sin(angle)*parent.childrenRadius
        y = parent.y + Math.cos(angle)*parent.childrenRadius
        var r:Number = Math.atan2(y - parent.y,  x - parent.x)
        var r2:Number = Math.atan2(player.y - parent.y, player.x - parent.x)
        var r3:Number = normalizeRadius(r-r2)
        var movef:Boolean = (parent.children.length <= 1);
        var rl:Number = normalizeRadius(brotherAngle( 1)-angle)
        var rr:Number = normalizeRadius(brotherAngle(-1)-angle)
             if(r3 >  0.05 && (movef || rl < 0 || rl >  0.5)) angle += 0.05
        else if(r3 < -0.05 && (movef || rr > 0 || rr < -0.5)) angle -= 0.05
        if(ticks > 30) {
            addBullet(x, y, -r+Math.PI/2)
            ticks = 0
        }
        ticks ++
        for (var i:int = 0; i < shots.length; i++) {
            
            if(Math.abs(x-shots[i].x)< 30 && Math.abs(y-shots[i].y) < 30) {
                shots.splice(i, 1); i--
                hit--
                radius--
                if(hit <= 0) {
                    this.move = null
                    addParticle(x,y,10)
                }
                break
            }
        }
/*
        for (i = 0; i < spl; i++)
            if (!sparks[i].update())  {
                sparks.splice(i, 1);  i--; spl--; }
//#     for (i = 0; i < shl; i++) if (!shots[i].update())   {
// shots.splice(i, 1);   i--; shl--; }
//#     for (i = 0; i < bnl; i++) if (!bonuses[i].update()) { bonuses.splice(i, 1); i--; bnl--; }
*/
    }
}

function addBullet(x:int, y:int, r:Number):void {
    bullets.push(new Bullet(x,y,r))
}
var bullets:Vector.<Bullet> = new Vector.<Bullet>
class Bullet extends Vector3D {
    public var move:Function = move1
    public var angle:Number
    public var speed:Number
    public function Bullet(x:int, y:int, a:Number, speed:Number=15){
        this.x = x
        this.y = y
        this.angle = a
        this.speed = speed
    }
    public function update():void {
        x += Math.sin(angle)*speed
        y += Math.cos(angle)*speed
        if(x > W) move = null
        if(y > H) move = null
        if(x < 0) move = null
        if(y < 0) move = null
        rect.width = rect.height = 7
        rect.x = x - 3
        rect.y = y - 3
        screen.fillRect(rect, 0xbbbb00)

    }
    public function move1():void {

    }
}

function addShot(x:int, y:int, r:Number):void {
    shots.push(new Shot(x,y,r))
}
var shots:Vector.<Shot> = new Vector.<Shot>
class Shot extends Vector3D {
    public var move:Function = move1
    public var angle:Number
    public var speed:Number
    public function Shot(x:int, y:int, a:Number, speed:Number=25){
        this.x = x
        this.y = y
        this.angle = a
        this.speed = speed
    }
    public function update():void {
        x += Math.tan(angle)*speed
        y += Math.cos(angle)*speed
        if(x > W) move = null
        if(y > H) move = null
        if(x < 0) move = null
        if(y < 0) move = null
        rect.width = 3; rect.height = 23
        rect.x = x - 3 - 10
        rect.y = y - 3
        screen.fillRect(rect, 0x88ff88)
        rect.x += 20
        screen.fillRect(rect, 0x88ff88)
    }
    public function move1():void {
    }
}

function addParticle(x:int, y:int, size:Number):void {
    for(var i:int = 0; i < size; i++)
        particles.push(new Particle(x,y,Math.random()*Math.PI*2,Math.random()*15+3))
}
var particles:Vector.<Particle> = new Vector.<Particle>
class Particle extends Vector3D {
    public var move:Function = move1
    public var angle:Number
    public var speed:Number
    public var ticks:int = 0
    public function Particle(x:int, y:int, a:Number, speed:Number=25){
        this.x = x
        this.y = y
        this.angle = a
        this.speed = speed
    }
    public function update():void {
        ticks++
        x += Math.sin(angle)*speed
        y += Math.cos(angle)*speed
        if(x > W) move = null
        if(y > H) move = null
        if(x < 0) move = null
        if(y < 0) move = null
        rect.width = rect.height = 9
        rect.x = x - 5
        rect.y = y - 5
        screen.fillRect(rect, 0xff6644-0x020201*(ticks))
        if(ticks > 32)move = null
    }
    public function move1():void {
    }
}

function normalizeRadius(a:Number):Number {
    if(a >  Math.PI) return a - Math.PI*2
    if(a < -Math.PI) return a + Math.PI*2
    return a
}