package { import flash.display.MovieClip; import flash.display.Sprite; import flash.events.Event; import flash.events.KeyboardEvent; import flash.events.EventDispatcher; import flash.events.MouseEvent; public class BallDocumentClass extends Movie{ public var replaybtn=new replay(); public function BallDocumentClass(){ var dispatcher=new EventDispatcher(); var keyer=new KeyboardEvent("KEY_DOWN") stage.addEventListener(Event.ENTER_FRAME,ballFall); stage.addEventListener(KeyboardEvent.KEY_DOWN,ball.keyHandler); replaybtn.addEventListener(MouseEvent.CLICK,replayhander); } public function replayhander(event:MouseEvent){ ball.rewind(); ball.startgame=false; ball.blood=3 redrawmap(0) removeChild(replaybtn) stage.focus=stage; } public function ballFall(event:Event){ if(ball.startgame){ ball.y+=ball.fallspeed; ball.fallspeed+=ball.addspeed; ball.y+=ball.yspeed ball.yspeed*=ball.resist; ball.x+=ball.xspeed; ball.xspeed*=ball.resist; var downleftX=Math.floor((ball.x-10)/20) var downleftY=Math.floor((ball.y+10)/20) var downrightX=Math.floor((ball.x+10)/20) var downrightY=Math.floor((ball.y+10)/20) var uprightX=Math.floor((ball.x+10)/20) var uprightY=Math.floor((ball.y-10)/20) var upleftX=Math.floor((ball.x-10)/20) var upleftY=Math.floor((ball.y-10)/20) if(vmap[downleftY][downleftX]==1||vmap[downrightY][downrightX]==1||vmap[upleftY][upleftX]==1||vmap[uprightY][uprightX]==1){ ball.play(); ball.rewind(); ball.startgame=false; ball.blood-- if(ball.blood==0){ child.graphics.clear(); addChild(replaybtn) } } if(vmap[downleftY][downleftX]==2||vmap[downrightY][downrightX]==2||vmap[upleftY][upleftX]==2||vmap[uprightY][uprightX]==2){ ball.rewind(); ball.startgame=false; var num=++smap.themapnum redrawmap(num) } } } } import flash.display.MovieClip; import flash.events.KeyboardEvent; import flash.events.Event; public class Ball extends MovieClip{ public var startgame:Boolean=false; public var xspeed:Number=0; public var yspeed:Number=0; public var fallspeed:Number=0; public var addspeed:Number=0.1; public var resist:Number=0.9; public var blood:Number=3; public function Ball(){ } public function rewind(){ this.x=50 this.y=50 this.xspeed=0 this.yspeed=0 this.fallspeed=0 } public function keyHandler(event:KeyboardEvent){ switch(event.keyCode){ case 37: this.xspeed=-4 break; case 39: this.xspeed=4 break; case 38: this.yspeed=-6 this.fallspeed=0 break; case 32: if(this.startgame==false){ this.startgame=true; rewind(); } break; } } } import flash.display.MovieClip; import flash.display.Sprite; public class Movie extends MovieClip{ public var cmap:Array; public var smap:map; public var vmap:Array public var child:Sprite=new MovieClip(); public var ball:Ball; public function Movie(){ smap=new map() ball=new Ball(); ball.x=50 ball.y=50 addChild(ball); drawMap(smap.nextMap) vmap=smap.nextMap; } public function redrawmap(mapid){ smap.themapnum=mapid; vmap=smap.nextMap; drawMap(vmap); } public function drawMap(cmap:Array){ child.graphics.clear(); for(var i=0;i