The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
untitled ActionScript Code
Posted by: baldnh | April 12, 2011 @ 1:59pm
ActionScript Code
[
Download
]
function Main () { stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler); } var destinationX:int = 150; var destinationY:int = 150; var dX:int = 0; var dY:int = 0; var vX:int = 0; var vY:int = 0; var moveSpeedMax:Number = 1000; var rotateSpeedMax:Number = 15; var trueRotation:Number = 0; var decay:Number = 0.98; function enterFrameHandler(event:Event):void { updatePosition(); updateRotation(); } function updatePosition():void { destinationX = stage.mouseX; destinationY = stage.mouseY; vX += (destinationX - water_drop.x) / moveSpeedMax; vY += (destinationY - water_drop.y) / moveSpeedMax; vX *= decay; vY *= decay; water_drop.x += vX; water_drop.y += vY; } function updateRotation():void { dX = water_drop.x - destinationX; dY = water_drop.y - destinationY; var rotateTo:Number = getDegrees(getRadians(dX, dY)); if (rotateTo > water_drop.rotation + 180) rotateTo -= 360; if (rotateTo < water_drop.rotation - 180) rotateTo += 360; trueRotation = (rotateTo - water_drop.rotation) / rotateSpeedMax; water_drop.rotation += trueRotation; } function getRadians(delta_x:Number, delta_y:Number):Number { var r:Number = Math.atan2(delta_y, delta_x); if (delta_y < 0) { r += (2 * Math.PI); } return r; } function getDegrees(radians:Number):Number { return Math.floor(radians/(Math.PI/180)); }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.46 / 8
41 Votes
http://codebin.yi.org/1220
page generated in 0.00 seconds