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

パーティクル崩し Rev. G ホワイトレーベル

難易度を調整した
LMBでフィールド範囲をコントロールできる
自機当たり判定も小さくなった
スコアカウンタも追加した
とにかくがんばれw
/**
 * Copyright 5parrowhawk ( http://wonderfl.net/user/5parrowhawk )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/3Dlb
 */

// forked from 5parrowhawk's パーティクル崩し Rev. G ブラックレーベル
// forked from 5parrowhawk's forked from: パーティクル崩し
// forked from coppieee's パーティクル崩し
//コードはめっちゃ汚いよ!
//ブロックの数465*100
//がんばってクリアしてください
//Plans for Green Label:
//- Life counter. When hit, field flashes and disappears. 
//- While field is gone, player is invulnerable.
//- Field reappears after 3 seconds.
//- Player has 10 lives.
//- Extra lives at score 1,000, 10,000, 100,000, 1000,000 etc
//- Reduce number of blocks to destroy by half (465*50)
//- Allow player to move further up
//- When using defense mode, field exerts constant force, not inverse square?
//- Limit the maximum force exerted by the field
//- Cosmetic enhancement: make the rainbow green
package 
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.geom.ColorTransform;
    import flash.geom.Matrix;
    import flash.geom.Rectangle;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.ui.Mouse;
    import net.hires.debug.Stats;
    
    [SWF(width = "465", height = "465", frameRate = "30")]
    public class BlockBreaker extends Sprite 
    {
        private static const HEIGHT:Number = 465;
        private static const WIDTH:Number = 465;
        private var _canvas:BitmapData;
        private var _blocks:Blocks;
        private var _fallBlocks:Vector.<Particle>;
        private var _balls:Vector.<Particle>;
        private var _bar:Bitmap;
        private var _ring:Bitmap;
        private var _ring2:Bitmap;
        private var _bottom: Bitmap;
        private var _bLowerField: Boolean;
        private var _score: uint = 0;
        private var _multText: TextField = new TextField();
        private var _scoreText:TextField = new TextField();
        
        public function BlockBreaker()
        {
            _canvas = new BitmapData(WIDTH, HEIGHT,false,0x000000);
            addChild(new Bitmap(_canvas));
            
            _blocks = new Blocks(WIDTH, 100);
            
            _fallBlocks = new Vector.<Particle>();
         
         
            stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown); 
            stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp); 
            
            var b:BitmapData = new BitmapData(3, 3, false, 0x00FF00);
            var c:BitmapData = new BitmapData(100, 100, true, 0x30FF0000);
            var d:BitmapData = new BitmapData(50, 50, true, 0x30FFFF00);
            var bottom: BitmapData = new BitmapData(200,10,false,0x555555);
            addChild(_bar = new Bitmap(b));
            addChild(_ring = new Bitmap(c));
            addChild(_ring2 = new Bitmap(d));
            addChild(_bottom = new Bitmap(bottom));
            _bottom.y = WIDTH - 10;
            _bottom.x = WIDTH/2 - bottom.width/2;
            _bar.y = WIDTH -c.width;
            _ring.y = _bar.y - 22;
            _ring2.y = _bar.y - 22;
            _ring2.visible = false;
            var _ball:Particle = new Particle(0xFFFFFF, WIDTH / 2, HEIGHT / 2);
            _ball.vx = Math.random() *4 - 2;
            _ball.vy = -Math.random() *2 -1;
            
            _balls = new Vector.<Particle>();
            _balls.push(_ball);
            
            
            _scoreText.text = "Score: 0";
            _scoreText.textColor = 0xFFFFFF;
            _scoreText.autoSize = TextFieldAutoSize.NONE; 
//            _scoreText.y = HEIGHT - 20;
            
            
            _multText.text = "Multiplier: 1";
            _multText.textColor = 0xFFFFFF;
            _multText.autoSize = TextFieldAutoSize.NONE; 
            _multText.x = WIDTH - 100;
