import mx.utils.Delegate; class Avi extends CustomMC { private var keyListener; private var opening : MovieClip; private var vxmax = 10; private var vymax = 5; private var xmin = 20; private var xmax = Stage.width-20; private var ymin = 20; private var ymax = Stage.height-120; private var damping = 0.03; private var tanking = false; private var ax=0; private var ay=0; private var vx=0; private var vy=0; private var r; private static var maxWater=15; private var water; private var waterClip : MovieClip; private var waterClipHeight : Number; public function halt () { this.onEnterFrame=null; } private function onLoad () { keyListener = new Object(); keyListener.onKeyDown = Delegate.create(this,KeyDown); //keyListener.onKeyDown = Delegate.create(this,KeyDown); Key.addListener(keyListener); water=maxWater; waterClipHeight = waterClip._height; } private function KeyDown () { /* if (Key.getCode() == Key.RIGHT) { ax = 1; r = 30; } if (Key.getCode() == Key.LEFT) { ax = -1; r = -5; } if (Key.getCode() == Key.UP) { ay = -1; r = 0; } if (Key.getCode() == Key.DOWN) { ay = 1; r = 0; }*/ if (Key.getCode() == Key.SPACE) { shoot(); } } private function KeyUp () { if (Key.getCode() == Key.RIGHT or Key.getCode() == Key.LEFT or Key.getCode() == Key.UP or Key.getCode() == Key.DOWN) { ax = 0; ay = 0; r = 0; } } private function onEnterFrame () { var down = false; if (Key.isDown(Key.RIGHT)) { ax = 1; r = 30; down=true; } if (Key.isDown(Key.LEFT)) { ax = -1; r = -5; down=true; } if (Key.isDown(Key.UP)) { ay = -1; r = 0; down=true; } if (Key.isDown(Key.DOWN)) { ay = 1; r = 0; down=true; } if (!down) { ax = 0; ay = 0; r = 0; } // damping var dampx = vx*damping; var dampy = vy*damping; vx += ax-dampx; vy += ay-dampy; // check speed if (vx>vxmax) { vx = vxmax; } else if (vy>vymax) { vy = vymax; } // checkposition if (_xxmax) { _x = xmax; vx = 0; } if (_yymax && vy>0) { vy = 0; } _x += vx; _y += vy; // rotation if (this._rotationr) { this._rotation -= 2; } // show hose if (_x<200) { _root.sim.activate(); } if (_x>300) { _root.sim.deactivate(); } _root.sim.track (_x,_y); } private function shoot () { if (water>0) { var p = new Vector (opening._x,opening._y); this.localToGlobal(p); var params = { startV : { x: this.vx, y : this.vy }, r : this._rotation, x : p.x, y : p.y } var d= _root.getNextHighestDepth (); var drop = _root.attachMovie ("Drop", "drop"+d,d, params); this.swapDepths (drop); decWaterlevel (); } } private function decWaterlevel () { if (water>0) water--; updateWaterlevel(); } public function incWaterlevel () { if (water