document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import java.awt.Color;  
  2. import java.awt.Graphics;
  3. /**
  4.  * @author Muthia Qurrota Akyun
  5.  * 18 Desember 2020
  6.  */  
  7. public class Paddle  
  8. {
  9.     public int paddleNumber;  
  10.     public int x, y, width = 60, height = 200;  
  11.     public int score;
  12.     /**
  13.      * constructor paddle
  14.      * @param pong
  15.      * @param paddleNumber jumlah pemain
  16.      */
  17.     public Paddle(Pong pong, int paddleNumber)
  18.     {  
  19.         this.paddleNumber = paddleNumber;  
  20.         if (paddleNumber == 1)  
  21.             this.x = 0;  
  22.         if (paddleNumber == 2)  
  23.             this.x = pong.width - width;  
  24.         this.y = pong.height / 2 - this.height / 2;  
  25.     }  
  26.     public void render(Graphics g)  
  27.     {
  28.         g.setColor(Color.BLACK);  
  29.         g.fillRect(x, y, width, height);  
  30.     }
  31.     /**
  32.      * method yang mengatur pergerakan paddle
  33.      * @param up kondisi tombol yang dipakai untuk bergerak
  34.      */
  35.     public void move(boolean up)  
  36.     {    
  37.         int speed = 15;  
  38.         if (up){  
  39.             if (y - speed > 0)        
  40.                 y -= speed;  
  41.             else  
  42.                 y = 0;  
  43.         }  
  44.         else {  
  45.             if (y + height + speed < Pong.pong.height)  
  46.                 y += speed;  
  47.             else  
  48.                 y = Pong.pong.height - height;  
  49.         }  
  50.     }  
  51. }  
');