// // 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; import flash.events.Event; [SWF(width="1024",height="768",backgroundColor="#000000",frameRate="50")] public class Pong1k extends Sprite { private var b : Sprite, p1 : Sprite, p2 : Sprite; private var v : Object = {x:-10,y:10}; // speed public function Pong1k() { addEventListener(Event.ADDED_TO_STAGE, init); } private function init( e : Event ) : void { stage.align = "TL"; stage.scaleMode = "noScale"; // 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 : Event) : void { b.x += v.x; b.y += v.y; p2.x = stage.stageWidth; p1.y = mouseY; p2.y = stage.stageHeight - mouseY; if (b.y < 10 || b.y > stage.stageHeight - 10) v.y = -v.y; if ( ( b.hitTestObject(p1) && b.x > 20 ) || ( b.hitTestObject(p2) && b.x < stage.stageWidth - 20 ) ) v.x = -v.x; if (b.x < -10 || b.x > stage.stageWidth + 10) { b.x = stage.stageWidth * .5; b.y = stage.stageHeight * .5; v.x = -v.x; } } // square drawing function private function d(t : Sprite, w : Number, h : Number) : void { t.graphics.beginFill( 0xFFFFFF, 1 ); t.graphics.drawRect( -w*.5, -h*.5, w, h ); t.graphics.endFill(); } } } Pong1k