//            _multText.y = HEIGHT - 20;
            
            addChild(_scoreText);
            addChild(_multText);
            
            //var stats:Stats = new Stats();
            //stats.y = 200;
            //addChild(stats);
            
            addEventListener(Event.ENTER_FRAME, update);
        }
        private function update(e:Event):void
        {
            _canvas.lock();
            _canvas.colorTransform(_canvas.rect, new ColorTransform (0.9, 0.5, 0.9));
//            _canvas.draw(_scoreText,new Matrix(5,0,0,5,300, HEIGHT-20));
            
            for each(var block:Particle in _blocks.values)
            {
                if (block)
                {
                    _canvas.setPixel(block.x, block.y, block.color);
                }
            }
            var removeBalls:Vector.<Particle> = new Vector.<Particle>();
             for each(var ball:Particle in _balls)
             {
                var bvx:Number = ball.vx;
                var bvy:Number = ball.vy;
                var bspeed:Number = Math.sqrt(bvx * bvx + bvy * bvy);
                var bradius:Number = Math.atan2(bvy, bvx);
                for (var i:int = 0; i < bspeed;i++)
                {
                    ball.x += ball.vx/bspeed;
                    ball.y += ball.vy/bspeed;
                    var hitParticle:Particle = _blocks.getParticle(ball.x, ball.y);
                    if(hitParticle)
                    {
                        var spawncount:Number = bspeed-3;
                        if (spawncount < 1) spawncount = 1;
                        var lv: Number = 0;
                        for (;lv<spawncount;lv++)
                        {
                            var removedP:Particle = _blocks.spawnParticle(ball.x, ball.y);
                            _score += _balls.length;
                            removedP.vx = Math.cos(bradius+Math.PI*2/(30*Math.random())-15)*3/spawncount;
                            removedP.vy = 1/spawncount;
                            removedP.color = hitParticle.color;
                            _fallBlocks.push(removedP);
                        }
                        _blocks.delParticle(ball.x, ball.y);
                        ball.vy = -ball.vy;
                    }
                    
                    if ((ball.x < 0 && ball.vx < 0) || (ball.x > WIDTH && ball.vx > 0))
                    {
                        ball.vx = -ball.vx;
                    }
                    if (ball.y < 0 && ball.vy < 0)
                    {
                        ball.vy = -ball.vy;
                    }
                    if (_bottom.hitTestPoint(ball.x,ball.y) && ball.vy > 0)
                    {
                        ball.vy = -ball.vy;
                    }
                    else if (ball.y > HEIGHT && ball.vy > 0)
                    {
                        //ball.vy = -ball.vy; 
                        removeBalls.push(ball);
                    }
                    
                    
                    var tx: Number;
                    var ty: Number;
                    var distsq: Number;
                    var force: Number;
                        
                    if (_bar.hitTestPoint(ball.x, ball.y))
                    {
                        removeEventListener(Event.ENTER_FRAME, update);
                        var dieTF:TextField = new TextField();
                        dieTF.text = "YOU DIED";
                        dieTF.textColor = 0xFF0000;
                        dieTF.autoSize = TextFieldAutoSize.LEFT; 
                        _canvas.draw(dieTF,new Matrix(5,0,0,5,WIDTH/2-dieTF.width*5/2,HEIGHT/2-dieTF.height*5/2));
                    } 
                    else if ((_ring.visible)&&_ring.hitTestPoint(ball.x, ball.y))
                    {
                        tx = ball.x - (_ring.x + 50);
                        ty = ball.y - (_ring.y + 50);
                        distsq = tx*tx + ty*ty;
                        //var force: Number = 40.0/distsq;
                        distsq = Math.sqrt(distsq); //now it is the length of the hypotenuse
                        force = 2.0/distsq; //not really inverse square but probably easier
                        ball.vx = ball.vx - tx/distsq * force;
                        //if (Math.abs(ball.vx) > 8) ball.vx *= 0.95;
                        ball.vy = ball.vy - ty/distsq * force;
                        //if (Math.abs(ball.vy) > 8) ball.vy *= 0.95;
                    }
                    else if ((_ring2.visible)&&_ring2.hitTestPoint(ball.x, ball.y))
                    {
                        tx = ball.x - (_ring2.x + 25);
                        ty = ball.y - (_ring2.y + 25);
                        distsq = tx*tx + ty*ty;
                        //var force: Number = 40.0/distsq;
                        distsq = Math.sqrt(distsq); //now it is the length of the hypotenuse
                        force = 1.0/distsq; //not really inverse square but probably easier
                        ball.vx = ball.vx - tx/distsq * force;
                        //if (Math.abs(ball.vx) > 8) ball.vx *= 0.95;
                        ball.vy = ball.vy - ty/distsq * force;
                        //if (Math.abs(ball.vy) > 8) ball.vy *= 0.95;
                    }
                    
                    var ballvelsq: Number = ball.vx*ball.vx+ball.vy*ball.vy;
                    if (bspeed > 6)
                    {
                        ball.vx *= 0.95;
                        ball.vy *= 0.95;
                    }


                    _canvas.setPixel(ball.x, ball.y, ball.color);
                }
            }
            removeBalls.forEach(function(b:Particle, ...args):void {
                var index:int = _balls.indexOf(b);
                if (index != -1)
                {
                    _balls.splice(index, 1);
                }
            });
            
            var removeFallBs:Vector.<Particle> = new Vector.<Particle>();
            _fallBlocks.forEach(function(fallP:Particle, ...args):void {
                fallP.vy += 0.05;
                fallP.x += fallP.vx;
                fallP.y += fallP.vy;
                _canvas.setPixel(fallP.x, fallP.y, fallP.color);
                var newball: Particle;
                if (_bar.hitTestPoint(fallP.x,fallP.y))
                {
                        removeEventListener(Event.ENTER_FRAME, update);
                        var dieTF:TextField = new TextField();
                        dieTF.text = "YOU DIED";
                        dieTF.textColor = 0xFF0000;
                        dieTF.autoSize = TextFieldAutoSize.LEFT;
                        _canvas.draw(dieTF,new Matrix(5,0,0,5,WIDTH/2-dieTF.width*5/2,HEIGHT/2-dieTF.height*5/2));
                }
                else if ((_ring.visible)&&_ring.hitTestPoint(fallP.x,fallP.y))
                {
                    newball = new Particle(fallP.color, fallP.x,fallP.y);
                    newball.vx = fallP.vx;
                    newball.vy = fallP.vy;
                    _balls.push(newball);
                    removeFallBs.push(fallP);
                }
                else if ((_ring2.visible)&&_ring2.hitTestPoint(fallP.x,fallP.y))
                {
                    newball = new Particle(fallP.color, fallP.x,fallP.y);
                    newball.vx = fallP.vx;
                    newball.vy = fallP.vy;
                    _balls.push(newball);
                    removeFallBs.push(fallP);
                }

                else if (fallP.y > HEIGHT)
                {
                    removeFallBs.push(fallP);
                }
            });
            
            removeFallBs.forEach(function(b:Particle,...args):void{
                var index:int = _fallBlocks.indexOf(b);
                if (index != -1)
                {
                    _fallBlocks.splice(index, 1);
                }
            });
            _bar.x = stage.mouseX;
            _bar.y = stage.mouseY;
            
            if (_bar.y < WIDTH/2) 
            {
                _bar.y = WIDTH/2;
            }
            else if (_bar.y > (WIDTH-20))
            {
                _bar.y = WIDTH-20;
            }


               
            if (_bar.x < 0)
            {
                _bar.x = 0;
            }
            else if (_bar.x > WIDTH - 4)
            {
                _bar.x = WIDTH - 4;
            }

               
            _ring.y = _bar.y - 48;
            _ring.x = _bar.x - 48;
               
            _ring2.y = _bar.y - 24;
            _ring2.x = _bar.x - 24;
                       
            if (_bLowerField)
            { 
                _ring.visible = false;
                _ring2.visible = true;
            }
            else
            {
                _ring.visible = true;
                _ring2.visible = false;
            }


            _canvas.unlock();
            
            if (_blocks.count == 0)
            {
                removeEventListener(Event.ENTER_FRAME, update);
                var clearTF:TextField = new TextField();
                clearTF.text = "CLEAR!\nおめでと";
                clearTF.textColor = 0xFFFFFF;
                clearTF.autoSize = TextFieldAutoSize.LEFT;
                _canvas.draw(clearTF,new Matrix(5,0,0,5,WIDTH/2-clearTF.width*5/2,HEIGHT/2-clearTF.height*5/2));
            }
            else if (_fallBlocks.length+_balls.length==0)
            {
                        removeEventListener(Event.ENTER_FRAME, update);
                        var dieTF2:TextField = new TextField();
                        dieTF2.text = "YOU DIED";
                        dieTF2.textColor = 0xFF0000;
                        dieTF2.autoSize = TextFieldAutoSize.LEFT; 
                        _canvas.draw(dieTF2,new Matrix(5,0,0,5,WIDTH/2-dieTF2.width*5/2,HEIGHT/2-dieTF2.height*5/2));
                
            }

            _scoreText.text = "Score: "+_score;
            _multText.text = "Multiplier: "+_balls.length;
            //_canvas.draw(_scoreText,new Matrix(2,0,0,2,_scoreText.x,_scoreText.y));
            //_canvas.draw(_multText,new Matrix(2,0,0,2,_multText.x,_multText.y));

            
        }
        
        private function onMouseDown(event:MouseEvent):void {
            _bLowerField = true;
        }
        private function onMouseUp(event:MouseEvent):void {
            _bLowerField = false;
        }
    }
}
import frocessing.color.ColorHSV;
class Blocks
{
    public function get count():int { return _count;}
    private var _count:int;
    public function get width():Number { return _width; }
    private var _width:Number;
    public function get height():Number { return _height; }
    private var _height:Number;
    public var values:Vector.<Particle>;
    function Blocks(width:Number,height:Number)
    {
        _width = width;
        _height = height;
        _count = width * height;
        values = new Vector.<Particle>(width * height, false);
        var c:ColorHSV = new ColorHSV();
        for (var i:int = 0; i < _width; i++)
        {
            c.h = 360 * i / _width;
            for (var j:int = 0 ; j < _height; j++ )
            {
                var p:Particle = new Particle(c.value, i, j);
                values[i + j * _width] = p;
            }
        }
    }
    public function getParticle(x:int, y:int):Particle
    {
        var index:int = x + y * _width;
        if (index >= values.length || index < 0)
        {
            return null;
        }
        return values[x + y * _width];
    }
    public function spawnParticle(x:int, y:int):Particle
    {
        var p:Particle = values[x + y * _width];
        return new Particle(p.color, p.x, p.y);
    }
    public function delParticle(x:int, y:int):void
    {
        var p:Particle = values[x + y * _width];
        if (p)
        {
            _count--;
            values[x + y * _width] = undefined;
        }
    }
    public function removeParticle(x:int, y:int):Particle
    {
        var p:Particle = values[x + y * _width];
        if (p)
        {
            _count--;
            values[x + y * _width] = undefined;
        }
        return p;
    }
}
class Particle
{
    public var x:Number;
    public var y:Number;
    public var vx:Number = 0;
    public var vy:Number = 0;
    public var color:uint;
    public function Particle(c: uint, x:Number=0,y:Number=0)
    {
        this.x = x;
        this.y = y;
        this.color = c;
    }
}