Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Adding a ball ##
- # A ball get added and given an angle by the user clicking, drag and releasing:
- # item.radians = Math.atan2(mouseUpY-mouseDownY, mouseUpX-mouseDownX);
- # Then this code loops on each frame moving the ball
- # This part is how I'm checking if the ball has hit a wall
- # The left and right wall math seem to work fine
- if (item.x + (item.width / 2) >= stage.stageWidth || item.x - (item.width / 2) <= 0) {
- item.radians = Math.PI - item.radians;
- }
- if (item.y + (item.height / 2) >= stage.stageHeight) {
- // Hit bottom wall
- } else if (item.y - (item.height / 2) <= 0) {
- // hit top wall
- }
- // This then calculates how many pixels to move the ball
- var xVel:Number = Math.cos(item.radians) * item.speed;
- var yVel:Number = Math.sin(item.radians) * item.speed;
- item.x += xVel;
- item.y += yVel;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement