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

flash on 2011-2-8

Get Adobe Flash player
by alex463 08 Feb 2011
    Embed
package  {
    
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    
    
    public class SquashMain extends MovieClip {
        
        var topWall:Sprite=new Sprite();
        var sideWall:Sprite=new Sprite();
        var botWall:Sprite=new Sprite();
        
        var ball:Sprite=new Sprite();
        
        var paddle:Sprite=new Sprite();
        
        var xV: int;
        var yV: int;
        
        public function SquashMain() 
        {
            // constructor code
            topWall.graphics.beginFill(0x00FF00);
            topWall.graphics.drawRect(0,0,stage.stageWidth,10);
            topWall.graphics.endFill();
            topWall.x=0;
            topWall.y=0;
            addChild(topWall);
            
            sideWall.graphics.beginFill(0x00FF00);
            sideWall.graphics.drawRect(0,0,10,stage.stageHeight);
            sideWall.graphics.endFill();
            sideWall.x=0;
            sideWall.y=0;
            addChild(sideWall);
            
            botWall.graphics.beginFill(0x00FF00);
            botWall.graphics.drawRect(0,0,stage.stageWidth,10);
            botWall.graphics.endFill();
            botWall.x=0;
            botWall.y=stage.stageHeight-10;
            addChild(botWall);
            
            
            ball.graphics.beginFill(0xFF0000);
            ball.graphics.drawCircle(0,0,10);
            ball.graphics.endFill();
            ball.x=stage.stageWidth/2;
            ball.y=stage.stageHeight/2;
            addChild(ball);
            ball.addEventListener(Event.ENTER_FRAME,ballBounce);
            
            paddle.graphics.beginFill(0x008000);
            paddle.graphics.drawEllipse(-15,-35,25,30);
            paddle.graphics.beginFill(0xA52A2A);
            paddle.graphics.drawRect(-5,-5,5,15);
            paddle.graphics.endFill();
            paddle.x=0;
            paddle.y=0;
            addChild(paddle);
            stage.addEventListener(MouseEvent.MOUSE_MOVE,paddleParty);
            
            xV=-5;
            yV=-5;
        }//end con
        
        private function ballBounce(e:Event)
        {
            ball.x+=xV;
            ball.y+=yV;
            
            if(ball.hitTestObject(topWall))
            {
                ball.y = topWall.y + topWall.height + ball.width/2;
                yV *= -1;
            }
            if(ball.hitTestObject(sideWall))
            {
                ball.x = sideWall.x + sideWall.width + ball.width/2;
                xV*=-1;
            }
            if(ball.hitTestObject(botWall))
            {
                ball.y = botWall.y - ball.width/2;
                yV*=-1;
            }
            if(ball.hitTestObject(paddle))
            {
                if(ball.x<paddle.x && ball.x >0)
                {
                    xV+=1;
                    xV*=-1;
                }
                if(ball.x>paddle.x && ball.x < 0)
                {
                    xV -=1;
                    xV *=-1;
                }
            }
            if(ball.x >= stage.stageWidth)
            {
                ball.x=stage.stageWidth/2;
                ball.y=stage.stageHeight/2;
            
                xV=-5;
                yV=-5;
            }
        }
        private function paddleParty(e:MouseEvent)
        {
            paddle.x=e.stageX;
            paddle.y=e.stageY;
        }
        
                                     
    
    }
    
}