document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1.  
  2. /**
  3.  * Class yang mengatur bat Pong.
  4.  *
  5.  * @author Dwinanda Bagoes Ansori
  6.  * @version 22 Desember 2020
  7.  */
  8. import java.awt.Color;
  9. import java.awt.Graphics;
  10.  
  11. public class Paddle
  12. {
  13.     public int paddleNumber;
  14.     public int x, y, width = 50, height = 250;
  15.     public int score;
  16.    
  17.     public Paddle(Pong pong, int paddleNumber)
  18.     {
  19.         this.paddleNumber = paddleNumber;
  20.        
  21.         if (paddleNumber == 1)
  22.         {
  23.             this.x = 0;
  24.         }
  25.        
  26.         if (paddleNumber == 2)
  27.         {
  28.             this.x = pong.width - width;
  29.         }
  30.        
  31.         this.y = pong.height / 2 - this.height / 2;
  32.     }
  33.    
  34.     public void render(Graphics g)
  35.     {
  36.         g.setColor(Color.WHITE);
  37.     g.fillOval(x, y, width, height);
  38.     }
  39.    
  40.     public void move(boolean up)
  41.     {
  42.         int speed = 15;
  43.        
  44.         if (up)
  45.         {
  46.             if (y - speed > 0)
  47.             {
  48.                 y -= speed;
  49.             }
  50.             else
  51.             {
  52.                 y = 0;
  53.             }
  54.         }
  55.         else
  56.         {
  57.             if (y + height + speed < Pong.pong.height)
  58.             {
  59.                 y += speed;
  60.             }
  61.             else
  62.             {
  63.                 y = Pong.pong.height - height;
  64.             }
  65.         }
  66.     }
  67. }
  68.  
');