Advertisement
Guest User

AS3

a guest
Apr 29th, 2011
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ## Adding a ball ##
  2. # A ball get added and given an angle by the user clicking, drag and releasing:
  3. # item.radians = Math.atan2(mouseUpY-mouseDownY, mouseUpX-mouseDownX);
  4.  
  5. # Then this code loops on each frame moving the ball
  6.  
  7.     # This part is how I'm checking if the ball has hit a wall
  8.    # The left and right wall math seem to work fine
  9.    if (item.x + (item.width / 2) >= stage.stageWidth || item.x - (item.width / 2) <= 0) {
  10.         item.radians = Math.PI - item.radians;
  11.    }
  12.    
  13.  
  14.    if (item.y + (item.height / 2) >= stage.stageHeight) {
  15.         // Hit bottom wall     
  16.    } else if (item.y - (item.height / 2) <= 0) {
  17.         // hit top wall    
  18.    }
  19.    
  20.    
  21.    // This then calculates how many pixels to move the ball
  22.    var xVel:Number = Math.cos(item.radians) * item.speed;
  23.    var yVel:Number = Math.sin(item.radians) * item.speed;
  24.    
  25.    item.x += xVel;
  26.    item.y += yVel;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement