// forked from mrdoob's Pong1k // // Pong1k (1,022bytes game) // by Mr.doob // // If you want to increase the level of difficulty, // make the browser window smaller :P // // inspired by monoPong-1k // http://pouet.net/prod.php?which=48976 // package { import flash.display.Sprite; [SWF(width="500",height="500",backgroundColor="#000000",frameRate="50")] public class P extends Sprite { private var b : *, p1 : *, p2 : *; private var vx:Number = 10, vy:Number = 5; // speed public function P() { // player 1 p1 = new Sprite addChild(p1); // player 2 p2 = new Sprite; addChild(p2); // ball b = new Sprite; addChild(b); // drawing the squares d( p1, 40, 80); d( p2, 40, 80); d( b, 20, 20); addEventListener("enterFrame",l); } // magic loop private function l(e :*):* { b.x += vx; b.y += vy; p2.x = 500; p1.y = mouseY; p2.y = 500 - mouseY; if (b.y < 10 || b.y > 490) vy *= -1; if ( ( b.hitTestObject(p1) && b.x > 20 ) || ( b.hitTestObject(p2) && b.x < 480 ) ) vx *= -1; if (b.x < -10 || b.x > 510) { b.x = 250; b.y = 250; vx *= -1; } } // square drawing function private function d(t : *, w : *, h : *) : * { t.graphics.beginFill( 0xffffff); t.graphics.drawRect( -w*.5, -h*.5, w, h ); } } } forked from: Pong1k