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

Memory Pong

MEMORY PONG BY GIRLFLASH ******

Inspired by all the neat play with *
yourself games, yay masturbation!  *

Instructions:            *
Click the mouse to start      *
package {

    // **************************************
    // ****** MEMORY PONG BY GIRLFLASH ******
    // **************************************
    // * Inspired by all the neat play with *
    // * yourself games, yay masturbation!  *
    // **************************************
    // *           Instructions:            *
    // *      Click the mouse to start      *
    // **************************************

    import flash.display.Sprite;
    import flash.display.MovieClip;
    import flash.events.*;
    import flash.text.*;
    public class MemoryPong extends Sprite {
        
        public var paddleA:MovieClip = new MovieClip();
        public var paddleB:MovieClip = new MovieClip();
        public var ball:MovieClip = new MovieClip();
        
        public var ballHspeed:Number = 5;
        public var ballVspeed:Number = 5;
        
        public var lastYA:Number = 0;
        public var lastYB:Number = 0;
        
        public var paddlePositions:Array = new Array();
        public var memoryLength:Number = 30;
        public var i:Number;
        
        public var scoreDisp:TextField = new TextField();
        public var recordDisp:TextField = new TextField();
        
        public var score:Number = 0;
        public var record:Number = 0;
        
        public var gameState:String = "AIM";
        
        public function MemoryPong() {
            
            addChild(scoreDisp);
            scoreDisp.x = 175;
            scoreDisp.selectable = false;
            addChild(recordDisp);
            recordDisp.x = 250;
            recordDisp.selectable = false;
            
            for (i=0; i<memoryLength;i++){
                paddlePositions.push(175);
            }
            
            paddleA.graphics.lineStyle(1,0x000000);
            paddleA.graphics.beginFill(0x000000);
            paddleA.graphics.lineTo(20,0);
            paddleA.graphics.lineTo(20,80);
            paddleA.graphics.lineTo(0,80);
            paddleA.graphics.endFill();
            addChild(paddleA);
            paddleA.x = 10;
            
            paddleB.graphics.lineStyle(1,0x000000);
            paddleB.graphics.beginFill(0x000000);
            paddleB.graphics.lineTo(20,0);
            paddleB.graphics.lineTo(20,80);
            paddleB.graphics.lineTo(0,80);
            paddleB.graphics.endFill();
            addChild(paddleB);
            paddleB.x = 430;
            
            ball.graphics.lineStyle(1,0x000000);
            ball.graphics.beginFill(0x000000);
            ball.graphics.lineTo(0,10);
            ball.graphics.lineTo(10,10);
            ball.graphics.lineTo(10,0);
            ball.graphics.endFill();
            addChild(ball);
            
            //stage.addEventListener(KeyboardEvent.KEY_DOWN,onPushy);
            stage.addEventListener(Event.ENTER_FRAME,onTick);
            stage.addEventListener(MouseEvent.CLICK,onClicky);
        }
        public function onTick(evt:Event):void{
            
            lastYA = paddleA.y;
            lastYB = paddleB.y;
            paddleA.y = mouseY - (paddleA.height/2);
            paddlePositions.splice(0,1);
            paddlePositions.push(paddleA.y);       
            paddleB.y = paddlePositions[0];
            
            if (gameState == "AIM"){
                ball.x = paddleA.x+paddleA.width+2;
                ball.y = paddleA.y+(paddleA.height/2)-5;
            }else{
                ball.x += ballHspeed;
                ball.y += ballVspeed;
                if (ball.x>450 || ball.x<0){
                    gameState = "AIM"
                    score=0;
                }
                if (ball.y>450 || ball.y<0){
                    ballVspeed *=-1;
                }
                
                if (ball.hitTestObject(paddleB)){
                    score++;
                    ball.x = paddleB.x-10;
                    ballHspeed*=-1;
                    ballVspeed += (paddleB.y-lastYB)/4;
                }
                if (ball.hitTestObject(paddleA)){
                    score++;
                    ball.x = paddleA.x+paddleA.width;
                    ballHspeed*=-1;
                    ballHspeed+=0.5;
                    ballVspeed += (paddleA.y-lastYA)/4;
                    
                    //dont make it easy to volley =p
                    if (ballVspeed<0 && ballVspeed>-1){
                        ballVspeed=-1;
                    }
                    if (ballVspeed>=0 && ballVspeed<1){
                        ballVspeed=1;
                    }
                }
            }
            
            
            if (score>record){
                record = score;
            }
            scoreDisp.text = "Score: " + score;
            recordDisp.text = "Record: " + record;
        }
        public function onClicky(evt:MouseEvent):void{
            if (gameState == "AIM"){
                ballHspeed = 5;
                ballVspeed = (Math.random()*10)-5;
                gameState = "PLAY";
            }
        }
    }
}