Advertisement
lamaulfarid

Paddle

Dec 15th, 2020
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.51 KB | None | 0 0
  1.  
  2. /**
  3.  * Source code untuk class Paddle.
  4.  *
  5.  * @author Ahmad Lamaul Farid
  6.  * @version 16 Desember 2020
  7.  */
  8.  
  9.  package pong;  
  10.  import java.awt.Color;  
  11.  import java.awt.Graphics;  
  12.  public class Paddle  
  13.  {  
  14.       public int paddleNumber;  
  15.       public int x, y, width = 50, height = 250;  
  16.       public int score;  
  17.       public Paddle(Pong pong, int paddleNumber)  
  18.       {  
  19.            this.paddleNumber = paddleNumber;  
  20.            if (paddleNumber == 1)  
  21.            {  
  22.                 this.x = 0;  
  23.            }  
  24.            if (paddleNumber == 2)  
  25.            {  
  26.                 this.x = pong.width - width;  
  27.            }  
  28.            this.y = pong.height / 2 - this.height / 2;  
  29.       }  
  30.       public void render(Graphics g)  
  31.       {  
  32.            g.setColor(Color.WHITE);  
  33.            g.fillRect(x, y, width, height);  
  34.       }  
  35.       public void move(boolean up)  
  36.       {  
  37.            int speed = 15;  
  38.            if (up)  
  39.            {  
  40.                 if (y - speed > 0)  
  41.                 {  
  42.                      y -= speed;  
  43.                 }  
  44.                 else  
  45.                 {  
  46.                      y = 0;  
  47.                 }  
  48.            }  
  49.            else  
  50.            {  
  51.                 if (y + height + speed < Pong.pong.height)  
  52.                 {  
  53.                      y += speed;  
  54.                 }  
  55.                 else  
  56.                 {  
  57.                      y = Pong.pong.height - height;  
  58.                 }  
  59.            }  
  60.       }  
  61.  }  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement