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