SHARE
TWEET

Untitled

a guest Jun 19th, 2017 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Ball  extends Actor
  2. {
  3.     /**
  4.      * Act - do whatever the Ball wants to do. This method is called whenever
  5.      * the 'Act' or 'Run' button gets pressed in the environment.
  6.      */
  7.     private int speedY = -5;
  8.     private int speedX = 5;
  9.    
  10.     public Ball(){
  11.        
  12.     }
  13.    
  14.     public void act()
  15.     {
  16.         move();
  17.         atWorldEdge();
  18.         bounce();
  19.     }  
  20.  
  21.   public boolean canSee(Class bounce)
  22.         {
  23.             Actor actor = getOneObjectAtOffset(0, 0, bounce);
  24.             return actor != null;            
  25.  
  26.         }
  27.  
  28.     private void move(){
  29.          int y = getY()+speedY;
  30.          setLocation(getX(),y);
  31.          
  32.          int x = getX()+speedX;        
  33.          setLocation(getY(),x);        
  34.          
  35.     }  
  36.  
  37.    private void atWorldEdge()
  38.     {
  39.         if(getX() == 0 || getX() == 599)
  40.         {
  41.             speedX = -speedX;
  42.         }
  43.         if(getY() == 0 || getY() ==799)
  44.         {
  45.             speedY = -speedY;
  46.         }        
  47.     }
  48.  
  49.    
  50.  
  51.     private void bounce()
  52.     {
  53.         if (canSee(Paddle.class))
  54.         {
  55.             speedY = -speedY;
  56.         }
  57.     }
  58. }
RAW Paste Data
Top