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

Blockage movement

http://www.emanueleferonato.com/2010/08/21/create-a-flash-game-like-blockage-movement-prototype/#more-3254
Get Adobe Flash player
by Albert 25 Aug 2010
    Embed
/**
 * Copyright Albert ( http://wonderfl.net/user/Albert )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/5l5l
 */

//http://www.emanueleferonato.com/2010/08/21/create-a-flash-game-like-blockage-movement-prototype/#more-3254

package {
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.geom.Point;
    public class block_mc extends Sprite {
        public var point:Point=new Point(50,50);
        public var defpoint:Point=new Point(50,100);
        public var rotation_dir:int=5;
        public var steps:uint=0;
        public function block_mc() {
            graphics.lineStyle(5, 0x000000);
            graphics.beginFill(0x993311);
            graphics.drawRect(0, 0, 50, 50);
            graphics.endFill();
            addEventListener(Event.ENTER_FRAME,on_enter_frame);            
        }
        private function on_enter_frame(e:Event):void {
            rotation+=rotation_dir;
            if (rotation%90==0) {
                rotation=0;
                steps++;
                if (steps==8) {
                    steps=0;
                    rotation_dir*=-1;
                    if (rotation_dir>0) {
                        point=new Point(50,50);
                    } else {
                        point=new Point(0,50);
                    }
                } else {
                    if (rotation_dir>0) {
                        defpoint=new Point(50,0).add(defpoint);
                    } else {
                        defpoint=new Point(-50,0).add(defpoint);
                    }
                }
            }
            var tmp_point:Point=localToGlobal(point);
            tmp_point=defpoint.subtract(tmp_point);
            x+=tmp_point.x;
            y+=tmp_point.y;
        }
    }
}