thomasfelix

PBO 9

Dec 19th, 2020
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.31 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Graphics;
  3.  
  4. /**
  5.  * Class yang mengatur bat Pong.
  6.  *
  7.  * @author Thomas Felix
  8.  * @version 19 Desember 2020
  9.  */
  10.  
  11. public class Paddle
  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.WHITE);
  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.        
  58.         else
  59.         {
  60.             if (y + height + speed < Pong.pong.height)
  61.             {
  62.                 y += speed;
  63.             }
  64.            
  65.             else
  66.             {
  67.                 y = Pong.pong.height - height;
  68.             }
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment