class Scroll extends MovieClip { //variables var ground1:MovieClip; var i:Number = 0; var iLimit:Number = 7; var scrollSpeed:Number = 8; var moving:Boolean = true var collision:Boolean = false; var groundStarty:Number; var groundHeight:Number=1199; var scrollStop:Boolean = false; var life:Number = 5; var music:Sound; var time:Number; var hit:Boolean = false; var musicOn:Boolean = true; var lifeChange:Number = 1; var gameOver:Boolean; var keys:Number; var level:Number = 1; //functions function backgroundMove () { this._y -= scrollSpeed; if (this._y <= (groundStarty-(groundHeight)*8.5)) { scrollStop=true; gameOver=true; } } function setupMaze () { this.attachMovie ('ground'+i,'ground'+i,0); // sets first section of hole this['ground'+i]._x=0; this['ground'+i]._y=0; for (i=1; i<= 9; i++) { this.attachMovie ('ground'+i,'ground'+i,i); //sets up remaining sections of hole this['ground'+i]._y = (groundHeight*i); groundStarty = this._y; //trace (i); } } function collisionTest () { //trace (collision); if (collision == false) { if (this.hitTest(_root.sprite.hit1x,_root.sprite.y1,true)) //top left hit { collision = true; //trace ('top left'); _root.sprite.topLeft (); lifeChange=1; lifeHandler (); } else if (this.hitTest(_root.sprite.hit2x,_root.sprite.y1,true)) //top right hit { collision = true; //trace ('top right'); _root.sprite.topRight(); lifeChange=1; lifeHandler (); } else if (this.hitTest(_root.sprite.hit3x,_root.sprite.y2,true)) //center left hit { collision = true; //trace ('center left'); _root.sprite.centerLeft (); lifeChange=1; lifeHandler (); } else if (this.hitTest(_root.sprite.hit4x,_root.sprite.y2,true)) //center right hit { collision = true; //trace ('center right'); _root.sprite.centerRight (); lifeChange=1; lifeHandler (); } else if (this.hitTest(_root.sprite.hit5x,_root.sprite.y3,true)) //bottom left hit { collision = true; //trace ('bottom left'); _root.sprite.bottomLeft (); lifeChange=1; lifeHandler (); } else if (this.hitTest(_root.sprite.hit6x,_root.sprite.y3,true)) //bottom right hit { collision = true; //trace ('bottom right'); _root.sprite.bottomRight (); lifeChange=1; lifeHandler (); } } } function lifeHandler () { if (hit == false) { _root.sprite.bonkSound.start (); time=getTimer()+100; //trace (lifeChange); life=life-lifeChange; hit=true; //trace (life); if (life >= 0) { _root.lifeIndicator.gotoAndPlay(_root.lifeIndicator._currentframe +(lifeChange*4)); if (_root.lifeIndicator.currentframe > 25) { _root.lifeIndicator.currentframe = 25; } } if (life <=0) { _root.gotoAndPlay ('gameOver'); scrollStop=true; music.stop ('music'); } } if (getTimer() > time) { hit=false; } } function startMusic () { if (scrollStop==false) { music=new Sound(); music.attachSound('music'); music.start (); } } //handlers function onEnterFrame() { //trace (scrollStop); if (scrollStop==false) { backgroundMove (); collisionTest (); } if (gameOver == true) { if (keys < 4) { gameOver = false; _root.gotoAndPlay ('lose'); } else { level++; scrollSpeed += (level*2); trace ('scroll speed = ' + scrollSpeed); gameOver = false; _root.gotoAndPlay ('win'); } } trace ('keys = '+ keys); } //constructor function Scroll () { setupMaze (); if (musicOn == true) { startMusic (); } } }