Guest User

Untitled

a guest
Jul 7th, 2012
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. package main;
  2.  
  3. import java.util.Timer;
  4. import java.util.TimerTask;
  5.  
  6. public class Ball extends Thread implements Runnable{
  7. int speed = 1;
  8. int ball_x = 300;
  9. int ball_y = 150;
  10. boolean hitP = false;
  11. Main main;
  12. Ai a = new Ai(main);
  13.  Timer timer;
  14. Player p = new Player(main);
  15.     public Ball(Main m){
  16.          timer = new Timer();
  17.          movement();
  18.         main = m;
  19.     }
  20.     public static void main(String[] args){
  21.     }
  22.     public void movement(){
  23.         timer.scheduleAtFixedRate(new TimerTask() {
  24.             public void run() {
  25.                 if(main.player.intersects(main.ball) && hitP == false){
  26.                     hitP = true;
  27.                     speed = -speed;
  28.                 }else if(main.ball.intersects(main.ai) && hitP == true){
  29.                     hitP = false;
  30.                     speed = -speed;
  31.                 }
  32.                 a.getBall(ball_y);
  33.                 ball_x+=speed;
  34.                 main.repaint();
  35.                
  36.             }
  37.         }, 0, 7);
  38.     }
  39.    
  40.     public int getX()
  41.     {
  42.             return ball_x;
  43.     }
  44.     public int getY()
  45.     {
  46.             return ball_y;
  47.     }  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment