Created
May 1, 2012 00:14
-
-
Save anonymous/2563886 to your computer and use it in GitHub Desktop.
Bat Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var batX = 10; | |
var batY = 10; | |
//This sets the bat's x position to tween to | |
var batXAim:Number = 550 - bat_mc.width/2; | |
bat_mc.x = batX; | |
bat_mc.y = batY; | |
stage.addEventListener(Event.ENTER_FRAME, repeatFlowers); | |
function repeatFlowers(e:Event):void | |
{ | |
//stores location of bat_mc for checkLocation | |
batX = bat_mc.x; | |
batY = bat_mc.y; | |
//keeps bat on screen | |
if(bat_mc.x < 0 + bat_mc.width/2) | |
{ | |
bat_mc.x = bat_mc.width/2; | |
} | |
if(bat_mc.x > 550 - bat_mc.width/2) | |
{ | |
bat_mc.x = 550 - bat_mc.width/2; | |
} | |
if(bat_mc.y > 400 - bat_mc.height/2) | |
{ | |
bat_mc.y = 400 - bat_mc.height/2; | |
} | |
if(bat_mc.y < 0 + bat_mc.height/2) | |
{ | |
bat_mc.y = 0 + bat_mc.height/2; | |
} | |
} | |
stage.addEventListener(Event.ENTER_FRAME, startCheckLocation); | |
function onFinish(e:TweenEvent):void | |
{ | |
stage.addEventListener(Event.ENTER_FRAME, checkLocation); | |
} | |
function checkLocation(e:Event):void | |
{ | |
stage.removeEventListener(Event.ENTER_FRAME, checkLocation); | |
if(batX > mothLeft_mc.x) | |
{ | |
batXAim = 0 + bat_mc.width/2; | |
} | |
if(batX < mothLeft_mc.x) | |
{ | |
batXAim = 550 - bat_mc.width/2; | |
} | |
var tweenScaleX:Tween = new Tween(bat_mc, "x", None.easeNone, batX, batXAim, 3, true); | |
var tweenScaleY:Tween = new Tween(bat_mc, "y", None.easeNone, batY, mothLeft_mc.y, 3, true); | |
tweenScaleX.addEventListener(TweenEvent.MOTION_FINISH, onFinish); | |
} | |
function startCheckLocation(e:Event):void | |
{ | |
stage.removeEventListener(Event.ENTER_FRAME, startCheckLocation); | |
stage.addEventListener(Event.ENTER_FRAME, checkLocation); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment