Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main;
- import java.util.Timer;
- import java.util.TimerTask;
- public class Ball extends Thread implements Runnable{
- int speed = 1;
- int ball_x = 300;
- int ball_y = 150;
- boolean hitP = false;
- Main main;
- Ai a = new Ai(main);
- Timer timer;
- Player p = new Player(main);
- public Ball(Main m){
- timer = new Timer();
- movement();
- main = m;
- }
- public static void main(String[] args){
- }
- public void movement(){
- timer.scheduleAtFixedRate(new TimerTask() {
- public void run() {
- if(main.player.intersects(main.ball) && hitP == false){
- hitP = true;
- speed = -speed;
- }else if(main.ball.intersects(main.ai) && hitP == true){
- hitP = false;
- speed = -speed;
- }
- a.getBall(ball_y);
- ball_x+=speed;
- main.repaint();
- }
- }, 0, 7);
- }
- public int getX()
- {
- return ball_x;
- }
- public int getY()
- {
- return ball_y;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment