Orginal address : Crydust.be thank you crydust
Mr.doob created a 1k pong game in as3. Which made my fingers itch to do better. So here it is, in as2, less than half the filesize and the same functionality.
var so = new SWFObject("http://www.crydust.be/blog/wp-content/uploads/pong0_5k.swf", "pong0_5k_swf", "450", "256", "6", "#000000"); so.write("pong0_5k"); // // Pong.5k (510 bytes game) // by Kristof Neirynck // // inspired by monoPong-1k and mrdoob // http://pouet.net/prod.php?which=48976 // http://mrdoob.com/blog/post/485/ // Stage . align = "TL" ; Stage . scaleMode = "noScale" ; // making 10 a variable to shave off some bytes var t : Number = 10 ; // speed var vx : Number = - t ; var vy : Number = t ; // player 1 var p : MovieClip = createEmptyMovieClip ( "p" , 1 ); // player 2 var q : MovieClip = createEmptyMovieClip ( "q" , 2 ); // ball var b : MovieClip = createEmptyMovieClip ( "b" , 3 ); // drawing the squares d ( p , 20 , 40 ); d ( q , 20 , 40 ); d ( b , t , t ); // magic loop function onEnterFrame () { b . _x += vx ; b . _y += vy ; q . _x = Stage . width ; p . _y = _ymouse ; q . _y = Stage . height - _ymouse ; // bounce top or bottom border if ( b . _y < t || b . _y > Stage . height - t ) { vy = - vy ; } // bounce player1 or left border // or player 2 or right border if (( b . hitTest ( p ) && b . _x > 20 ) || ( b . hitTest ( q ) && b . _x < Stage . width - 20 )) { vx = - vx ; } // someone scored if (- t > b . _x || b . _x > Stage . width + t ) { b . _x = Stage . width * 0 . 5 ; b . _y = Stage . height * 0 . 5 ; vx = - vx ; } }; // square drawing function function d ( m : MovieClip , w : Number , h : Number ): Void { //w and h are already / 2 //w /= 2; //h /= 2; m . beginFill ( 0xFFFFFF ); m . moveTo (- w ,- h ); m . lineTo ( w ,- h ); m . lineTo ( w , h ); m . lineTo (- w , h ); //not needed //t.lineTo(-w,-h); //t.endFill(); } |
---|