Advertisement
kuchuz

PBO-C 8 : Paddle

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