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: circle pong

test
+ http://wonderfl.net/c/cpzw
// forked from h_sakurai's forked from: circle pong
// forked from shinh's circle pong

//test
//+ http://wonderfl.net/c/cpzw

package {
    import flash.display.*
    import flash.geom.*
    import flash.text.*
    import flash.events.*
    import flash.filters.BlurFilter;   
    
    import org.si.sion.*;
    import org.si.sion.utils.SiONPresetVoice;
    
    public class CirclePong extends Sprite {
        
        private var screen:BitmapData
        private const W:int = 465, H:int = 465
        private var ba:Number = 0, bv:Number = 0
        private var cnt:int, noColCnt:int
        private var running:Boolean
        private var ball:Shape = new Shape()
        private var wall:Shape = new Shape()
        private var score:TextField = new TextField()
        private var text:TextField = new TextField()
        private var dbg:TextField = new TextField()
        
        private var _ct:ColorTransform;
        private var radius:int = 200;
        private var mat:Matrix = new Matrix();
        
        private var ballCanvas:Sprite = new Sprite();
        
        private var driver:SiONDriver = new SiONDriver();
        private var presetVoice:SiONPresetVoice = new SiONPresetVoice()
        private var mainMelody:SiONData;
        private var voice:SiONVoice;

        private function makeTextField(t:TextField, x:int, y:int, s:int):TextField {
            t.x = x
            t.y = y
            t.width = W
            t.height = H
            var fm:TextFormat = new TextFormat
            fm.color = 0xffffff
            fm.font = '_sans'; //'_typewriter';
            fm.size = s
            fm.bold = true
            t.defaultTextFormat = fm
            return t
        }
        public function CirclePong() {
            
            addChild(new Bitmap(screen = new BitmapData(W, H, false, 0)))
            ball.graphics.lineStyle(2, 0xffffff);
            //ball.graphics.beginFill(0xffffff)
            ball.graphics.drawCircle(0, 0, 7);
            ballCanvas.addChild(ball)
            wall.graphics.lineStyle(2, 0xffffff);
            //wall.graphics.beginFill(0xffffff)
            //wall.graphics.drawRect(-25, -2, 50, 5)
            //wall.graphics.drawRect(-50, -2, 100, 5);
            wall.graphics.drawRoundRect(-50, -2, 100, 5,2,2)
            addChild(wall)
            score.text = '0'
            addChild(makeTextField(score, 10, 10, 20))
            addChild(makeTextField(text, 100, 150, 30))
            addChild(makeTextField(dbg, 0, 20, 10))
            ball.x = -50
            running = true
            addEventListener(Event.ENTER_FRAME, update)
            addEventListener(MouseEvent.CLICK, init)
            
            _ct = new ColorTransform(0.9, 0.95, 0.98,1,0,0,0,-1)
            
            addChild(ballCanvas);
            
          
            mainMelody = driver.compile("t100 l8 [c]1");
            voice = presetVoice["valsound.bell16"];
           
            

       
        }
        public function init(event:MouseEvent): void {
            if (running) return
            running = true
            bv = 4;
            ba = Math.random() * 360
            ball.x = W / 2
            ball.y = H / 2
            score.text = '' + (cnt = 0)
            text.text = ''
            
        }
        public function update(event:Event): void {
            var a:Number = Math.atan2(stage.mouseX - W / 2,
                                      stage.mouseY - H / 2)
            var bx:Number = ball.x - W / 2
            var by:Number = ball.y - H / 2
            var da:Number = Math.abs(Math.atan2(bx, by) - a)
            if ((noColCnt -= 1) < 0 &&
                (da < 0.2 || da > Math.PI * 2- 0.2) &&
                Math.abs(Math.sqrt(bx*bx + by*by) - radius) < ball.width/2) {
                ba = Math.PI - ba + a * 2 + Math.random() * 0.2 - 0.1
                bv += 0.1
                ball.width = ball.height += 4;
                score.text = '' + (cnt += 1)
                noColCnt = 10
                
                 driver.play();
                //第一引数にSiONData、第二引数にSiONVoice、第三引数以降は、length=0(play all of sequence), delay=0(no delay), quantize=2(8th beat)
                driver.sequenceOn(mainMelody, voice,0,2)
            }
            wall.rotation = - a / 3.141592 * 180
            ball.x += bv * Math.sin(ba)
            ball.y += bv * Math.cos(ba)
            wall.x = W / 2 + Math.sin(a) * radius 
            wall.y = H / 2 + Math.cos(a) * radius 
            if ((ball.x < 0 || ball.x > W ||
                 ball.y < 0 || ball.y > H) && running) {
                text.text = ' Circle  Pong\n\n\n  GAME  OVER\nCLICK TO START'
                running = false
                ball.scaleX = ball.scaleY = 1
            }
            
   
       
           
            screen.lock();
            screen.applyFilter( screen, screen.rect, new Point(), new BlurFilter(2,2,3))
            screen.colorTransform(screen.rect, _ct);
            screen.draw(this,mat)
            screen.unlock();
        }
    }
}