class Ball extends MovieClip { // variables var xmov:Number; var ymov:Number; var gravity:Number = 2; var ylimit:Number = 350; var wallColorTimer:Number; var leftWallColor:Object; var rightWallColor:Object; var coinToss:Number; var i:Number; var xstart:Number; var ystart:Number; var timer:Number; var whichWall:String; //functions function moveBall () { this._x += xmov; ymov += gravity; this._y += ymov; if (this._y >ylimit) { this._y = ylimit; ymov *= -1; xmov = xmov *.9; } } function collisionTest () { if (this.hitTest(_root.leftWall)) { xmov = -xmov; // bounce off of wall changeWallColor('left') xmovAdjust (); } if (this.hitTest(_root.rightWall)) { xmov = -xmov; // bounce off of wall changeWallColor('right') xmovAdjust (); } } function changeWallColor (whichWall) //change wall color temporarily when ball bounces off of it { if (whichWall == "left") { wallColorTimer = getTimer() +50; // sets timer for wall color change leftWallColor.setRGB (0x555555); //changes wall to grey } if (whichWall == "right") { wallColorTimer = getTimer() +50; // sets timer for wall color change rightWallColor.setRGB (0x555555); //changes wall to grey } } function resetWallColor () { if (getTimer () > wallColorTimer) { leftWallColor.setRGB (0xffff00); // resets wall color when timer has expired rightWallColor.setRGB (0xffff00); } } function diminishGravity () { timer = getTimer () + 1; if (getTimer() < timer) { gravity += .1; } trace ('gravity = '+gravity); trace ('xmov = '+xmov); } function xmovAdjust () { xmov = xmov * .95; } //frame events function onEnterFrame () { moveBall (); collisionTest (); resetWallColor (); diminishGravity (); } function reset () { gravity = 2; coinToss= Math.floor(Math.random()*2) if (coinToss== 0) i=1; if (coinToss==1) i=-1; xmov= (Math.floor((Math.random()*20))*i); ymov= Math.floor(Math.random()*20); leftWallColor = new Color (_root.leftWall); rightWallColor = new Color (_root.rightWall); xstart = (Math.floor(Math.random()*300)+100); ystart = (Math.floor(Math.random()*300)); this._x= xstart; this._y= ystart; } //constructor function Ball () { reset (); } }